diff --git a/src/worker/ActionCreator.spec.ts b/src/worker/ActionCreator.spec.ts index 29e5991..ddbab14 100644 --- a/src/worker/ActionCreator.spec.ts +++ b/src/worker/ActionCreator.spec.ts @@ -8,25 +8,23 @@ describe('ActionCreator', () => { it('should fail if one of the steps fails', () => { const msg = { content: { - toString: function () { - return '{"test": "value"}' - } + toString: () => '{"test": "value"}' }, - ack: function () {} + ack: function () {}, } const event = new Event({ name: 'test', eventName: 'memberships', route: 'created', - actions: [] + actions: [], }) const actionCreator = new ActionCreator(rabbit, event) actionCreator.createHandler() expect.assertions(1) - return expect(actionCreator.executeActions(msg)).resolves.toBeFalsy() + return expect(actionCreator.executeActions(msg)).rejects.toBeTruthy() }) it('should handle coming events', () => { @@ -81,8 +79,5 @@ describe('ActionCreator', () => { .then((results) => { return expect(typeof results).toBe('object') }) - .catch((e) => { - return expect(e).toBeFalsy() - }) }) }) diff --git a/src/worker/ActionCreator.ts b/src/worker/ActionCreator.ts index 16e25d8..51e5102 100644 --- a/src/worker/ActionCreator.ts +++ b/src/worker/ActionCreator.ts @@ -57,13 +57,14 @@ export default class ActionCreator { .catch((err) => { debug('Error in serial execution', err) // The plugin executed is asking to abort operation and - // discard the message, preventing to be send to dead-letter queue + // discard the message, preventing to be sent to dead-letter queue if (err.action && err.action === 'abort') { logger.error(this.preLog, 'The execution of operator has been aborted', err) return msg.ack() } logger.error(this.preLog, 'An error has been ocurred executing the handler actions', err) - // return msg.nack() + + // send message to dead-letter return msg.reject() }) }) @@ -79,6 +80,10 @@ export default class ActionCreator { let promiseChain = Promise.resolve([]).then(() => contents) + if (!this.event.actions.length) { + return Promise.reject(new Error('Empty actions object')) + } + // Iterate over all actions passing the lastResult this.event.actions.forEach((action, index) => { const executer = new ActionExecuter({ diff --git a/yarn.lock b/yarn.lock index ab12ec2..0e1eca0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -71,11 +71,16 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.0.tgz#5a7306e367c539b9f6543499de8dd519fac37a8b" integrity sha512-A2TAGbTFdBw9azHbpVd+/FkdW2T6msN1uct1O9bH3vTerEHKZhTXJUQXy+hNq1B0RagfU8U+KBdqiZpxjhOUQA== -"@types/node@*", "@types/node@^10.5.2": +"@types/node@*": version "10.5.2" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.2.tgz#f19f05314d5421fe37e74153254201a7bf00a707" integrity sha512-m9zXmifkZsMHZBOyxZWilMwmTlpC8x5Ty360JKTiXvlXZfBWYpsg9ZZvP/Ye+iZUh+Q+MxDLjItVTWIsfwz+8Q== +"@types/node@^10.5.2": + version "10.12.8" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.8.tgz#d0a3ab5a6e61458c492304e2776ac136b81db927" + integrity sha512-INamyRZG4rW3lDCUmwVd5Xho/bXvQm/v1yP8V0UN1RuInU7RoWoaO570b+yLX4Ia/0szsx1wa8VzcsVlsvbWLA== + "@types/range-parser@*": version "1.2.2" resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.2.tgz#fa8e1ad1d474688a757140c91de6dace6f4abc8d"