Skip to content

Commit e372fc7

Browse files
Change supplier header to app-supplier-id
1 parent c1d296d commit e372fc7

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

lambdas/api-handler/src/handlers/__tests__/get-letters.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('API Lambda handler', () => {
1717
const mockedGetLetterIds = letterService.getLetterIdsForSupplier as jest.Mock;
1818
mockedGetLetterIds.mockResolvedValue(['l1', 'l2', 'l3']);
1919

20-
const event = makeApiGwEvent({path: '/letters'});
20+
const event = makeApiGwEvent({path: '/letters', headers: {'app-supplier-id': 'supplier1'}});
2121
const context = mockDeep<Context>();
2222
const callback = jest.fn();
2323
const result = await getLetters(event, context, callback);
@@ -54,4 +54,16 @@ describe('API Lambda handler', () => {
5454
body: 'Not Found',
5555
});
5656
});
57+
58+
it('returns 400 Bad Request: Missing supplier ID if header app-supplier-id ', async () => {
59+
const event = makeApiGwEvent({path: '/letters'});
60+
const context = mockDeep<Context>();
61+
const callback = jest.fn();
62+
const result = await getLetters(event, context, callback);
63+
64+
expect(result).toEqual({
65+
statusCode: 400,
66+
body: 'Bad Request: Missing supplier ID',
67+
});
68+
});
5769
});

lambdas/api-handler/src/handlers/__tests__/patch-letters.test.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ describe('patchLetters API Handler', () => {
3333
const event = makeApiGwEvent({
3434
path: '/letters/id1',
3535
body: requestBody,
36-
pathParameters: {id: "id1"}});
36+
pathParameters: {id: "id1"},
37+
headers: {'app-supplier-id': 'supplier1'}});
3738
const context = mockDeep<Context>();
3839
const callback = jest.fn();
3940

@@ -51,7 +52,8 @@ describe('patchLetters API Handler', () => {
5152
it('returns 400 Bad Request as there is no body', async () => {
5253
const event = makeApiGwEvent({
5354
path: '/letters/id1',
54-
pathParameters: {id: "id1"}});
55+
pathParameters: {id: "id1"},
56+
headers: {'app-supplier-id': 'supplier1'}});
5557
const context = mockDeep<Context>();
5658
const callback = jest.fn();
5759
const result = await patchLetters(event, context, callback);
@@ -66,7 +68,8 @@ describe('patchLetters API Handler', () => {
6668
const event = makeApiGwEvent({
6769
path: '/unknown',
6870
body: requestBody,
69-
pathParameters: {id: "id1"}});
71+
pathParameters: {id: "id1"},
72+
headers: {'app-supplier-id': 'supplier1'}});
7073
const context = mockDeep<Context>();
7174
const callback = jest.fn();
7275
const result = await patchLetters(event, context, callback);
@@ -80,7 +83,8 @@ describe('patchLetters API Handler', () => {
8083
it('returns 404 Not Found as path parameter is not found', async () => {
8184
const event = makeApiGwEvent({
8285
path: '/letters',
83-
body: requestBody});
86+
body: requestBody,
87+
headers: {'app-supplier-id': 'supplier1'}});
8488
const context = mockDeep<Context>();
8589
const callback = jest.fn();
8690
const result = await patchLetters(event, context, callback);
@@ -98,7 +102,8 @@ describe('patchLetters API Handler', () => {
98102
const event = makeApiGwEvent({
99103
path: '/letters/id1',
100104
body: requestBody,
101-
pathParameters: { id: "id1" }
105+
pathParameters: {id: "id1"},
106+
headers: {'app-supplier-id': 'supplier1'}
102107
});
103108
const context = mockDeep<Context>();
104109
const callback = jest.fn();
@@ -118,7 +123,8 @@ describe('patchLetters API Handler', () => {
118123
const event = makeApiGwEvent({
119124
path: '/letters/id1',
120125
body: requestBody,
121-
pathParameters: { id: "id1" }
126+
pathParameters: {id: "id1"},
127+
headers: {'app-supplier-id': 'supplier1'}
122128
});
123129
const context = mockDeep<Context>();
124130
const callback = jest.fn();
@@ -138,11 +144,27 @@ describe('patchLetters API Handler', () => {
138144
const event = makeApiGwEvent({
139145
path: '/letters/id1',
140146
body: requestBody,
141-
pathParameters: { id: "id1" }
147+
pathParameters: {id: "id1"},
148+
headers: {'app-supplier-id': 'supplier1'}
142149
});
143150
const context = mockDeep<Context>();
144151
const callback = jest.fn();
145152

146153
await expect(patchLetters(event, context, callback)).rejects.toThrow('Unexpected error');
147154
});
155+
156+
it('returns 400 Bad Request: Missing supplier ID if header app-supplier-id ', async () => {
157+
const event = makeApiGwEvent({
158+
path: '/letters/id1',
159+
body: requestBody,
160+
pathParameters: {id: "id1"}});
161+
const context = mockDeep<Context>();
162+
const callback = jest.fn();
163+
const result = await patchLetters(event, context, callback);
164+
165+
expect(result).toEqual({
166+
statusCode: 400,
167+
body: 'Bad Request: Missing supplier ID',
168+
});
169+
});
148170
});

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ export const getLetters: APIGatewayProxyHandler = async (event) => {
88

99
if (event.path === '/letters') {
1010

11-
// default to supplier1 for now
12-
const supplierId = event.headers['nhsd-apim-apikey'] ?? "supplier1";
11+
const supplierId = event.headers['app-supplier-id'];
12+
13+
if (!supplierId) {
14+
return {
15+
statusCode: 400,
16+
body: "Bad Request: Missing supplier ID"
17+
};
18+
}
1319

1420
const letterIds = await getLetterIdsForSupplier(supplierId, letterRepo);
1521

lambdas/api-handler/src/handlers/patch-letters.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ import { NotFoundError, ValidationError } from '../errors';
77
const letterRepo = createLetterRepository();
88
export const patchLetters: APIGatewayProxyHandler = async (event) => {
99

10-
// TODO CCM-11188: default to supplier1 for now
11-
const supplierId = event.headers['nhsd-apim-apikey'] ?? "supplier1";
10+
const supplierId = event.headers['app-supplier-id'];
11+
12+
if (!supplierId) {
13+
return {
14+
statusCode: 400,
15+
body: "Bad Request: Missing supplier ID"
16+
};
17+
}
1218

1319
const pathParameters = event.pathParameters || {};
1420
const letterId = pathParameters["id"];

0 commit comments

Comments
 (0)