-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-handler.test.ts
More file actions
40 lines (33 loc) · 1.5 KB
/
test-handler.test.ts
File metadata and controls
40 lines (33 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {APIGatewayProxyResult} from "aws-lambda"
import {Logger} from "@aws-lambda-powertools/logger"
import {handler} from "../src/capabilityStatement"
import {
expect,
describe,
it,
vi
} from "vitest"
import capabilityStatement from "../src/apim-medicines-prescriptionstatusupdate.json"
import {mockAPIGatewayProxyEvent, mockContext} from "@psu-common/testing"
describe("Unit test for app handler", function () {
it("verifies successful response with no params", async () => {
const result: APIGatewayProxyResult = await handler(mockAPIGatewayProxyEvent, mockContext)
expect(result.statusCode).toEqual(200)
expect(result.body).toEqual(JSON.stringify(capabilityStatement))
})
it("returns a response with the correct MIME type", async () => {
const result: APIGatewayProxyResult = await handler(mockAPIGatewayProxyEvent, mockContext)
expect(result.headers).toEqual({"Content-Type": "application/fhir+json", "Cache-Control": "no-cache"})
})
it("appends trace id's to the logger", async () => {
const mockAppendKeys = vi.spyOn(Logger.prototype, "appendKeys")
await handler(mockAPIGatewayProxyEvent, mockContext)
expect(mockAppendKeys).toHaveBeenCalledWith({
"nhsd-correlation-id": "test-request-id.test-correlation-id.rrt-5789322914740101037-b-aet2-20145-482635-2",
"x-request-id": "test-request-id",
"nhsd-request-id": "test-request-id",
"x-correlation-id": "test-correlation-id",
"apigw-request-id": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
})
})
})