@squiz/db-lib 1.77.2 → 1.77.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/dynamodb/AbstractDynamoDbRepository.spec.d.ts.map +1 -1
- package/lib/dynamodb/AbstractDynamoDbRepository.spec.js +109 -101
- package/lib/dynamodb/AbstractDynamoDbRepository.spec.js.map +1 -1
- package/lib/externalized/ExternalizedDynamoDbRepository.d.ts +0 -6
- package/lib/externalized/ExternalizedDynamoDbRepository.d.ts.map +1 -1
- package/lib/externalized/ExternalizedDynamoDbRepository.js +2 -30
- package/lib/externalized/ExternalizedDynamoDbRepository.js.map +1 -1
- package/lib/externalized/ExternalizedDynamoDbRepository.spec.js +7 -19
- package/lib/externalized/ExternalizedDynamoDbRepository.spec.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
- package/src/dynamodb/AbstractDynamoDbRepository.spec.ts +17 -9
- package/src/externalized/ExternalizedDynamoDbRepository.spec.ts +7 -21
- package/src/externalized/ExternalizedDynamoDbRepository.ts +3 -41
- package/src/index.ts +2 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -15,6 +15,14 @@ const client_dynamodb_2 = require("@aws-sdk/client-dynamodb");
|
|
|
15
15
|
const crypto_1 = __importDefault(require("crypto"));
|
|
16
16
|
const InvalidDataFormatError_1 = require("../error/InvalidDataFormatError");
|
|
17
17
|
const ddbClientMock = (0, aws_sdk_client_mock_1.mockClient)(lib_dynamodb_1.DynamoDBDocumentClient);
|
|
18
|
+
const DeleteCommand = lib_dynamodb_1.DeleteCommand;
|
|
19
|
+
const GetCommand = lib_dynamodb_1.GetCommand;
|
|
20
|
+
const PutCommand = lib_dynamodb_1.PutCommand;
|
|
21
|
+
const QueryCommand = lib_dynamodb_1.QueryCommand;
|
|
22
|
+
const UpdateCommand = lib_dynamodb_1.UpdateCommand;
|
|
23
|
+
const TransactWriteCommand = lib_dynamodb_1.TransactWriteCommand;
|
|
24
|
+
const BatchGetCommand = lib_dynamodb_1.BatchGetCommand;
|
|
25
|
+
const BatchWriteCommand = lib_dynamodb_1.BatchWriteCommand;
|
|
18
26
|
const ddbDoc = lib_dynamodb_1.DynamoDBDocument.from(new client_dynamodb_2.DynamoDB({}));
|
|
19
27
|
class TestItem {
|
|
20
28
|
constructor(data = {}) {
|
|
@@ -141,7 +149,7 @@ describe('AbstractRepository', () => {
|
|
|
141
149
|
});
|
|
142
150
|
describe('createItem()', () => {
|
|
143
151
|
it('should create and return the item object if valid input', async () => {
|
|
144
|
-
ddbClientMock.on(
|
|
152
|
+
ddbClientMock.on(PutCommand).resolves({
|
|
145
153
|
$metadata: {
|
|
146
154
|
httpStatusCode: 200,
|
|
147
155
|
},
|
|
@@ -173,7 +181,7 @@ describe('AbstractRepository', () => {
|
|
|
173
181
|
},
|
|
174
182
|
};
|
|
175
183
|
const result = await repository.createItem(item);
|
|
176
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
184
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(PutCommand, input);
|
|
177
185
|
expect(result).toEqual(new TestItem({
|
|
178
186
|
name: 'foo',
|
|
179
187
|
age: 99,
|
|
@@ -186,7 +194,7 @@ describe('AbstractRepository', () => {
|
|
|
186
194
|
}));
|
|
187
195
|
});
|
|
188
196
|
it('should create and return the item with multiple gsi fields', async () => {
|
|
189
|
-
ddbClientMock.on(
|
|
197
|
+
ddbClientMock.on(PutCommand).resolves({
|
|
190
198
|
$metadata: {
|
|
191
199
|
httpStatusCode: 200,
|
|
192
200
|
},
|
|
@@ -222,7 +230,7 @@ describe('AbstractRepository', () => {
|
|
|
222
230
|
email: 'foo@bar.xyz',
|
|
223
231
|
};
|
|
224
232
|
const result = await repository.createItem(item);
|
|
225
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
233
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(PutCommand, input);
|
|
226
234
|
expect(result).toEqual(new TestItem({
|
|
227
235
|
name: 'foo',
|
|
228
236
|
age: 99,
|
|
@@ -266,7 +274,7 @@ describe('AbstractRepository', () => {
|
|
|
266
274
|
});
|
|
267
275
|
describe('updateItem()', () => {
|
|
268
276
|
it('should update and return the item object if valid input', async () => {
|
|
269
|
-
ddbClientMock.on(
|
|
277
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
270
278
|
$metadata: {
|
|
271
279
|
httpStatusCode: 200,
|
|
272
280
|
},
|
|
@@ -277,7 +285,7 @@ describe('AbstractRepository', () => {
|
|
|
277
285
|
data: {},
|
|
278
286
|
},
|
|
279
287
|
});
|
|
280
|
-
ddbClientMock.on(
|
|
288
|
+
ddbClientMock.on(UpdateCommand).resolves({
|
|
281
289
|
$metadata: {
|
|
282
290
|
httpStatusCode: 200,
|
|
283
291
|
},
|
|
@@ -309,7 +317,7 @@ describe('AbstractRepository', () => {
|
|
|
309
317
|
country: 'au-updated',
|
|
310
318
|
};
|
|
311
319
|
const result = await repository.updateItem(updateItem);
|
|
312
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
320
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, UpdateCommand, input);
|
|
313
321
|
expect(result).toEqual(new TestItem({
|
|
314
322
|
name: 'foo',
|
|
315
323
|
age: 99,
|
|
@@ -318,7 +326,7 @@ describe('AbstractRepository', () => {
|
|
|
318
326
|
}));
|
|
319
327
|
});
|
|
320
328
|
it('should only update the changed attributes', async () => {
|
|
321
|
-
ddbClientMock.on(
|
|
329
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
322
330
|
$metadata: {
|
|
323
331
|
httpStatusCode: 200,
|
|
324
332
|
},
|
|
@@ -329,7 +337,7 @@ describe('AbstractRepository', () => {
|
|
|
329
337
|
data: {},
|
|
330
338
|
},
|
|
331
339
|
});
|
|
332
|
-
ddbClientMock.on(
|
|
340
|
+
ddbClientMock.on(UpdateCommand).resolves({
|
|
333
341
|
$metadata: {
|
|
334
342
|
httpStatusCode: 200,
|
|
335
343
|
},
|
|
@@ -359,7 +367,7 @@ describe('AbstractRepository', () => {
|
|
|
359
367
|
data: { active: true },
|
|
360
368
|
};
|
|
361
369
|
const result = await repository.updateItem(updateItem);
|
|
362
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
370
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, UpdateCommand, input);
|
|
363
371
|
expect(result).toEqual(new TestItem({
|
|
364
372
|
name: 'foo',
|
|
365
373
|
age: 99,
|
|
@@ -368,7 +376,7 @@ describe('AbstractRepository', () => {
|
|
|
368
376
|
}));
|
|
369
377
|
});
|
|
370
378
|
it('should not trigger update request if the input attributes are same as in the existing item', async () => {
|
|
371
|
-
ddbClientMock.on(
|
|
379
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
372
380
|
$metadata: {
|
|
373
381
|
httpStatusCode: 200,
|
|
374
382
|
},
|
|
@@ -379,7 +387,7 @@ describe('AbstractRepository', () => {
|
|
|
379
387
|
data: {},
|
|
380
388
|
},
|
|
381
389
|
});
|
|
382
|
-
ddbClientMock.on(
|
|
390
|
+
ddbClientMock.on(UpdateCommand).rejects(new Error('updateItem() called when not expected'));
|
|
383
391
|
// update input attributes are same as in the existing item
|
|
384
392
|
const updateItem = {
|
|
385
393
|
name: 'foo',
|
|
@@ -394,7 +402,7 @@ describe('AbstractRepository', () => {
|
|
|
394
402
|
}));
|
|
395
403
|
});
|
|
396
404
|
it('should return undefined if item does does not exist', async () => {
|
|
397
|
-
ddbClientMock.on(
|
|
405
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
398
406
|
$metadata: {
|
|
399
407
|
httpStatusCode: 200,
|
|
400
408
|
},
|
|
@@ -407,7 +415,7 @@ describe('AbstractRepository', () => {
|
|
|
407
415
|
expect(result).toEqual(undefined);
|
|
408
416
|
});
|
|
409
417
|
it('should return undefined if update cmd conditional check fails', async () => {
|
|
410
|
-
ddbClientMock.on(
|
|
418
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
411
419
|
$metadata: {
|
|
412
420
|
httpStatusCode: 200,
|
|
413
421
|
},
|
|
@@ -418,7 +426,7 @@ describe('AbstractRepository', () => {
|
|
|
418
426
|
data: {},
|
|
419
427
|
},
|
|
420
428
|
});
|
|
421
|
-
ddbClientMock.on(
|
|
429
|
+
ddbClientMock.on(UpdateCommand).rejects(new client_dynamodb_1.ConditionalCheckFailedException({
|
|
422
430
|
$metadata: {},
|
|
423
431
|
message: 'not found',
|
|
424
432
|
}));
|
|
@@ -430,7 +438,7 @@ describe('AbstractRepository', () => {
|
|
|
430
438
|
expect(result).toEqual(undefined);
|
|
431
439
|
});
|
|
432
440
|
it('should throw error update data has invalid data', async () => {
|
|
433
|
-
ddbClientMock.on(
|
|
441
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
434
442
|
$metadata: {
|
|
435
443
|
httpStatusCode: 200,
|
|
436
444
|
},
|
|
@@ -448,7 +456,7 @@ describe('AbstractRepository', () => {
|
|
|
448
456
|
await expect(repository.updateItem(updateItem)).rejects.toEqual(new Error('Invalid "country"'));
|
|
449
457
|
});
|
|
450
458
|
it('should throw error if excess column in input', async () => {
|
|
451
|
-
ddbClientMock.on(
|
|
459
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
452
460
|
$metadata: {
|
|
453
461
|
httpStatusCode: 200,
|
|
454
462
|
},
|
|
@@ -476,7 +484,7 @@ describe('AbstractRepository', () => {
|
|
|
476
484
|
});
|
|
477
485
|
describe('getItem()', () => {
|
|
478
486
|
it('should return the item object if found', async () => {
|
|
479
|
-
ddbClientMock.on(
|
|
487
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
480
488
|
$metadata: {
|
|
481
489
|
httpStatusCode: 200,
|
|
482
490
|
},
|
|
@@ -494,7 +502,7 @@ describe('AbstractRepository', () => {
|
|
|
494
502
|
};
|
|
495
503
|
const partialItem = { name: 'foo' };
|
|
496
504
|
const result = await repository.getItem(partialItem);
|
|
497
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
505
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(GetCommand, input);
|
|
498
506
|
expect(result).toEqual(new TestItem({
|
|
499
507
|
name: 'foo',
|
|
500
508
|
age: 99,
|
|
@@ -507,7 +515,7 @@ describe('AbstractRepository', () => {
|
|
|
507
515
|
}));
|
|
508
516
|
});
|
|
509
517
|
it('should return undefined if item not found', async () => {
|
|
510
|
-
ddbClientMock.on(
|
|
518
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
511
519
|
$metadata: {
|
|
512
520
|
httpStatusCode: 200,
|
|
513
521
|
},
|
|
@@ -518,11 +526,11 @@ describe('AbstractRepository', () => {
|
|
|
518
526
|
};
|
|
519
527
|
const partialItem = { name: 'foo' };
|
|
520
528
|
const result = await repository.getItem(partialItem);
|
|
521
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
529
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(GetCommand, input);
|
|
522
530
|
expect(result).toEqual(undefined);
|
|
523
531
|
});
|
|
524
532
|
it('should throw error if item schema validation fails', async () => {
|
|
525
|
-
ddbClientMock.on(
|
|
533
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
526
534
|
$metadata: {
|
|
527
535
|
httpStatusCode: 200,
|
|
528
536
|
},
|
|
@@ -541,7 +549,7 @@ describe('AbstractRepository', () => {
|
|
|
541
549
|
await expect(repository.getItem(partialItem)).rejects.toEqual(new MissingKeyValuesError_1.MissingKeyValuesError('Key field "name" must be specified in the input item in entity test-item-entity'));
|
|
542
550
|
});
|
|
543
551
|
it('should throw error if JSON string field has non-string data', async () => {
|
|
544
|
-
ddbClientMock.on(
|
|
552
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
545
553
|
$metadata: {
|
|
546
554
|
httpStatusCode: 200,
|
|
547
555
|
},
|
|
@@ -562,7 +570,7 @@ describe('AbstractRepository', () => {
|
|
|
562
570
|
});
|
|
563
571
|
describe('getItems()', () => {
|
|
564
572
|
it('should use BatchGetItem to get result', async () => {
|
|
565
|
-
ddbClientMock.on(
|
|
573
|
+
ddbClientMock.on(BatchGetCommand).resolves({
|
|
566
574
|
$metadata: {
|
|
567
575
|
httpStatusCode: 200,
|
|
568
576
|
},
|
|
@@ -597,7 +605,7 @@ describe('AbstractRepository', () => {
|
|
|
597
605
|
};
|
|
598
606
|
const requestItems = [{ name: 'foo' }, { name: 'foo2' }];
|
|
599
607
|
const result = await repository.getItems(requestItems);
|
|
600
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
608
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(BatchGetCommand, input);
|
|
601
609
|
expect(result).toEqual([
|
|
602
610
|
new TestItem({
|
|
603
611
|
name: 'foo',
|
|
@@ -622,7 +630,7 @@ describe('AbstractRepository', () => {
|
|
|
622
630
|
]);
|
|
623
631
|
});
|
|
624
632
|
it('should remove duplicate items in BatchGetItem request', async () => {
|
|
625
|
-
ddbClientMock.on(
|
|
633
|
+
ddbClientMock.on(BatchGetCommand).resolves({
|
|
626
634
|
$metadata: {
|
|
627
635
|
httpStatusCode: 200,
|
|
628
636
|
},
|
|
@@ -657,7 +665,7 @@ describe('AbstractRepository', () => {
|
|
|
657
665
|
};
|
|
658
666
|
const requestItems = [{ name: 'foo' }, { name: 'foo2' }, { name: 'foo2' }];
|
|
659
667
|
const result = await repository.getItems(requestItems);
|
|
660
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
668
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(BatchGetCommand, input);
|
|
661
669
|
expect(result).toEqual([
|
|
662
670
|
new TestItem({
|
|
663
671
|
name: 'foo',
|
|
@@ -699,7 +707,7 @@ describe('AbstractRepository', () => {
|
|
|
699
707
|
},
|
|
700
708
|
},
|
|
701
709
|
};
|
|
702
|
-
ddbClientMock.on(
|
|
710
|
+
ddbClientMock.on(BatchGetCommand, input1).resolves({
|
|
703
711
|
$metadata: {
|
|
704
712
|
httpStatusCode: 200,
|
|
705
713
|
},
|
|
@@ -720,7 +728,7 @@ describe('AbstractRepository', () => {
|
|
|
720
728
|
},
|
|
721
729
|
},
|
|
722
730
|
});
|
|
723
|
-
ddbClientMock.on(
|
|
731
|
+
ddbClientMock.on(BatchGetCommand, input2).resolves({
|
|
724
732
|
$metadata: {
|
|
725
733
|
httpStatusCode: 200,
|
|
726
734
|
},
|
|
@@ -739,8 +747,8 @@ describe('AbstractRepository', () => {
|
|
|
739
747
|
});
|
|
740
748
|
const requestItems = [{ name: 'foo' }, { name: 'foo2' }];
|
|
741
749
|
const result = await repository.getItems(requestItems);
|
|
742
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
743
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
750
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, BatchGetCommand, input1);
|
|
751
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, BatchGetCommand, input2);
|
|
744
752
|
expect(result).toEqual([
|
|
745
753
|
new TestItem({
|
|
746
754
|
name: 'foo',
|
|
@@ -782,7 +790,7 @@ describe('AbstractRepository', () => {
|
|
|
782
790
|
},
|
|
783
791
|
},
|
|
784
792
|
};
|
|
785
|
-
ddbClientMock.on(
|
|
793
|
+
ddbClientMock.on(BatchGetCommand, input1).resolves({
|
|
786
794
|
$metadata: {
|
|
787
795
|
httpStatusCode: 200,
|
|
788
796
|
},
|
|
@@ -803,7 +811,7 @@ describe('AbstractRepository', () => {
|
|
|
803
811
|
},
|
|
804
812
|
},
|
|
805
813
|
});
|
|
806
|
-
ddbClientMock.on(
|
|
814
|
+
ddbClientMock.on(BatchGetCommand, input2).resolves({
|
|
807
815
|
$metadata: {
|
|
808
816
|
httpStatusCode: 200,
|
|
809
817
|
},
|
|
@@ -816,13 +824,13 @@ describe('AbstractRepository', () => {
|
|
|
816
824
|
});
|
|
817
825
|
const requestItems = [{ name: 'foo' }, { name: 'foo2' }];
|
|
818
826
|
await expect(repository.getItems(requestItems)).rejects.toEqual(new Error('Maximum allowed retries exceeded for unprocessed items'));
|
|
819
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
820
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
821
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(3,
|
|
822
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(4,
|
|
827
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, BatchGetCommand, input1);
|
|
828
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, BatchGetCommand, input2);
|
|
829
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(3, BatchGetCommand, input2);
|
|
830
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(4, BatchGetCommand, input2);
|
|
823
831
|
});
|
|
824
832
|
it('should request BatchGetItem in batch of 100 items to get result', async () => {
|
|
825
|
-
ddbClientMock.on(
|
|
833
|
+
ddbClientMock.on(BatchGetCommand).resolves({
|
|
826
834
|
$metadata: {
|
|
827
835
|
httpStatusCode: 200,
|
|
828
836
|
},
|
|
@@ -856,9 +864,9 @@ describe('AbstractRepository', () => {
|
|
|
856
864
|
},
|
|
857
865
|
};
|
|
858
866
|
await repository.getItems(requestItems);
|
|
859
|
-
expect(ddbClientMock).toHaveReceivedCommandTimes(
|
|
860
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
861
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
867
|
+
expect(ddbClientMock).toHaveReceivedCommandTimes(BatchGetCommand, 2);
|
|
868
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, BatchGetCommand, input1);
|
|
869
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, BatchGetCommand, input2);
|
|
862
870
|
});
|
|
863
871
|
it('should throw error if any input item does not includes key field(s)', async () => {
|
|
864
872
|
const requestItems = [{ name: 'foo' }, { age: 22 }];
|
|
@@ -867,7 +875,7 @@ describe('AbstractRepository', () => {
|
|
|
867
875
|
});
|
|
868
876
|
describe('deleteItems()', () => {
|
|
869
877
|
it('should use batchWrite() to get result', async () => {
|
|
870
|
-
ddbClientMock.on(
|
|
878
|
+
ddbClientMock.on(BatchWriteCommand).resolves({
|
|
871
879
|
$metadata: {
|
|
872
880
|
httpStatusCode: 200,
|
|
873
881
|
},
|
|
@@ -893,10 +901,10 @@ describe('AbstractRepository', () => {
|
|
|
893
901
|
};
|
|
894
902
|
const requestItems = [{ name: 'foo' }, { name: 'foo2' }];
|
|
895
903
|
await repository.deleteItems(requestItems);
|
|
896
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
904
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(BatchWriteCommand, input);
|
|
897
905
|
});
|
|
898
906
|
it('should remove duplicate items in batchWrite() request', async () => {
|
|
899
|
-
ddbClientMock.on(
|
|
907
|
+
ddbClientMock.on(BatchWriteCommand).resolves({
|
|
900
908
|
$metadata: {
|
|
901
909
|
httpStatusCode: 200,
|
|
902
910
|
},
|
|
@@ -922,7 +930,7 @@ describe('AbstractRepository', () => {
|
|
|
922
930
|
};
|
|
923
931
|
const requestItems = [{ name: 'foo' }, { name: 'foo2' }, { name: 'foo2' }, { name: 'foo' }];
|
|
924
932
|
await repository.deleteItems(requestItems);
|
|
925
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
933
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(BatchWriteCommand, input);
|
|
926
934
|
});
|
|
927
935
|
it('should use re-try if unprocessed items returned', async () => {
|
|
928
936
|
const input1 = {
|
|
@@ -952,7 +960,7 @@ describe('AbstractRepository', () => {
|
|
|
952
960
|
],
|
|
953
961
|
},
|
|
954
962
|
};
|
|
955
|
-
ddbClientMock.on(
|
|
963
|
+
ddbClientMock.on(BatchWriteCommand, input1).resolves({
|
|
956
964
|
$metadata: {
|
|
957
965
|
httpStatusCode: 200,
|
|
958
966
|
},
|
|
@@ -966,7 +974,7 @@ describe('AbstractRepository', () => {
|
|
|
966
974
|
],
|
|
967
975
|
},
|
|
968
976
|
});
|
|
969
|
-
ddbClientMock.on(
|
|
977
|
+
ddbClientMock.on(BatchWriteCommand, input2).resolves({
|
|
970
978
|
$metadata: {
|
|
971
979
|
httpStatusCode: 200,
|
|
972
980
|
},
|
|
@@ -974,8 +982,8 @@ describe('AbstractRepository', () => {
|
|
|
974
982
|
});
|
|
975
983
|
const requestItems = [{ name: 'foo' }, { name: 'foo2' }];
|
|
976
984
|
await repository.deleteItems(requestItems);
|
|
977
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
978
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
985
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, BatchWriteCommand, input1);
|
|
986
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, BatchWriteCommand, input2);
|
|
979
987
|
});
|
|
980
988
|
it('should fail after max number of retries', async () => {
|
|
981
989
|
const input1 = {
|
|
@@ -1005,7 +1013,7 @@ describe('AbstractRepository', () => {
|
|
|
1005
1013
|
],
|
|
1006
1014
|
},
|
|
1007
1015
|
};
|
|
1008
|
-
ddbClientMock.on(
|
|
1016
|
+
ddbClientMock.on(BatchWriteCommand).resolves({
|
|
1009
1017
|
$metadata: {
|
|
1010
1018
|
httpStatusCode: 200,
|
|
1011
1019
|
},
|
|
@@ -1021,13 +1029,13 @@ describe('AbstractRepository', () => {
|
|
|
1021
1029
|
});
|
|
1022
1030
|
const requestItems = [{ name: 'foo' }, { name: 'foo2' }];
|
|
1023
1031
|
await expect(repository.deleteItems(requestItems)).rejects.toEqual(new Error('Maximum allowed retries exceeded for unprocessed items'));
|
|
1024
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
1025
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
1026
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(3,
|
|
1027
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(4,
|
|
1032
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, BatchWriteCommand, input1);
|
|
1033
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, BatchWriteCommand, input2);
|
|
1034
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(3, BatchWriteCommand, input2);
|
|
1035
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(4, BatchWriteCommand, input2);
|
|
1028
1036
|
});
|
|
1029
1037
|
it('should request batchWrite in batch of 25 items to get result', async () => {
|
|
1030
|
-
ddbClientMock.on(
|
|
1038
|
+
ddbClientMock.on(BatchWriteCommand).resolves({
|
|
1031
1039
|
$metadata: {
|
|
1032
1040
|
httpStatusCode: 200,
|
|
1033
1041
|
},
|
|
@@ -1069,9 +1077,9 @@ describe('AbstractRepository', () => {
|
|
|
1069
1077
|
},
|
|
1070
1078
|
};
|
|
1071
1079
|
await repository.deleteItems(requestItems);
|
|
1072
|
-
expect(ddbClientMock).toHaveReceivedCommandTimes(
|
|
1073
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
1074
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
1080
|
+
expect(ddbClientMock).toHaveReceivedCommandTimes(BatchWriteCommand, 2);
|
|
1081
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, BatchWriteCommand, input1);
|
|
1082
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, BatchWriteCommand, input2);
|
|
1075
1083
|
});
|
|
1076
1084
|
it('should throw error if any input item does not includes key field(s)', async () => {
|
|
1077
1085
|
const requestItems = [{ name: 'foo' }, { age: 22 }];
|
|
@@ -1080,7 +1088,7 @@ describe('AbstractRepository', () => {
|
|
|
1080
1088
|
});
|
|
1081
1089
|
describe('queryItems()', () => {
|
|
1082
1090
|
it('should return the items if found', async () => {
|
|
1083
|
-
ddbClientMock.on(
|
|
1091
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1084
1092
|
$metadata: {
|
|
1085
1093
|
httpStatusCode: 200,
|
|
1086
1094
|
},
|
|
@@ -1105,7 +1113,7 @@ describe('AbstractRepository', () => {
|
|
|
1105
1113
|
};
|
|
1106
1114
|
const partialItem = { name: 'foo' };
|
|
1107
1115
|
const result = await repository.queryItems(partialItem);
|
|
1108
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1116
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1109
1117
|
expect(result).toEqual([
|
|
1110
1118
|
new TestItem({
|
|
1111
1119
|
name: 'foo',
|
|
@@ -1116,7 +1124,7 @@ describe('AbstractRepository', () => {
|
|
|
1116
1124
|
]);
|
|
1117
1125
|
});
|
|
1118
1126
|
it('should return empty array if no items found', async () => {
|
|
1119
|
-
ddbClientMock.on(
|
|
1127
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1120
1128
|
$metadata: {
|
|
1121
1129
|
httpStatusCode: 200,
|
|
1122
1130
|
},
|
|
@@ -1133,11 +1141,11 @@ describe('AbstractRepository', () => {
|
|
|
1133
1141
|
};
|
|
1134
1142
|
const partialItem = { name: 'foo' };
|
|
1135
1143
|
const result = await repository.queryItems(partialItem);
|
|
1136
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1144
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1137
1145
|
expect(result).toEqual([]);
|
|
1138
1146
|
});
|
|
1139
1147
|
it('should use sort key in query if "useSortKey" param is true', async () => {
|
|
1140
|
-
ddbClientMock.on(
|
|
1148
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1141
1149
|
$metadata: {
|
|
1142
1150
|
httpStatusCode: 200,
|
|
1143
1151
|
},
|
|
@@ -1156,10 +1164,10 @@ describe('AbstractRepository', () => {
|
|
|
1156
1164
|
};
|
|
1157
1165
|
const partialItem = { name: 'foo' };
|
|
1158
1166
|
const _result = await repository.queryItems(partialItem, { useSortKey: true });
|
|
1159
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1167
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1160
1168
|
});
|
|
1161
1169
|
it('should return the items if found when using gsi index', async () => {
|
|
1162
|
-
ddbClientMock.on(
|
|
1170
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1163
1171
|
$metadata: {
|
|
1164
1172
|
httpStatusCode: 200,
|
|
1165
1173
|
},
|
|
@@ -1193,7 +1201,7 @@ describe('AbstractRepository', () => {
|
|
|
1193
1201
|
const partialItem = { country: 'au' };
|
|
1194
1202
|
const useSortKey = false;
|
|
1195
1203
|
const result = await repository.queryItems(partialItem, { useSortKey, index });
|
|
1196
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1204
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1197
1205
|
expect(result).toEqual([
|
|
1198
1206
|
new TestItem({
|
|
1199
1207
|
name: 'foo',
|
|
@@ -1210,7 +1218,7 @@ describe('AbstractRepository', () => {
|
|
|
1210
1218
|
]);
|
|
1211
1219
|
});
|
|
1212
1220
|
it('should use sort key in query if "useSortKey" param is true when using gsi index', async () => {
|
|
1213
|
-
ddbClientMock.on(
|
|
1221
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1214
1222
|
$metadata: {
|
|
1215
1223
|
httpStatusCode: 200,
|
|
1216
1224
|
},
|
|
@@ -1232,10 +1240,10 @@ describe('AbstractRepository', () => {
|
|
|
1232
1240
|
const partialItem = { age: 99, country: 'au' };
|
|
1233
1241
|
const useSortKey = true;
|
|
1234
1242
|
const _result = await repository.queryItems(partialItem, { useSortKey, index });
|
|
1235
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1243
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1236
1244
|
});
|
|
1237
1245
|
it('should set input query correctly when "filter - begins_with" query option is set', async () => {
|
|
1238
|
-
ddbClientMock.on(
|
|
1246
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1239
1247
|
$metadata: {
|
|
1240
1248
|
httpStatusCode: 200,
|
|
1241
1249
|
},
|
|
@@ -1260,10 +1268,10 @@ describe('AbstractRepository', () => {
|
|
|
1260
1268
|
},
|
|
1261
1269
|
};
|
|
1262
1270
|
await repository.queryItems(partialItem, queryOptions);
|
|
1263
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1271
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1264
1272
|
});
|
|
1265
1273
|
it('should throw error invalid "filter" query option is set', async () => {
|
|
1266
|
-
ddbClientMock.on(
|
|
1274
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1267
1275
|
$metadata: {
|
|
1268
1276
|
httpStatusCode: 200,
|
|
1269
1277
|
},
|
|
@@ -1278,7 +1286,7 @@ describe('AbstractRepository', () => {
|
|
|
1278
1286
|
await expect(repository.queryItems(partialItem, queryOptions)).rejects.toEqual(new Error(`Invalid query filter type: invalid-type`));
|
|
1279
1287
|
});
|
|
1280
1288
|
it('should set input query correctly when "limit" query option is set', async () => {
|
|
1281
|
-
ddbClientMock.on(
|
|
1289
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1282
1290
|
$metadata: {
|
|
1283
1291
|
httpStatusCode: 200,
|
|
1284
1292
|
},
|
|
@@ -1299,10 +1307,10 @@ describe('AbstractRepository', () => {
|
|
|
1299
1307
|
const partialItem = { name: 'foo' };
|
|
1300
1308
|
const queryOptions = { limit: 33 };
|
|
1301
1309
|
await repository.queryItems(partialItem, queryOptions);
|
|
1302
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1310
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1303
1311
|
});
|
|
1304
1312
|
it('should set input query correctly when "order asc" query option is set', async () => {
|
|
1305
|
-
ddbClientMock.on(
|
|
1313
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1306
1314
|
$metadata: {
|
|
1307
1315
|
httpStatusCode: 200,
|
|
1308
1316
|
},
|
|
@@ -1321,10 +1329,10 @@ describe('AbstractRepository', () => {
|
|
|
1321
1329
|
const partialItem = { name: 'foo' };
|
|
1322
1330
|
const queryOptions = { order: 'asc' };
|
|
1323
1331
|
await repository.queryItems(partialItem, queryOptions);
|
|
1324
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1332
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1325
1333
|
});
|
|
1326
1334
|
it('should set input query correctly when "order desc" query option is set', async () => {
|
|
1327
|
-
ddbClientMock.on(
|
|
1335
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1328
1336
|
$metadata: {
|
|
1329
1337
|
httpStatusCode: 200,
|
|
1330
1338
|
},
|
|
@@ -1343,7 +1351,7 @@ describe('AbstractRepository', () => {
|
|
|
1343
1351
|
const partialItem = { name: 'foo' };
|
|
1344
1352
|
const queryOptions = { order: 'desc' };
|
|
1345
1353
|
await repository.queryItems(partialItem, queryOptions);
|
|
1346
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1354
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1347
1355
|
});
|
|
1348
1356
|
it('should throw error for invalid index query', async () => {
|
|
1349
1357
|
const index = 'undefined-index';
|
|
@@ -1400,7 +1408,7 @@ describe('AbstractRepository', () => {
|
|
|
1400
1408
|
},
|
|
1401
1409
|
];
|
|
1402
1410
|
it('should return all items when there is only 1 page of results', async () => {
|
|
1403
|
-
ddbClientMock.on(
|
|
1411
|
+
ddbClientMock.on(QueryCommand).resolves({
|
|
1404
1412
|
Items: [mockItems[0], mockItems[1], mockItems[2]],
|
|
1405
1413
|
});
|
|
1406
1414
|
const input = {
|
|
@@ -1415,14 +1423,14 @@ describe('AbstractRepository', () => {
|
|
|
1415
1423
|
};
|
|
1416
1424
|
const partialItem = { name: 'foo' };
|
|
1417
1425
|
const result = await repository.queryItems(partialItem);
|
|
1418
|
-
expect(ddbClientMock).toHaveReceivedCommandTimes(
|
|
1419
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1426
|
+
expect(ddbClientMock).toHaveReceivedCommandTimes(QueryCommand, 1);
|
|
1427
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(QueryCommand, input);
|
|
1420
1428
|
expect(result).toEqual([new TestItem(mockItems[0]), new TestItem(mockItems[1]), new TestItem(mockItems[2])]);
|
|
1421
1429
|
});
|
|
1422
1430
|
it('should return all items when there are more than 1 page of results', async () => {
|
|
1423
1431
|
const mockLastEvaluatedKey = { pk: { S: 'test_item#foo' }, sk: { S: 'name#bar' } };
|
|
1424
1432
|
ddbClientMock
|
|
1425
|
-
.on(
|
|
1433
|
+
.on(QueryCommand)
|
|
1426
1434
|
.resolvesOnce({
|
|
1427
1435
|
Items: [mockItems[0], mockItems[1], mockItems[2]],
|
|
1428
1436
|
LastEvaluatedKey: mockLastEvaluatedKey,
|
|
@@ -1442,9 +1450,9 @@ describe('AbstractRepository', () => {
|
|
|
1442
1450
|
};
|
|
1443
1451
|
const partialItem = { name: 'foo' };
|
|
1444
1452
|
const result = await repository.queryItems(partialItem);
|
|
1445
|
-
expect(ddbClientMock).toHaveReceivedCommandTimes(
|
|
1446
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
1447
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
1453
|
+
expect(ddbClientMock).toHaveReceivedCommandTimes(QueryCommand, 2);
|
|
1454
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, QueryCommand, input);
|
|
1455
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, QueryCommand, {
|
|
1448
1456
|
...input,
|
|
1449
1457
|
ExclusiveStartKey: mockLastEvaluatedKey,
|
|
1450
1458
|
});
|
|
@@ -1460,7 +1468,7 @@ describe('AbstractRepository', () => {
|
|
|
1460
1468
|
const mockLimit = 2;
|
|
1461
1469
|
const mockLastEvaluatedKey = { pk: { S: 'test_item#foo' }, sk: { S: 'name#bar' } };
|
|
1462
1470
|
ddbClientMock
|
|
1463
|
-
.on(
|
|
1471
|
+
.on(QueryCommand)
|
|
1464
1472
|
.resolvesOnce({
|
|
1465
1473
|
Items: [mockItems[0], mockItems[1], mockItems[2]],
|
|
1466
1474
|
LastEvaluatedKey: mockLastEvaluatedKey,
|
|
@@ -1481,15 +1489,15 @@ describe('AbstractRepository', () => {
|
|
|
1481
1489
|
// Only expect first two items from the first page of results.
|
|
1482
1490
|
const partialItem = { name: 'foo' };
|
|
1483
1491
|
const result = await repository.queryItems(partialItem, { limit: mockLimit });
|
|
1484
|
-
expect(ddbClientMock).toHaveReceivedCommandTimes(
|
|
1485
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
1492
|
+
expect(ddbClientMock).toHaveReceivedCommandTimes(QueryCommand, 1);
|
|
1493
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, QueryCommand, input);
|
|
1486
1494
|
expect(result).toEqual([new TestItem(mockItems[0]), new TestItem(mockItems[1])]);
|
|
1487
1495
|
});
|
|
1488
1496
|
it('should return items up to the limit when limit spans multiple pages', async () => {
|
|
1489
1497
|
const mockLimit = 4;
|
|
1490
1498
|
const mockLastEvaluatedKey = { pk: { S: 'test_item#foo' }, sk: { S: 'name#bar' } };
|
|
1491
1499
|
ddbClientMock
|
|
1492
|
-
.on(
|
|
1500
|
+
.on(QueryCommand)
|
|
1493
1501
|
.resolvesOnce({
|
|
1494
1502
|
Items: [mockItems[0], mockItems[1], mockItems[2]],
|
|
1495
1503
|
LastEvaluatedKey: mockLastEvaluatedKey,
|
|
@@ -1511,9 +1519,9 @@ describe('AbstractRepository', () => {
|
|
|
1511
1519
|
// Expect all 3 results from first page, but only 1 result from second page.
|
|
1512
1520
|
const partialItem = { name: 'foo' };
|
|
1513
1521
|
const result = await repository.queryItems(partialItem, { limit: mockLimit });
|
|
1514
|
-
expect(ddbClientMock).toHaveReceivedCommandTimes(
|
|
1515
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(1,
|
|
1516
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
1522
|
+
expect(ddbClientMock).toHaveReceivedCommandTimes(QueryCommand, 2);
|
|
1523
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(1, QueryCommand, input);
|
|
1524
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, QueryCommand, {
|
|
1517
1525
|
...input,
|
|
1518
1526
|
ExclusiveStartKey: mockLastEvaluatedKey,
|
|
1519
1527
|
});
|
|
@@ -1528,7 +1536,7 @@ describe('AbstractRepository', () => {
|
|
|
1528
1536
|
});
|
|
1529
1537
|
describe('deleteItem()', () => {
|
|
1530
1538
|
it('should return 1 when item is found and deleted', async () => {
|
|
1531
|
-
ddbClientMock.on(
|
|
1539
|
+
ddbClientMock.on(DeleteCommand).resolves({
|
|
1532
1540
|
$metadata: {
|
|
1533
1541
|
httpStatusCode: 200,
|
|
1534
1542
|
},
|
|
@@ -1539,11 +1547,11 @@ describe('AbstractRepository', () => {
|
|
|
1539
1547
|
};
|
|
1540
1548
|
const partialItem = { name: 'foo' };
|
|
1541
1549
|
const result = await repository.deleteItem(partialItem);
|
|
1542
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1550
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(DeleteCommand, input);
|
|
1543
1551
|
expect(result).toBe(1);
|
|
1544
1552
|
});
|
|
1545
1553
|
it('should return 0 when item is not found', async () => {
|
|
1546
|
-
ddbClientMock.on(
|
|
1554
|
+
ddbClientMock.on(DeleteCommand).rejects(new client_dynamodb_1.ConditionalCheckFailedException({
|
|
1547
1555
|
$metadata: {},
|
|
1548
1556
|
message: 'not found',
|
|
1549
1557
|
}));
|
|
@@ -1553,12 +1561,12 @@ describe('AbstractRepository', () => {
|
|
|
1553
1561
|
};
|
|
1554
1562
|
const partialItem = { name: 'foo' };
|
|
1555
1563
|
const result = await repository.deleteItem(partialItem);
|
|
1556
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1564
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(DeleteCommand, input);
|
|
1557
1565
|
expect(result).toBe(0);
|
|
1558
1566
|
});
|
|
1559
1567
|
it('should throw error if request fails', async () => {
|
|
1560
1568
|
const partialItem = { name: 'foo' };
|
|
1561
|
-
ddbClientMock.on(
|
|
1569
|
+
ddbClientMock.on(DeleteCommand).rejects('some other error');
|
|
1562
1570
|
await expect(repository.deleteItem(partialItem)).rejects.toEqual(new Error('some other error'));
|
|
1563
1571
|
});
|
|
1564
1572
|
it('should throw error if input does not includes key field(s)', async () => {
|
|
@@ -1570,7 +1578,7 @@ describe('AbstractRepository', () => {
|
|
|
1570
1578
|
it('should execute the multiple transaction write request in a single request', async () => {
|
|
1571
1579
|
const spy = jest.spyOn(crypto_1.default, 'randomUUID');
|
|
1572
1580
|
spy.mockImplementation(() => 'some-token');
|
|
1573
|
-
ddbClientMock.on(
|
|
1581
|
+
ddbClientMock.on(GetCommand).resolves({
|
|
1574
1582
|
$metadata: {
|
|
1575
1583
|
httpStatusCode: 200,
|
|
1576
1584
|
},
|
|
@@ -1581,7 +1589,7 @@ describe('AbstractRepository', () => {
|
|
|
1581
1589
|
data: {},
|
|
1582
1590
|
},
|
|
1583
1591
|
});
|
|
1584
|
-
ddbClientMock.on(
|
|
1592
|
+
ddbClientMock.on(TransactWriteCommand).resolves({
|
|
1585
1593
|
$metadata: {
|
|
1586
1594
|
httpStatusCode: 200,
|
|
1587
1595
|
},
|
|
@@ -1648,7 +1656,7 @@ describe('AbstractRepository', () => {
|
|
|
1648
1656
|
},
|
|
1649
1657
|
],
|
|
1650
1658
|
};
|
|
1651
|
-
expect(ddbClientMock).toHaveReceivedNthCommandWith(2,
|
|
1659
|
+
expect(ddbClientMock).toHaveReceivedNthCommandWith(2, TransactWriteCommand, input);
|
|
1652
1660
|
expect(result).toEqual({
|
|
1653
1661
|
name: 'foo3',
|
|
1654
1662
|
age: 11,
|
|
@@ -1660,7 +1668,7 @@ describe('AbstractRepository', () => {
|
|
|
1660
1668
|
describe('Entity definitions having keys with the object properties', () => {
|
|
1661
1669
|
it('should use the correct keys in the request', async () => {
|
|
1662
1670
|
const repository = new TestItem2Repository(TABLE_NAME, ddbManager);
|
|
1663
|
-
ddbClientMock.on(
|
|
1671
|
+
ddbClientMock.on(PutCommand).resolves({
|
|
1664
1672
|
$metadata: {
|
|
1665
1673
|
httpStatusCode: 200,
|
|
1666
1674
|
},
|
|
@@ -1698,7 +1706,7 @@ describe('AbstractRepository', () => {
|
|
|
1698
1706
|
},
|
|
1699
1707
|
};
|
|
1700
1708
|
const result = await repository.createItem(item);
|
|
1701
|
-
expect(ddbClientMock).toHaveReceivedCommandWith(
|
|
1709
|
+
expect(ddbClientMock).toHaveReceivedCommandWith(PutCommand, input);
|
|
1702
1710
|
expect(result).toEqual(new TestItem2({
|
|
1703
1711
|
date: '2025-02-26',
|
|
1704
1712
|
info: {
|