2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-04 00:24:39 +08:00
|
|
|
var Channel = require('../../../lib/batch/pubsub/channel');
|
|
|
|
var JobPublisher = require('../../../lib/batch/pubsub/job-publisher');
|
2016-01-23 02:31:25 +08:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
describe('batch API job publisher', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
var self = this;
|
|
|
|
this.host = 'irrelevantHost';
|
|
|
|
this.redis = {
|
|
|
|
createClient: function () {
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
publish: function () {
|
2016-10-13 00:44:46 +08:00
|
|
|
var isValidFirstArg = arguments[0] === Channel.NAME;
|
2016-01-23 02:31:25 +08:00
|
|
|
var isValidSecondArg = arguments[1] === self.host;
|
|
|
|
self.redis.publishIsCalledWithValidArgs = isValidFirstArg && isValidSecondArg;
|
2016-07-07 16:44:17 +08:00
|
|
|
},
|
|
|
|
on: function () {},
|
|
|
|
ping: function (cb) {
|
|
|
|
cb();
|
2016-01-23 02:31:25 +08:00
|
|
|
}
|
|
|
|
};
|
2016-07-07 20:14:46 +08:00
|
|
|
this.pool = {
|
|
|
|
acquire: function (db, cb) {
|
|
|
|
cb(null, self.redis);
|
|
|
|
}
|
|
|
|
};
|
2016-01-23 02:31:25 +08:00
|
|
|
|
2016-07-07 20:14:46 +08:00
|
|
|
this.jobPublisher = new JobPublisher(this.pool);
|
2016-01-23 02:31:25 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('.publish() should publish new messages', function () {
|
|
|
|
this.jobPublisher.publish(this.host);
|
|
|
|
assert.ok(this.redis.publishIsCalledWithValidArgs);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|