-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmixin.test.js
63 lines (53 loc) · 2.21 KB
/
mixin.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict'
require('./common')
const path = require('path')
const { requireUncached } = require('./common')
const TEST_APP = path.join(__dirname, 'fixtures/test-server/server.js')
describe('Mixin', function() {
let app = null
// before(function(done) {
// rabbit.once('default.connection.configured', () => done())
// })
before(function(done) {
app = requireUncached(TEST_APP)
app.once('booted', done)
})
describe('Mixin initialized', function() {
it('should create producer methods', function() {
expect(app.models.Item).itself.to.respondTo('publishItem')
expect(app.models.Item).itself.to.respondTo('publishNewItem')
expect(app.models.Item).itself.to.respondTo('publishUpdatedItem')
})
})
describe('Producer (without type)', function() {
beforeEach(function() {
this.sinon.spy(app.models.Client, 'consumeAllItems')
this.sinon.spy(app.models.Client, 'consumeNewItems')
return app.models.Item.publishItem('a message')
})
it('should call the relevant consumers when a mesage is received', function() {
expect(app.models.Client.consumeAllItems.calledOnce).to.be.true()
expect(app.models.Client.consumeNewItems.called).to.be.false()
})
it('should pass the message body to the consumer', function() {
expect(app.models.Client.consumeAllItems.calledWith('a message')).to.be.true()
})
})
describe('Producer (with type)', function() {
beforeEach(function() {
this.sinon.spy(app.models.Client, 'consumeAllItems')
this.sinon.spy(app.models.Client, 'consumeNewItems')
return app.models.Item.publishItem('a message', 'item.write.created')
})
it('should call the relevant consumers when a mesage is received', function() {
expect(app.models.Client.consumeAllItems.calledOnce).to.be.true()
expect(app.models.Client.consumeNewItems.calledOnce).to.be.true()
})
it('should pass the message body to the consumer', function() {
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()
})
})
})