Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-lambda-stream",
"version": "1.1.10",
"version": "1.1.11",
"description": "Create stream processors with AWS Lambda functions.",
"keywords": [
"aws",
Expand Down
10 changes: 5 additions & 5 deletions src/flavors/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
printStartPipeline, printEndPipeline,
faulty, faultyAsyncStream, splitObject,
compact,
faultify,
} from '../utils';

import {
Expand Down Expand Up @@ -63,8 +64,7 @@ const toGetRequest = (rule) => faulty((uow) => ({
: undefined,
}));

const toUpdateRequest = (rule) => faultyAsyncStream((uow) => Promise.resolve(rule.toUpdateRequest(uow, rule))
.then((updateRequest) => ({
...uow,
updateRequest,
})));
const toUpdateRequest = (rule) => faultyAsyncStream(async (uow) => ({
...uow,
updateRequest: await faultify(rule.toUpdateRequest)(uow, rule),
}));
74 changes: 74 additions & 0 deletions test/unit/flavors/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,80 @@ describe('flavors/update.js', () => {
})
.done(done);
});

it('should fault on error', (done) => {
sinon.stub(DynamoDBConnector.prototype, 'query').resolves([]);
sinon.stub(DynamoDBConnector.prototype, 'batchGet').resolves({
Responses: {
undefined: [{
pk: '2',
sk: 'thing',
discriminator: 'thing',
name: 'thing2',
}],
},
UnprocessedKeys: {},
});
const ebStub = sinon.stub(EventBridgeConnector.prototype, 'putEvents').resolves({ FailedEntryCount: 0 });

sinon.stub(KmsConnector.prototype, 'generateDataKey').resolves(MOCK_GEN_DK_RESPONSE);

const events = toDynamodbRecords([
{
timestamp: 1572832690,
keys: {
pk: '1',
sk: 'thing',
},
newImage: {
pk: '1',
sk: 'thing',
discriminator: 'thing',
name: 'Thing One',
description: 'This is thing one',
otherThing: 'thing|2',
ttl: 1549053422,
timestamp: 1548967022000,
},
},
]);

const errorRule = {
id: 'error-rule',
flavor: update,
eventType: /thing-*/,
filters: [() => true],
toGetRequest,
fks: ['otherThing'],
toUpdateRequest: (uow) => { throw new Error('intentional fault'); },
};

initialize({
...initializeFrom([errorRule]),
}, { ...defaultOptions, AES: false })
.assemble(fromDynamodb(events), true)
.collect()
// .tap((collected) => console.log(JSON.stringify(collected, null, 2)))
.tap((collected) => {
expect(collected.length).to.eq(1);
expect(collected[0].event.err.message).to.eq('intentional fault');
expect(ebStub).to.have.been.calledOnceWith({
Entries: [{
EventBusName: 'undefined',
Source: 'custom',
DetailType: 'fault',
Detail: JSON.stringify(collected[0].event),
}],
}, {
batch: [{
event: collected[0].event,
publishRequestEntry: collected[0].publishRequestEntry,
}],
publishRequest: collected[0].publishRequest,
});
})
.done(done);
});
});

const toUpdateRequest = (uow) => ({
Expand Down