Skip to content

Commit

Permalink
tests: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Shelomentsev committed May 2, 2023
1 parent 66972fc commit a48ad1d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
26 changes: 13 additions & 13 deletions proxy/errors/integrarionError.test.ts
Original file line number Diff line number Diff line change
@@ -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))
})
})
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))
})
})
61 changes: 30 additions & 31 deletions proxy/handlers/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down Expand Up @@ -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(`
Expand Down Expand Up @@ -158,6 +158,5 @@ describe('Handle status', () => {
</html>
"
`)

})
})
})

0 comments on commit a48ad1d

Please sign in to comment.