Skip to content

Commit 3bff39b

Browse files
committed
Completed integration tests
1 parent 5c83f5e commit 3bff39b

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

lib/actions/publish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ function processAction(msg, cfg) {
4848
console.log('Message published id=%s', msg.id);
4949
yield channel.waitForConfirms();
5050
console.log('Message publishing confirmed id=%s', msg.id);
51-
this.emit('data', msg);
51+
return msg;
5252
}.bind(this));
5353
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"files": [
1212
"lib"
1313
],
14+
"scripts": {
15+
"integration-test": "NODE_ENV=test mocha spec-integration/*"
16+
},
1417
"main": "lib/index.js",
1518
"keywords": [
1619
"elasticio",
@@ -32,8 +35,10 @@
3235
"request-promise": "^4.1.1"
3336
},
3437
"devDependencies": {
38+
"chai": "^3.5.0",
3539
"eslint": "^2.1.0",
36-
"eslint-config-xo-space": "^0.10.0"
40+
"eslint-config-xo-space": "^0.10.0",
41+
"mocha": "^3.2.0"
3742
},
3843
"eslintConfig": {
3944
"extends": "xo-space",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
'use strict';
2+
const expect = require('chai').expect;
3+
const publish = require('../lib/actions/publish');
4+
const consume = require('../lib/triggers/consume');
5+
const EventEmitter = require('events');
6+
const co = require('co');
7+
8+
class TestEmitter extends EventEmitter {
9+
10+
constructor(done) {
11+
super();
12+
this.data = [];
13+
this.end = 0;
14+
this.error = [];
15+
16+
this.on('data', (value) => this.data.push(value));
17+
this.on('error', (value) => this.error.push(value));
18+
this.on('end', () => {
19+
this.end++;
20+
done();
21+
});
22+
}
23+
24+
}
25+
26+
describe('Integration test', () => {
27+
28+
29+
before(() => {
30+
if (!process.env.AMQP_URL) throw new Error("Please set AMQP_URL env variable to proceed");
31+
if (!process.env.ELASTICIO_MESSAGE_CRYPTO_IV) throw new Error("Please set ELASTICIO_MESSAGE_CRYPTO_IV env " +
32+
"variable to proceed");
33+
if (!process.env.ELASTICIO_MESSAGE_CRYPTO_PASSWORD) throw new Error("Please set " +
34+
"ELASTICIO_MESSAGE_CRYPTO_PASSWORD env variable to proceed");
35+
36+
});
37+
38+
describe('subscribe then publish', () => {
39+
const cfg = {
40+
amqpURI : process.env.AMQP_URL,
41+
topic: 'integartion-testing-' + (process.env.TRAVIS_BUILD_ID || 'local'),
42+
bindingKeys: 'foo.bar'
43+
};
44+
45+
before(() => publish.init(cfg).then(consume.init(cfg)));
46+
47+
48+
it('send and receive', () => co(function* gen() {
49+
console.log('Starting test');
50+
const receiver = new TestEmitter();
51+
const sender = new TestEmitter();
52+
const msg1 = {
53+
id: 'one',
54+
body: {
55+
routingKey: 'foo.bar',
56+
payload: {
57+
value: 'foo.bar'
58+
}
59+
},
60+
attachments: {
61+
one: 'http://one.com'
62+
}
63+
};
64+
const msg2 = {
65+
id: 'two',
66+
body: {
67+
routingKey: 'foo.baz',
68+
payload: {
69+
value: 'foo.baz'
70+
}
71+
},
72+
attachments: {
73+
two: 'http://two.com'
74+
}
75+
};
76+
console.log('Initializing receiver');
77+
yield consume.process.call(receiver, {}, cfg);
78+
yield new Promise((ok) => setTimeout(ok, 1000));
79+
console.log('Sending messages');
80+
const out1 = yield publish.process.call(sender, msg1, cfg);
81+
const out2 = yield publish.process.call(sender, msg2, cfg);
82+
expect(out1).deep.equal(msg1);
83+
expect(out2).deep.equal(msg2);
84+
console.log('Sending completed, now wait');
85+
yield new Promise((ok) => setTimeout(ok, 1000));
86+
console.log('Lets check');
87+
expect(receiver.data.length).equal(1);
88+
expect(receiver.data[0]).deep.equal({
89+
id: 'one',
90+
body: {
91+
value: 'foo.bar'
92+
},
93+
attachments: {
94+
one: 'http://one.com'
95+
},
96+
headers: {},
97+
metadata: {}
98+
});
99+
})).timeout(5000);
100+
});
101+
102+
});

0 commit comments

Comments
 (0)