From 6238a7483a76c0ca273eb913e37513cec4a05df7 Mon Sep 17 00:00:00 2001 From: Bram Borggreve Date: Tue, 28 Mar 2017 11:49:54 -0500 Subject: [PATCH] feat: pass the full message into the consumer as second param --- lib/mixins/message-queue.js | 2 +- test/mixin.test.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/mixins/message-queue.js b/lib/mixins/message-queue.js index d3f1f4b..5e88278 100644 --- a/lib/mixins/message-queue.js +++ b/lib/mixins/message-queue.js @@ -29,7 +29,7 @@ module.exports = function messageQueueMixin(Model, options) { const RabbitMQ = loopback.getModel('RabbitMQ') try { - return Model[name](msg.body) + return Model[name](msg.body, msg) .then(() => { debug('consumer %s ran successfully for model %s. key: %o', name, Model.modelName, msg.fields.routingKey) diff --git a/test/mixin.test.js b/test/mixin.test.js index cebd73b..7ac2634 100644 --- a/test/mixin.test.js +++ b/test/mixin.test.js @@ -58,8 +58,10 @@ describe('Mixin', function() { expect(app.models.Client.consumeNewItems.calledOnce).to.be.true() }) it('should pass the message body to the consumer', function() { - expect(app.models.Client.consumeAllItems.calledWith('a message')).to.be.true() - expect(app.models.Client.consumeNewItems.calledWith('a message')).to.be.true() + expect( + app.models.Client.consumeAllItems.calledWithMatch('a message', { type: 'item.write.created' })).to.be.true() + expect( + app.models.Client.consumeNewItems.calledWithMatch('a message', { type: 'item.write.created' })).to.be.true() }) }) })