This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createHttpGet, createUrl, Paths } from './get-env-vars' | |
| describe("GetProducts", () => { | |
| const products = [{ id: 1 }]; | |
| const url = 'https://example.com' | |
| const httpGet = jest.fn().mockResolvedValue({ | |
| json: jest.fn().mockResolvedValue(products) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export enum Paths { | |
| PRODUCTS = '/products' | |
| } | |
| export const createLogger = (logger) => { | |
| error: e => logger.error(`Something bad happened today: ${e}`) | |
| } | |
| export const createUrl = (path: Paths, url = process.env.BASE_URL) => `${url}${path}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createUrl, getProducts, Paths } from './get-env-vars' | |
| import * as fns from './get-env-vars' | |
| describe("GetEnvVars", () => { | |
| const MOCKED_PRODCUTS = [{ id: 1 }]; | |
| global.fetch = jest.fn(() => Promise.resolve({ | |
| json: () => Promise.resolve(MOCKED_PRODCUTS) | |
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export enum Paths { | |
| PRODUCTS = '/products' | |
| } | |
| export const createLogger = () => { | |
| error: e => console.error(`Something bad happened today: ${e}!`) | |
| } | |
| export const loggerService = createLogger() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createUrl, getProducts, Paths } from './get-env-vars' | |
| describe("GetProducts", () => { | |
| const products = [{ id: 1 }]; | |
| const httpGet = jest.fn().mockResolvedValue({ | |
| json: jest.fn().mockResolvedValue(products) | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export enum Paths { | |
| PRODUCTS = '/products' | |
| } | |
| export const createUrl = (path: Paths, url = process.env.BASE_URL) => `${url}${path}` | |
| export const getProducts = ( | |
| httpGet = fetch, | |
| url: string = createUrl(Paths.PRODUCTS), | |
| ) => httpGet(url).then(e => e.json()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createUrl, getProducts, Paths } from './get-env-vars' | |
| describe("GetEnvVars", () => { | |
| const MOCKED_PRODUCTS = [{ id: 1 }]; | |
| global.fetch = jest.fn(() => Promise.resolve({ | |
| json: () => Promise.resolve(MOCKED_PRODUCTS) | |
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export enum Paths { | |
| PRODUCTS = '/products' | |
| } | |
| export const createUrl = (path: Paths) => `${process.env.BASE_URL}${path}` | |
| export const productsUrl = createUrl(Paths.PRODUCTS) | |
| export const getProducts = () => fetch(productsUrl).then(e => e.json()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createUrl, Paths } from './get-env-vars' | |
| describe("GetEnvVars", () => { | |
| test('should create a new url', () => { | |
| const url = 'https://example.com' | |
| expect(createUrl(Paths.PRODUCTS, url)).toEqual(`${url}/${Paths.PRODUCTS}`); | |
| }); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export enum Paths { | |
| PRODUCTS = '/products' | |
| } | |
| // pass the dependency, simply as optional variable | |
| export const createUrl = (path: Paths, baseUrl = process.env.BASE_URL) => `${url}${path}` | |
| export const productsUrl = createUrl(Paths.PRODUCTS) |
NewerOlder