-
Notifications
You must be signed in to change notification settings - Fork 0
/
poc-queue-manager.js
76 lines (59 loc) · 2.2 KB
/
poc-queue-manager.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
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);
var QueueManager = require('app/lib/queue-manager');
/* jshint multistr: true */
var DEFAULT_QUEUE_URL =
'https://sqs.us-east-1.amazonaws.com/891008257771/homolog_carbono_paas';
describe('Running tests on the Queue Manager class', function () {
describe('.constructor()', function () {
it('Create manager with custom queue', function (done) {
var QUEUE = 'myQueue';
var queueManager = new QueueManager(QUEUE);
queueManager.queueUrl.should.equal(QUEUE);
queueManager.sqs.should.be.an('object');
done();
});
it('Create manager with default queue', function (done) {
var queueManager = new QueueManager();
queueManager.queueUrl.should.equal(DEFAULT_QUEUE_URL);
queueManager.sqs.should.be.an('object');
done();
});
});
describe('.sendMessage()', function () {
it('Send a message to the queue', function (done) {
var queueManager = new QueueManager();
var callback = sinon.spy();
var promise = queueManager.sendMessage({
MessageBody: 'Test message',
});
promise
.then(function (data) {
data.MessageId.should.be.a('string');
done();
}, callback)
.done(function () {
callback.should.have.callCount(0);
});
});
it('Fail to send message to the queue', function (done) {
var queueManager = new QueueManager('invalidQueueUrl');
var callback = sinon.spy();
var promise = queueManager.sendMessage({
MessageBody: 'Test message',
});
promise
.then(callback, function (err) {
err.should.not.have.property('MessageId');
done();
})
.done(function () {
callback.should.have.callCount(0);
});
});
});
});