Skip to content

Commit e52604b

Browse files
Add flag to allow skipping of the outLatched
1 parent 77b08b4 commit e52604b

2 files changed

Lines changed: 95 additions & 1 deletion

File tree

src/flavors/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { normalize } from './correlate';
1818

1919
export const update = (rule) => (s) => s // eslint-disable-line import/prefer-default-export
2020
// reacting to collected events vs change events
21-
.filter(outLatched)
21+
.filter((uow) => (rule.skipLatched ? true : outLatched(uow)))
2222
.map((uow) => (uow.record.eventName === 'INSERT' && uow.record.dynamodb.Keys.sk.S === 'EVENT' ? /* istanbul ignore next */ normalize(uow) : uow))
2323

2424
.filter(onEventType(rule))

test/unit/flavors/update.test.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,100 @@ describe('flavors/update.js', () => {
477477
})
478478
.done(done);
479479
});
480+
481+
it('should execute if latched but skipLatched flag is set', (done) => {
482+
sinon.stub(DynamoDBConnector.prototype, 'query').resolves([]);
483+
sinon.stub(DynamoDBConnector.prototype, 'batchGet').resolves({
484+
Responses: {
485+
undefined: [{
486+
pk: '2',
487+
sk: 'thing',
488+
discriminator: 'thing',
489+
name: 'thing2',
490+
}],
491+
},
492+
UnprocessedKeys: {},
493+
});
494+
495+
sinon.stub(KmsConnector.prototype, 'generateDataKey').resolves(MOCK_GEN_DK_RESPONSE);
496+
const events = toDynamodbRecords([
497+
{
498+
timestamp: 1572832690,
499+
keys: {
500+
pk: '1',
501+
sk: 'thing',
502+
},
503+
newImage: {
504+
pk: '1',
505+
sk: 'thing',
506+
discriminator: 'thing',
507+
name: 'Thing One',
508+
description: 'This is thing one',
509+
otherThing: 'thing|2',
510+
latched: true,
511+
ttl: 1549053422,
512+
timestamp: 1548967022000,
513+
},
514+
},
515+
]);
516+
517+
initialize({
518+
...initializeFrom([
519+
{
520+
id: 'update1',
521+
flavor: update,
522+
eventType: /thing-*/,
523+
filters: [() => true],
524+
toGetRequest,
525+
fks: ['otherThing'],
526+
toUpdateRequest,
527+
skipLatched: true,
528+
}]),
529+
}, { ...defaultOptions, AES: false })
530+
.assemble(fromDynamodb(events), false)
531+
.collect()
532+
// .tap((collected) => console.log(JSON.stringify(collected, null, 2)))
533+
.tap((collected) => {
534+
expect(collected.length).to.equal(1);
535+
expect(collected[0].updateRequest).to.deep.equal({
536+
Key: {
537+
pk: '1',
538+
sk: 'thing',
539+
},
540+
ExpressionAttributeNames: {
541+
'#pk': 'pk',
542+
'#sk': 'sk',
543+
'#discriminator': 'discriminator',
544+
'#name': 'name',
545+
'#description': 'description',
546+
'#otherThing': 'otherThing',
547+
'#latched': 'latched',
548+
'#ttl': 'ttl',
549+
'#timestamp': 'timestamp',
550+
},
551+
ExpressionAttributeValues: {
552+
':pk': '1',
553+
':sk': 'thing',
554+
':discriminator': 'thing',
555+
':name': 'Thing One',
556+
':description': 'This is thing one',
557+
':otherThing': {
558+
pk: '2',
559+
sk: 'thing',
560+
discriminator: 'thing',
561+
name: 'thing2',
562+
},
563+
':latched': true,
564+
':ttl': 1549053422,
565+
':timestamp': 1548967022000,
566+
},
567+
UpdateExpression: 'SET #pk = :pk, #sk = :sk, #discriminator = :discriminator, #name = :name, #description = :description, #otherThing = :otherThing, #latched = :latched, #ttl = :ttl, #timestamp = :timestamp',
568+
ReturnValues: 'ALL_NEW',
569+
ConditionExpression: 'attribute_not_exists(#timestamp) OR #timestamp < :timestamp',
570+
});
571+
})
572+
.done(done);
573+
});
480574
});
481575

482576
const toUpdateRequest = (uow) => ({

0 commit comments

Comments
 (0)