Skip to content

Commit 0055b8b

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/CCM-10385-fix-logging
2 parents bc20c41 + 52ced5c commit 0055b8b

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

lambdas/backend-api/src/__tests__/templates/infra/template-repository.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,76 @@ describe('templateRepository', () => {
294294
});
295295
});
296296

297+
test('should return error when UnprocessedKeys are returned', async () => {
298+
const { templateRepository, mocks } = setup();
299+
300+
mocks.ddbDocClient.on(BatchGetCommand).resolves({
301+
Responses: {
302+
[templatesTableName]: [],
303+
},
304+
UnprocessedKeys: {
305+
[templatesTableName]: {
306+
Keys: [
307+
{
308+
id: 'abc-def-ghi-jkl-123',
309+
owner: 'userid',
310+
},
311+
],
312+
},
313+
},
314+
});
315+
316+
const response = await templateRepository.get('abc-def-ghi-jkl-123', {
317+
userId: 'userid',
318+
clientId: undefined,
319+
});
320+
321+
expect(response).toEqual({
322+
error: {
323+
code: 500,
324+
message: 'Failed to get template',
325+
actualError: new Error('Partial failure of batch get templates'),
326+
},
327+
});
328+
});
329+
330+
test('should return error when more than one template is returned', async () => {
331+
const { templateRepository, mocks } = setup();
332+
333+
mocks.ddbDocClient.on(BatchGetCommand).resolves({
334+
Responses: {
335+
[templatesTableName]: [
336+
{
337+
id: 'abc-def-ghi-jkl-123',
338+
owner: 'userid',
339+
templateStatus: 'NOT_YET_SUBMITTED',
340+
},
341+
{
342+
id: 'abc-def-ghi-jkl-123',
343+
owner: 'CLIENT#clientid',
344+
templateStatus: 'NOT_YET_SUBMITTED',
345+
},
346+
],
347+
},
348+
UnprocessedKeys: {},
349+
});
350+
351+
const response = await templateRepository.get('abc-def-ghi-jkl-123', {
352+
userId: 'userid',
353+
clientId: 'clientid',
354+
});
355+
356+
expect(response).toEqual({
357+
error: {
358+
code: 500,
359+
message: 'Failed to get template',
360+
actualError: new Error(
361+
'Unexpectedly found both a client owned and a user owned template'
362+
),
363+
},
364+
});
365+
});
366+
297367
test('should return template', async () => {
298368
const { templateRepository, mocks } = setup();
299369

0 commit comments

Comments
 (0)