@@ -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