From a996fde85a853b060beef7773411cab0815dbda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Mon, 1 May 2023 18:31:14 +0900 Subject: [PATCH] chore: improve coverage --- jest.config.js | 10 ++++++- proxy/customer-variables/selectors.test.ts | 33 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 proxy/customer-variables/selectors.test.ts diff --git a/jest.config.js b/jest.config.js index 274076d0..e3812aa4 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,7 +4,15 @@ module.exports = { testEnvironment: 'node', testRegex: '/proxy/.+test.tsx?$|/management/.+test.tsx?$', passWithNoTests: true, - collectCoverageFrom: ['./proxy/**/**.ts', '!**/index.ts', '!**/config.ts', './management/**/**.ts'], + collectCoverageFrom: [ + './proxy/**/**.ts', + './management/**/**.ts', + '!**/index.ts', + '!**/errors/**', + '!**/config.ts', + '!**/env.ts', + '!**/handlers/**', + ], coverageReporters: ['lcov', 'json-summary', ['text', { file: 'coverage.txt', path: './' }]], transform: { '^.+\\.[tj]sx?$': [ diff --git a/proxy/customer-variables/selectors.test.ts b/proxy/customer-variables/selectors.test.ts new file mode 100644 index 00000000..51e25c66 --- /dev/null +++ b/proxy/customer-variables/selectors.test.ts @@ -0,0 +1,33 @@ +import { CustomerVariables } from './CustomerVariables' +import { EnvCustomerVariables } from './EnvCustomerVariables' +import { getAgentDownloadUri, getResultUri, getStatusUri } from './selectors' +import { CustomerVariableType } from './types' + +describe('customer variables selectors', () => { + describe('from env', () => { + const getHeaderCustomerVariables = (env: typeof process.env) => + new CustomerVariables([new EnvCustomerVariables(env)]) + + test('with env variables', async () => { + const env = { + [CustomerVariableType.AgentDownloadPath]: 'greiodsfkljlds', + [CustomerVariableType.RoutePrefix]: 'eifjdsnmzxcn', + [CustomerVariableType.GetResultPath]: 'eiwflsdkadlsjdsa', + } + + const customerVariables = getHeaderCustomerVariables(env) + + expect(await getAgentDownloadUri(customerVariables)).toBe('eifjdsnmzxcn/greiodsfkljlds') + expect(await getResultUri(customerVariables)).toBe('eifjdsnmzxcn/eiwflsdkadlsjdsa') + expect(await getStatusUri(customerVariables)).toBe('eifjdsnmzxcn/status') + }) + + test('with empty env', async () => { + const customerVariables = getHeaderCustomerVariables({}) + + expect(await getAgentDownloadUri(customerVariables)).toBe('fpjs/agent') + expect(await getResultUri(customerVariables)).toBe('fpjs/resultId') + expect(await getStatusUri(customerVariables)).toBe('fpjs/status') + }) + }) +})