From a48ad1d4d8c74f7bcc57af03c32fb79f652f38f6 Mon Sep 17 00:00:00 2001 From: Sergey Shelomentsev Date: Tue, 2 May 2023 21:20:30 +0300 Subject: [PATCH] tests: update tests --- proxy/errors/integrarionError.test.ts | 26 ++++++------ proxy/handlers/status.test.ts | 61 +++++++++++++-------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/proxy/errors/integrarionError.test.ts b/proxy/errors/integrarionError.test.ts index 52846200..394d9a9c 100644 --- a/proxy/errors/integrarionError.test.ts +++ b/proxy/errors/integrarionError.test.ts @@ -1,16 +1,16 @@ import { IntegrationError } from './IntegrationError' describe('check integration error result', () => { - it('check if error return valid body', async () => { - const json = { - vendor: 'Fingerprint Pro Azure Function', - message: 'Download failed', - path: 'fpjs/agent', - } - - const message: IntegrationError = new IntegrationError(json.message, json.path) - const body = message.toBody() - - expect(body).toBe(JSON.stringify(json)) - }) -}) \ No newline at end of file + it('check if error return valid body', async () => { + const json = { + vendor: 'Fingerprint Pro Azure Function', + message: 'Download failed', + path: 'fpjs/agent', + } + + const message: IntegrationError = new IntegrationError(json.message, json.path) + const body = message.toBody() + + expect(body).toBe(JSON.stringify(json)) + }) +}) diff --git a/proxy/handlers/status.test.ts b/proxy/handlers/status.test.ts index d21dc7c7..ae66b961 100644 --- a/proxy/handlers/status.test.ts +++ b/proxy/handlers/status.test.ts @@ -5,49 +5,49 @@ import { handleStatus } from './status' import { HttpRequest, Form, FormPart } from '@azure/functions' const fp: FormPart = { - value: Buffer.from("") + value: Buffer.from(''), } const form: Form = { - get: (_: string) => fp, - getAll: (_: string) => [fp], - has: (_: string) => true, - length: 0, - *[Symbol.iterator]() {} + get: (_: string) => fp, + getAll: (_: string) => [fp], + has: (_: string) => true, + length: 0, + *[Symbol.iterator]() {}, } const req: HttpRequest = { - method: 'GET', - url: 'https://fp.domain.com/fpjs/status', - headers: {}, - query: {}, - params: {}, - user: null, - get: (x) => { return x }, - parseFormBody: () => form + method: 'GET', + url: 'https://fp.domain.com/fpjs/status', + headers: {}, + query: {}, + params: {}, + user: null, + get: (x) => x, + parseFormBody: () => form, } -function removeNonce(body: string): string { - const nonceParam = ' nonce=\'' - const begin = body.indexOf(nonceParam) - const end = body.indexOf('\'', begin + nonceParam.length) + 1 +function removeNonce(body: string): string { + const nonceParam = " nonce='" + const begin = body.indexOf(nonceParam) + const end = body.indexOf("'", begin + nonceParam.length) + 1 - return body.replace(body.substring(begin, end), '') + return body.replace(body.substring(begin, end), '') } describe('Handle status', () => { it('returns correct status info in html if all variables are set', async () => { const getHeaderCustomerVariables = (env: typeof process.env) => - new CustomerVariables([new EnvCustomerVariables(env)]) + new CustomerVariables([new EnvCustomerVariables(env)]) const env = { - [CustomerVariableType.AgentDownloadPath]: 'qwertyt', - [CustomerVariableType.RoutePrefix]: 'dsgfkjdfs', - [CustomerVariableType.GetResultPath]: 'fdgvdsfgfds', - [CustomerVariableType.PreSharedSecret]: 'aadddddd' + [CustomerVariableType.AgentDownloadPath]: 'qwertyt', + [CustomerVariableType.RoutePrefix]: 'dsgfkjdfs', + [CustomerVariableType.GetResultPath]: 'fdgvdsfgfds', + [CustomerVariableType.PreSharedSecret]: 'aadddddd', } const customerVariables = getHeaderCustomerVariables(env) const result = await handleStatus({ - httpRequest: req, - customerVariables: customerVariables + httpRequest: req, + customerVariables: customerVariables, }) expect(removeNonce(result.body)).toMatchInlineSnapshot(` @@ -96,12 +96,12 @@ describe('Handle status', () => { it('returns correct status info in html if some variables are using default values', async () => { const getHeaderCustomerVariables = (env: typeof process.env) => - new CustomerVariables([new EnvCustomerVariables(env)]) + new CustomerVariables([new EnvCustomerVariables(env)]) const customerVariables = getHeaderCustomerVariables({}) const result = await handleStatus({ - httpRequest: req, - customerVariables: customerVariables + httpRequest: req, + customerVariables: customerVariables, }) expect(removeNonce(result.body)).toMatchInlineSnapshot(` @@ -158,6 +158,5 @@ describe('Handle status', () => { " `) - }) -}) \ No newline at end of file +})