1
1
import { BatchGet , MAX_READ_BATCH_SIZE } from './BatchGet' ;
2
- import { AttributeMap , BatchGetItemOutput } from 'aws-sdk/clients/dynamodb' ;
2
+ import { AttributeMap , BatchGetItemInput , BatchGetItemOutput } from 'aws-sdk/clients/dynamodb' ;
3
3
4
4
describe ( 'BatchGet' , ( ) => {
5
5
const promiseFunc = jest . fn ( ( ) => Promise . resolve ( {
6
- UnprocessedItems : { }
7
- } ) ) ;
6
+ UnprocessedKeys : { }
7
+ } as BatchGetItemOutput ) ) ;
8
8
const mockDynamoDbClient = {
9
9
config : { } ,
10
10
batchGetItem : jest . fn ( ( ) => ( { promise : promiseFunc } ) ) ,
11
- } ;
11
+ } as any ;
12
12
13
13
beforeEach ( ( ) => {
14
14
promiseFunc . mockClear ( ) ;
@@ -279,7 +279,7 @@ describe('BatchGet', () => {
279
279
const buzz = { S : 'Static string' } ;
280
280
const response : BatchGetItemOutput = { } ;
281
281
282
- const { RequestItems} = mockDynamoDbClient . batchGetItem . mock . calls . slice ( - 1 ) [ 0 ] [ 0 ] ;
282
+ const { RequestItems} = ( mockDynamoDbClient . batchGetItem . mock . calls . slice ( - 1 ) [ 0 ] as any ) [ 0 ] ;
283
283
for ( const tableName of Object . keys ( RequestItems ) ) {
284
284
for ( const item of RequestItems [ tableName ] . Keys ) {
285
285
if ( toBeFailed . has ( item . fizz . N ) ) {
@@ -310,7 +310,7 @@ describe('BatchGet', () => {
310
310
}
311
311
}
312
312
313
- return response ;
313
+ return Promise . resolve ( response ) ;
314
314
} ) ;
315
315
316
316
const input = asyncInput
@@ -348,8 +348,7 @@ describe('BatchGet', () => {
348
348
const { calls} = mockDynamoDbClient . batchGetItem . mock ;
349
349
expect ( calls . length ) . toBe ( Math . ceil ( gets . length / MAX_READ_BATCH_SIZE ) ) ;
350
350
351
-
352
- const callCount : { [ key : string ] : number } = calls . reduce (
351
+ const callCount : { [ key : string ] : number } = ( calls as Array < Array < BatchGetItemInput > > ) . reduce (
353
352
(
354
353
keyUseCount : { [ key : string ] : number } ,
355
354
[ { RequestItems} ]
@@ -359,10 +358,12 @@ describe('BatchGet', () => {
359
358
keys . push ( ...RequestItems [ table ] . Keys ) ;
360
359
}
361
360
for ( const { fizz : { N : key } } of keys ) {
362
- if ( key in keyUseCount ) {
363
- keyUseCount [ key ] ++ ;
364
- } else {
365
- keyUseCount [ key ] = 1 ;
361
+ if ( key ) {
362
+ if ( key in keyUseCount ) {
363
+ keyUseCount [ key ] ++ ;
364
+ } else {
365
+ keyUseCount [ key ] = 1 ;
366
+ }
366
367
}
367
368
}
368
369
0 commit comments