Skip to content

Commit 54da309

Browse files
committed
Allow for no headers
1 parent 77bf03c commit 54da309

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

lambdas/api-handler/src/handlers/__tests__/get_status.test.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('API Lambda handler', () => {
1111
it('passes if S3 and DynamoDB are available', async() => {
1212

1313
const event = makeApiGwEvent({path: '/_status',
14-
headers: {'Nhsd-Correlation-Id': 'correlationId'}
14+
headers: undefined
1515
});
1616

1717
const getLetterDataHandler = createGetStatusHandler(getMockedDeps());
@@ -28,14 +28,15 @@ describe('API Lambda handler', () => {
2828
mockedDeps.s3Client.send = jest.fn().mockRejectedValue(new Error('unexpected error'));
2929

3030
const event = makeApiGwEvent({path: '/_status',
31-
headers: {'Nhsd-Correlation-Id': 'correlationId'}
31+
headers: undefined
3232
});
3333

3434
const getLetterDataHandler = createGetStatusHandler(mockedDeps);
3535
const result = await getLetterDataHandler(event, mockDeep<Context>(), jest.fn());
3636

37-
expect(result!.statusCode).toBe(500);
38-
expect(JSON.parse(result!.body).errors[0].id).toBe('correlationId');
37+
expect(result).toEqual(expect.objectContaining({
38+
statusCode: 500
39+
}));
3940
});
4041

4142

@@ -50,24 +51,11 @@ describe('API Lambda handler', () => {
5051
const getLetterDataHandler = createGetStatusHandler(mockedDeps);
5152
const result = await getLetterDataHandler(event, mockDeep<Context>(), jest.fn());
5253

53-
expect(result!.statusCode).toBe(500);
54-
expect(JSON.parse(result!.body).errors[0].id).toBe('correlationId');
54+
expect(result).toEqual(expect.objectContaining({
55+
statusCode: 500
56+
}));
5557
});
5658

57-
it('allows the correlation ID to be absent', async() => {
58-
const mockedDeps = getMockedDeps();
59-
mockedDeps.dbHealthcheck.check = jest.fn().mockRejectedValue(new Error('unexpected error'));
60-
61-
const event = makeApiGwEvent({path: '/_status',
62-
headers: {}
63-
});
64-
65-
const getLetterDataHandler = createGetStatusHandler(mockedDeps);
66-
const result = await getLetterDataHandler(event, mockDeep<Context>(), jest.fn());
67-
68-
expect(result!.statusCode).toBe(500);
69-
expect(JSON.parse(result!.body).errors[0].id).toBeDefined();
70-
});
7159

7260
function getMockedDeps(): jest.Mocked<Deps> {
7361
return {

lambdas/api-handler/src/handlers/get-status.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@ import { mapErrorToResponse } from "../mappers/error-mapper";
55

66
export function createGetStatusHandler(deps: Deps): APIGatewayProxyHandler {
77

8-
return async(event) => {
9-
10-
const correlationId = Object.entries(event.headers)
11-
.find(([headerName, _]) => headerName.toLowerCase() === deps.env.APIM_CORRELATION_HEADER)?.[1];
8+
return async(_) => {
129

1310
try {
1411
await deps.dbHealthcheck.check();
1512
await s3HealthCheck(deps.s3Client);
1613

1714
deps.logger.info({
18-
description: 'Healthcheck passed',
19-
correlationId
15+
description: 'Healthcheck passed'
2016
});
2117

2218
return {
2319
statusCode: 200,
2420
body: '{}'
2521
};
2622
} catch (error) {
27-
return mapErrorToResponse(error, correlationId || '', deps.logger);
23+
return mapErrorToResponse(error, undefined, deps.logger);
2824
}
2925
}
3026
}

0 commit comments

Comments
 (0)