@@ -4,19 +4,11 @@ import { createFhirErrorResponse, createFhirResponse } from "../lib/fhir-respons
44import { ResultStatus } from "../lib/types/status" ;
55import { lambdaHandler } from "./index" ;
66
7- const mockLogInfo = jest . fn ( ) ;
8- const mockLogDebug = jest . fn ( ) ;
9- const mockLogError = jest . fn ( ) ;
107const mockUpdateResultStatus = jest . fn ( ) ;
118const mockRetrievePatientIdFromOrder = jest . fn ( ) ;
129
1310jest . mock ( "./init" , ( ) => ( {
1411 init : jest . fn ( ( ) => ( {
15- commons : {
16- logInfo : mockLogInfo ,
17- logDebug : mockLogDebug ,
18- logError : mockLogError ,
19- } ,
2012 resultService : {
2113 updateResultStatus : mockUpdateResultStatus ,
2214 } ,
@@ -40,6 +32,7 @@ jest.mock("../lib/fhir-response", () => ({
4032const VALID_ORDER_UUID = "123a1234-a12b-1234-abcd-1234567890ab" ;
4133const VALID_PATIENT_UUID = "123a1234-a12b-1234-abcd-1234567890ab" ;
4234const VALID_CORRELATION_ID = "123a1234-a12b-1234-abcd-1234567890ab" ;
35+ const VALID_HEADERS = { "X-Correlation-ID" : VALID_CORRELATION_ID } ;
4336
4437const validTask = {
4538 resourceType : "Task" ,
@@ -66,9 +59,6 @@ describe("result-status-lambda handler", () => {
6659 beforeEach ( ( ) => {
6760 jest . clearAllMocks ( ) ;
6861
69- mockLogInfo . mockReset ( ) ;
70- mockLogDebug . mockReset ( ) ;
71- mockLogError . mockReset ( ) ;
7262 mockUpdateResultStatus . mockReset ( ) ;
7363 mockRetrievePatientIdFromOrder . mockReset ( ) ;
7464
@@ -81,7 +71,7 @@ describe("result-status-lambda handler", () => {
8171
8272 describe ( "request body parsing" , ( ) => {
8373 it ( "returns 400 when body is null" , async ( ) => {
84- const res = await lambdaHandler ( makeEvent ( null ) ) ;
74+ const res = await lambdaHandler ( makeEvent ( null , VALID_HEADERS ) ) ;
8575
8676 expect ( res . statusCode ) . toBe ( 400 ) ;
8777 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -93,7 +83,7 @@ describe("result-status-lambda handler", () => {
9383 } ) ;
9484
9585 it ( "returns 400 when body is invalid JSON" , async ( ) => {
96- const res = await lambdaHandler ( makeEvent ( "not-valid-json" ) ) ;
86+ const res = await lambdaHandler ( makeEvent ( "not-valid-json" , VALID_HEADERS ) ) ;
9787
9888 expect ( res . statusCode ) . toBe ( 400 ) ;
9989 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -117,7 +107,9 @@ describe("result-status-lambda handler", () => {
117107 } ) ;
118108
119109 it ( "returns 400 when task fails schema validation" , async ( ) => {
120- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( { resourceType : "Task" } ) ) ) ;
110+ const res = await lambdaHandler (
111+ makeEvent ( JSON . stringify ( { resourceType : "Task" } ) , VALID_HEADERS ) ,
112+ ) ;
121113
122114 expect ( res . statusCode ) . toBe ( 400 ) ;
123115 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -131,7 +123,7 @@ describe("result-status-lambda handler", () => {
131123 it ( "returns 400 when resourceType is not Task" , async ( ) => {
132124 const invalidTask = { ...validTask , resourceType : "Observation" } ;
133125
134- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) ) ) ;
126+ const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) , VALID_HEADERS ) ) ;
135127
136128 expect ( res . statusCode ) . toBe ( 400 ) ;
137129 } ) ;
@@ -142,15 +134,15 @@ describe("result-status-lambda handler", () => {
142134 businessStatus : { coding : [ { code : ResultStatus . Result_Withheld } ] } ,
143135 } ;
144136
145- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) ) ) ;
137+ const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) , VALID_HEADERS ) ) ;
146138
147139 expect ( res . statusCode ) . toBe ( 400 ) ;
148140 } ) ;
149141
150142 it ( "returns 400 when identifier array is empty" , async ( ) => {
151143 const invalidTask = { ...validTask , identifier : [ ] } ;
152144
153- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) ) ) ;
145+ const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) , VALID_HEADERS ) ) ;
154146
155147 expect ( res . statusCode ) . toBe ( 400 ) ;
156148 } ) ;
@@ -160,7 +152,7 @@ describe("result-status-lambda handler", () => {
160152 it ( "returns 400 when for.reference has no slash (single segment)" , async ( ) => {
161153 const invalidTask = { ...validTask , for : { reference : VALID_PATIENT_UUID } } ;
162154
163- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) ) ) ;
155+ const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) , VALID_HEADERS ) ) ;
164156
165157 expect ( res . statusCode ) . toBe ( 400 ) ;
166158 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -177,7 +169,7 @@ describe("result-status-lambda handler", () => {
177169 for : { reference : `Patient/${ VALID_PATIENT_UUID } /extra` } ,
178170 } ;
179171
180- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) ) ) ;
172+ const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) , VALID_HEADERS ) ) ;
181173
182174 expect ( res . statusCode ) . toBe ( 400 ) ;
183175 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -191,7 +183,7 @@ describe("result-status-lambda handler", () => {
191183 it ( "returns 400 when patient ID in for.reference is not a valid UUID" , async ( ) => {
192184 const invalidTask = { ...validTask , for : { reference : "Patient/not-a-uuid" } } ;
193185
194- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) ) ) ;
186+ const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) , VALID_HEADERS ) ) ;
195187
196188 expect ( res . statusCode ) . toBe ( 400 ) ;
197189 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -205,7 +197,7 @@ describe("result-status-lambda handler", () => {
205197 it ( "returns 400 when order identifier value is not a valid UUID" , async ( ) => {
206198 const invalidTask = { ...validTask , identifier : [ { value : "not-a-uuid" } ] } ;
207199
208- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) ) ) ;
200+ const res = await lambdaHandler ( makeEvent ( JSON . stringify ( invalidTask ) , VALID_HEADERS ) ) ;
209201
210202 expect ( res . statusCode ) . toBe ( 400 ) ;
211203 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -221,7 +213,9 @@ describe("result-status-lambda handler", () => {
221213 it ( "returns 500 when orderService.retrievePatientIdFromOrder throws" , async ( ) => {
222214 mockRetrievePatientIdFromOrder . mockRejectedValueOnce ( new Error ( "DB connection failed" ) ) ;
223215
224- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( validTask ) ) ) ;
216+ const res = await lambdaHandler (
217+ makeEvent ( JSON . stringify ( validTask ) , { "X-Correlation-ID" : VALID_CORRELATION_ID } ) ,
218+ ) ;
225219
226220 expect ( res . statusCode ) . toBe ( 500 ) ;
227221 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -235,7 +229,9 @@ describe("result-status-lambda handler", () => {
235229 it ( "returns 404 when order is not found" , async ( ) => {
236230 mockRetrievePatientIdFromOrder . mockResolvedValueOnce ( null ) ;
237231
238- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( validTask ) ) ) ;
232+ const res = await lambdaHandler (
233+ makeEvent ( JSON . stringify ( validTask ) , { "X-Correlation-ID" : VALID_CORRELATION_ID } ) ,
234+ ) ;
239235
240236 expect ( res . statusCode ) . toBe ( 404 ) ;
241237 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
@@ -254,7 +250,9 @@ describe("result-status-lambda handler", () => {
254250 patient_uid : "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11" ,
255251 } ) ;
256252
257- const res = await lambdaHandler ( makeEvent ( JSON . stringify ( validTask ) ) ) ;
253+ const res = await lambdaHandler (
254+ makeEvent ( JSON . stringify ( validTask ) , { "X-Correlation-ID" : VALID_CORRELATION_ID } ) ,
255+ ) ;
258256
259257 expect ( res . statusCode ) . toBe ( 403 ) ;
260258 expect ( createFhirErrorResponse ) . toHaveBeenCalledWith (
0 commit comments