Skip to content

Commit

Permalink
Fixed ActionCreator not throwing error when empty actions were passed
Browse files Browse the repository at this point in the history
  • Loading branch information
elboletaire committed Nov 15, 2018
1 parent a7d68dc commit 7f7c4c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
13 changes: 4 additions & 9 deletions src/worker/ActionCreator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -81,8 +79,5 @@ describe('ActionCreator', () => {
.then((results) => {
return expect(typeof results).toBe('object')
})
.catch((e) => {
return expect(e).toBeFalsy()
})
})
})
9 changes: 7 additions & 2 deletions src/worker/ActionCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand All @@ -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({
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7f7c4c6

Please sign in to comment.