Skip to content

Commit 748ae70

Browse files
committed
CCM-10430: controller tests
1 parent db3b8fa commit 748ae70

File tree

9 files changed

+362
-108
lines changed

9 files changed

+362
-108
lines changed

lambdas/backend-api/src/__tests__/templates/api/create.test.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,33 @@ const setup = () => {
1515
describe('Template API - Create', () => {
1616
beforeEach(jest.resetAllMocks);
1717

18-
test('should return 400 - Invalid request when, no user in requestContext', async () => {
19-
const { handler, mocks } = setup();
20-
21-
const event = mock<APIGatewayProxyEvent>({
22-
requestContext: { authorizer: undefined },
23-
body: JSON.stringify({ id: 1 }),
24-
});
25-
26-
const result = await handler(event, mock<Context>(), jest.fn());
27-
28-
expect(result).toEqual({
29-
statusCode: 400,
30-
body: JSON.stringify({
18+
test.each([
19+
['undefined', undefined],
20+
['missing user', { clientId: 'client-id', user: undefined }],
21+
['missing client', { clientId: undefined, user: 'user-id' }],
22+
])(
23+
'should return 400 - Invalid request when requestContext is %s',
24+
async (_, ctx) => {
25+
const { handler, mocks } = setup();
26+
27+
const event = mock<APIGatewayProxyEvent>({
28+
requestContext: { authorizer: ctx },
29+
body: JSON.stringify({ id: 1 }),
30+
});
31+
32+
const result = await handler(event, mock<Context>(), jest.fn());
33+
34+
expect(result).toEqual({
3135
statusCode: 400,
32-
technicalMessage: 'Invalid request',
33-
}),
34-
});
35-
36-
expect(mocks.templateClient.createTemplate).not.toHaveBeenCalled();
37-
});
36+
body: JSON.stringify({
37+
statusCode: 400,
38+
technicalMessage: 'Invalid request',
39+
}),
40+
});
41+
42+
expect(mocks.templateClient.createTemplate).not.toHaveBeenCalled();
43+
}
44+
);
3845

3946
test('should return 400 - Invalid request when, no body', async () => {
4047
const { handler, mocks } = setup();

lambdas/backend-api/src/__tests__/templates/api/delete.test.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,33 @@ const setup = () => {
1414
describe('Template API - Delete', () => {
1515
beforeEach(jest.resetAllMocks);
1616

17-
test('should return 400 - Invalid request when no user in requestContext', async () => {
18-
const { handler, mocks } = setup();
19-
20-
const event = mock<APIGatewayProxyEvent>({
21-
requestContext: { authorizer: undefined },
22-
pathParameters: { templateId: '1-2-3' },
23-
});
24-
25-
const result = await handler(event, mock<Context>(), jest.fn());
26-
27-
expect(result).toEqual({
28-
statusCode: 400,
29-
body: JSON.stringify({
17+
test.each([
18+
['undefined', undefined],
19+
['missing user', { clientId: 'client-id', user: undefined }],
20+
['missing client', { clientId: undefined, user: 'user-id' }],
21+
])(
22+
'should return 400 - Invalid request when requestContext is %s',
23+
async (_, ctx) => {
24+
const { handler, mocks } = setup();
25+
26+
const event = mock<APIGatewayProxyEvent>({
27+
requestContext: { authorizer: ctx },
28+
pathParameters: { templateId: 'id' },
29+
});
30+
31+
const result = await handler(event, mock<Context>(), jest.fn());
32+
33+
expect(result).toEqual({
3034
statusCode: 400,
31-
technicalMessage: 'Invalid request',
32-
}),
33-
});
34-
35-
expect(mocks.templateClient.deleteTemplate).not.toHaveBeenCalled();
36-
});
35+
body: JSON.stringify({
36+
statusCode: 400,
37+
technicalMessage: 'Invalid request',
38+
}),
39+
});
40+
41+
expect(mocks.templateClient.deleteTemplate).not.toHaveBeenCalled();
42+
}
43+
);
3744

3845
test('should return 400 - Invalid request when, no templateId', async () => {
3946
const { handler, mocks } = setup();

lambdas/backend-api/src/__tests__/templates/api/get-client-configuration.test.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,35 @@ describe('Template API - get client configuration', () => {
1717
jest.resetAllMocks();
1818
});
1919

20-
test('should return 400 - Invalid request when, no user or client in requestContext', async () => {
21-
const { handler, mocks } = setup();
22-
23-
const event = mock<APIGatewayProxyEvent>({
24-
requestContext: { authorizer: undefined },
25-
});
26-
27-
const result = await handler(event, mock<Context>(), jest.fn());
28-
29-
expect(result).toEqual({
30-
statusCode: 400,
31-
body: JSON.stringify({
20+
test.each([
21+
['undefined', undefined],
22+
['missing clientId', { userId: 'user-id', clientId: undefined }],
23+
['missing user', { clientId: 'client-id', user: undefined }],
24+
])(
25+
'should return 400 - Invalid request when requestContext is %s',
26+
async (_, ctx) => {
27+
const { handler, mocks } = setup();
28+
29+
const event = mock<APIGatewayProxyEvent>({
30+
requestContext: { authorizer: ctx },
31+
body: JSON.stringify({ id: 1 }),
32+
});
33+
34+
const result = await handler(event, mock<Context>(), jest.fn());
35+
36+
expect(result).toEqual({
3237
statusCode: 400,
33-
technicalMessage: 'Invalid request',
34-
}),
35-
});
36-
37-
expect(mocks.templateClient.getClientConfiguration).not.toHaveBeenCalled();
38-
});
38+
body: JSON.stringify({
39+
statusCode: 400,
40+
technicalMessage: 'Invalid request',
41+
}),
42+
});
43+
44+
expect(
45+
mocks.templateClient.getClientConfiguration
46+
).not.toHaveBeenCalled();
47+
}
48+
);
3949

4050
test('should return error when getting client fails', async () => {
4151
const { handler, mocks } = setup();

lambdas/backend-api/src/__tests__/templates/api/get.test.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,33 @@ describe('Template API - Get', () => {
1717
jest.resetAllMocks();
1818
});
1919

20-
test('should return 400 - Invalid request when, no user in requestContext', async () => {
21-
const { handler, mocks } = setup();
22-
23-
const event = mock<APIGatewayProxyEvent>({
24-
requestContext: { authorizer: undefined },
25-
pathParameters: { templateId: '1' },
26-
});
27-
28-
const result = await handler(event, mock<Context>(), jest.fn());
29-
30-
expect(result).toEqual({
31-
statusCode: 400,
32-
body: JSON.stringify({
20+
test.each([
21+
['undefined', undefined],
22+
['missing user', { clientId: 'client-id', user: undefined }],
23+
['missing client', { clientId: undefined, user: 'user-id' }],
24+
])(
25+
'should return 400 - Invalid request when requestContext is %s',
26+
async (_, ctx) => {
27+
const { handler, mocks } = setup();
28+
29+
const event = mock<APIGatewayProxyEvent>({
30+
requestContext: { authorizer: ctx },
31+
pathParameters: { templateId: 'id' },
32+
});
33+
34+
const result = await handler(event, mock<Context>(), jest.fn());
35+
36+
expect(result).toEqual({
3337
statusCode: 400,
34-
technicalMessage: 'Invalid request',
35-
}),
36-
});
37-
38-
expect(mocks.templateClient.getTemplate).not.toHaveBeenCalled();
39-
});
38+
body: JSON.stringify({
39+
statusCode: 400,
40+
technicalMessage: 'Invalid request',
41+
}),
42+
});
43+
44+
expect(mocks.templateClient.getTemplate).not.toHaveBeenCalled();
45+
}
46+
);
4047

4148
test('should return 400 - Invalid request when, no templateId', async () => {
4249
const { handler, mocks } = setup();

lambdas/backend-api/src/__tests__/templates/api/list.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,33 @@ describe('Template API - List', () => {
1717
jest.resetAllMocks();
1818
});
1919

20+
test.each([
21+
['undefined', undefined],
22+
['missing user', { clientId: 'client-id', user: undefined }],
23+
['missing client', { clientId: undefined, user: 'user-id' }],
24+
])(
25+
'should return 400 - Invalid request when requestContext is %s',
26+
async (_, ctx) => {
27+
const { handler, mocks } = setup();
28+
29+
const event = mock<APIGatewayProxyEvent>({
30+
requestContext: { authorizer: ctx },
31+
});
32+
33+
const result = await handler(event, mock<Context>(), jest.fn());
34+
35+
expect(result).toEqual({
36+
statusCode: 400,
37+
body: JSON.stringify({
38+
statusCode: 400,
39+
technicalMessage: 'Invalid request',
40+
}),
41+
});
42+
43+
expect(mocks.templateClient.listTemplates).not.toHaveBeenCalled();
44+
}
45+
);
46+
2047
test('should return 400 - Invalid request when, no user in requestContext', async () => {
2148
const { handler, mocks } = setup();
2249

0 commit comments

Comments
 (0)