Skip to content

Commit d37c36f

Browse files
committed
Fix + cleanup test.
1 parent 4ecb29c commit d37c36f

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/from/dynamodb.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const fromDynamodb = (event, {
3535
type: `${calculateEventTypePrefix(record, { skFn, discriminatorFn, eventTypePrefix })}-${calculateEventTypeSuffix(record)}`,
3636
partitionKey: record.dynamodb.Keys[pkFn].S,
3737
timestamp: deriveTimestamp(record),
38+
approximateCreationTimestamp: ddbApproximateCreationTimestamp(record),
3839
tags: {
3940
region: record.awsRegion,
4041
},
@@ -89,7 +90,9 @@ const calculateEventTypeSuffix = (record) => {
8990
};
9091

9192
const deriveTimestamp = (record) =>
92-
record.dynamodb.NewImage?.timestamp || (record.dynamodb.ApproximateCreationDateTime * 1000);
93+
parseInt(record.dynamodb.NewImage?.timestamp?.N, 10) || ddbApproximateCreationTimestamp(record);
94+
95+
const ddbApproximateCreationTimestamp = (record) => record.dynamodb.ApproximateCreationDateTime * 1000;
9396

9497
//--------------------------------------------
9598
// global table support - version: 2017.11.29

test/unit/from/dynamodb.test.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describe('from/dynamodb.js', () => {
9393
type: 'thing-created',
9494
partitionKey: '1',
9595
timestamp: 1572832690000,
96+
approximateCreationTimestamp: 1572832690000,
9697
tags: {
9798
region: 'us-west-2',
9899
},
@@ -111,7 +112,7 @@ describe('from/dynamodb.js', () => {
111112
.done(done);
112113
});
113114

114-
it('should prefer image timestamp if present on INSERT', (done) => {
115+
it('should prefer image timestamp if present', (done) => {
115116
const events = toDynamodbRecords([
116117
{
117118
timestamp: 1572832690,
@@ -124,7 +125,7 @@ describe('from/dynamodb.js', () => {
124125
sk: 'thing',
125126
discriminator: 'thing',
126127
name: 'n1',
127-
timestamp: 1572832690001
128+
timestamp: 1572832690001,
128129
// insert in the current region will not have the awsregion field
129130
},
130131
},
@@ -188,6 +189,9 @@ describe('from/dynamodb.js', () => {
188189
name: {
189190
S: 'n1',
190191
},
192+
timestamp: {
193+
N: '1572832690001',
194+
},
191195
},
192196
OldImage: undefined,
193197
SequenceNumber: '0',
@@ -198,7 +202,8 @@ describe('from/dynamodb.js', () => {
198202
id: '0',
199203
type: 'thing-created',
200204
partitionKey: '1',
201-
timestamp: 1572832690000,
205+
timestamp: 1572832690001,
206+
approximateCreationTimestamp: 1572832690000,
202207
tags: {
203208
region: 'us-west-2',
204209
},
@@ -208,6 +213,7 @@ describe('from/dynamodb.js', () => {
208213
sk: 'thing',
209214
discriminator: 'thing',
210215
name: 'n1',
216+
timestamp: 1572832690001,
211217
},
212218
old: undefined,
213219
},
@@ -334,6 +340,7 @@ describe('from/dynamodb.js', () => {
334340
type: 'thing-updated',
335341
partitionKey: '1',
336342
timestamp: 1572832690000,
343+
approximateCreationTimestamp: 1572832690000,
337344
tags: {
338345
region: 'us-west-2',
339346
},
@@ -440,6 +447,7 @@ describe('from/dynamodb.js', () => {
440447
type: 'thing-deleted',
441448
partitionKey: '1',
442449
timestamp: 1572832690000,
450+
approximateCreationTimestamp: 1572832690000,
443451
tags: {
444452
region: 'us-west-2',
445453
},
@@ -549,6 +557,7 @@ describe('from/dynamodb.js', () => {
549557
type: 'thing-deleted',
550558
partitionKey: '1',
551559
timestamp: 1572832690000,
560+
approximateCreationTimestamp: 1572832690000,
552561
tags: {
553562
region: 'us-west-2',
554563
},
@@ -673,6 +682,7 @@ describe('from/dynamodb.js', () => {
673682
type: 'thing-undeleted',
674683
partitionKey: '1',
675684
timestamp: 1572832690000,
685+
approximateCreationTimestamp: 1572832690000,
676686
tags: {
677687
region: 'us-west-2',
678688
},
@@ -771,6 +781,7 @@ describe('from/dynamodb.js', () => {
771781
type: 'thing-deleted',
772782
partitionKey: '1',
773783
timestamp: 1573005490000,
784+
approximateCreationTimestamp: 1573005490000,
774785
tags: {
775786
region: 'us-west-2',
776787
},
@@ -948,6 +959,7 @@ describe('from/dynamodb.js', () => {
948959
type: 'thing-updated',
949960
partitionKey: '1',
950961
timestamp: 1572832690000,
962+
approximateCreationTimestamp: 1572832690000,
951963
tags: {
952964
region: 'us-west-2',
953965
},
@@ -1029,6 +1041,7 @@ describe('from/dynamodb.js', () => {
10291041
type: 'thing-updated',
10301042
partitionKey: '1',
10311043
timestamp: 1572832990000,
1044+
approximateCreationTimestamp: 1572832990000,
10321045
tags: {
10331046
region: 'us-east-1',
10341047
},

test/unit/utils/encryption.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('utils/encryption.js', () => {
6262
type: 'thing-created',
6363
partitionKey: '1',
6464
timestamp: 1572832690000,
65+
approximateCreationTimestamp: 1572832690000,
6566
tags: {
6667
region: 'us-west-2',
6768
},
@@ -394,6 +395,7 @@ describe('utils/encryption.js', () => {
394395
type: 'thing-created',
395396
partitionKey: '1',
396397
timestamp: 1572832690000,
398+
approximateCreationTimestamp: 1572832690000,
397399
tags: {
398400
region: 'us-west-2',
399401
},
@@ -475,6 +477,7 @@ describe('utils/encryption.js', () => {
475477
type: 'thing-updated',
476478
partitionKey: '1',
477479
timestamp: 1572832690000,
480+
approximateCreationTimestamp: 1572832690000,
478481
tags: {
479482
region: 'us-west-2',
480483
},
@@ -545,6 +548,7 @@ describe('utils/encryption.js', () => {
545548
type: 'thing-deleted',
546549
partitionKey: '1',
547550
timestamp: 1572832690000,
551+
approximateCreationTimestamp: 1572832690000,
548552
tags: {
549553
region: 'us-west-2',
550554
},

0 commit comments

Comments
 (0)