-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from fingerprintjs/feature/unit-tests
Feature/unit tests
- Loading branch information
Showing
5 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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)) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { CustomerVariables } from '../customer-variables/CustomerVariables' | ||
import { CustomerVariableType } from '../customer-variables/types' | ||
import { EnvCustomerVariables } from '../customer-variables/EnvCustomerVariables' | ||
import { handleStatus } from './status' | ||
import { HttpRequest, Form, FormPart } from '@azure/functions' | ||
|
||
const fp: FormPart = { | ||
value: Buffer.from(''), | ||
} | ||
const form: Form = { | ||
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) => x, | ||
parseFormBody: () => form, | ||
} | ||
|
||
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), '') | ||
} | ||
|
||
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)]) | ||
const env = { | ||
[CustomerVariableType.AgentDownloadPath]: 'qwertyt', | ||
[CustomerVariableType.RoutePrefix]: 'dsgfkjdfs', | ||
[CustomerVariableType.GetResultPath]: 'fdgvdsfgfds', | ||
[CustomerVariableType.PreSharedSecret]: 'aadddddd', | ||
} | ||
const customerVariables = getHeaderCustomerVariables(env) | ||
|
||
const result = await handleStatus({ | ||
httpRequest: req, | ||
customerVariables: customerVariables, | ||
}) | ||
|
||
expect(removeNonce(result.body)).toMatchInlineSnapshot(` | ||
" | ||
<html lang='en-US'> | ||
<head> | ||
<title>Fingerprint Pro Azure integration status</title> | ||
<meta charset='utf-8'> | ||
<style> | ||
body, .env-info { | ||
display: flex; | ||
} | ||
.env-info { | ||
flex-direction: column; | ||
} | ||
body { | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
body > * { | ||
margin-bottom: 1em; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Fingerprint Pro Azure integration status</h1> | ||
<div> | ||
Fingerprint Pro Azure Function App version: __azure_function_version__ | ||
</div> | ||
<div> | ||
✅ All environment variables are set | ||
</div> | ||
<span> | ||
Please reach out our support via <a href='mailto:[email protected]'>[email protected]</a> if you have any issues | ||
</span> | ||
</body> | ||
</html> | ||
" | ||
`) | ||
}) | ||
|
||
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)]) | ||
const customerVariables = getHeaderCustomerVariables({}) | ||
|
||
const result = await handleStatus({ | ||
httpRequest: req, | ||
customerVariables: customerVariables, | ||
}) | ||
|
||
expect(removeNonce(result.body)).toMatchInlineSnapshot(` | ||
" | ||
<html lang='en-US'> | ||
<head> | ||
<title>Fingerprint Pro Azure integration status</title> | ||
<meta charset='utf-8'> | ||
<style> | ||
body, .env-info { | ||
display: flex; | ||
} | ||
.env-info { | ||
flex-direction: column; | ||
} | ||
body { | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
body > * { | ||
margin-bottom: 1em; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Fingerprint Pro Azure integration status</h1> | ||
<div> | ||
Fingerprint Pro Azure Function App version: __azure_function_version__ | ||
</div> | ||
<div class='env-info'> | ||
<div class='env-info-item'> | ||
⚠️ <strong>fpjs_route_prefix </strong> is not defined and uses default value | ||
</div> | ||
<div class='env-info-item'> | ||
⚠️ <strong>fpjs_get_result_path </strong> is not defined and uses default value | ||
</div> | ||
<div class='env-info-item'> | ||
⚠️ <strong>fpjs_pre_shared_secret </strong> is not defined | ||
</div> | ||
<div class='env-info-item'> | ||
⚠️ <strong>fpjs_agent_download_path </strong> is not defined and uses default value | ||
</div> | ||
</div> | ||
<span> | ||
Please reach out our support via <a href='mailto:[email protected]'>[email protected]</a> if you have any issues | ||
</span> | ||
</body> | ||
</html> | ||
" | ||
`) | ||
}) | ||
}) |
This file contains 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