CartoDB-SQL-API/test/unit/batch/job-subscriber-test.js
Daniel García Aubert 0c92fcaf96 Node.js 12 support:
- Update `gc-stats` to version 1.4.0
- Replace `zipfile` -> `adm-zip`
- Update `libxmljs` to version 0.19.7
- Update `sqlite` to version 4.2.0
- Adapted pool acquires to the new version of `cartodb-redis`
- Adapted test to use `adm-zip`
2020-05-18 11:32:41 +02:00

75 lines
2.4 KiB
JavaScript

'use strict';
var Channel = require('../../../lib/batch/pubsub/channel');
var JobSubscriber = require('../../../lib/batch/pubsub/job-subscriber');
var assert = require('assert');
describe('batch API job subscriber', function () {
beforeEach(function () {
var self = this;
this.onMessageListener = function () {};
this.redis = {
createClient: function () {
return this;
},
subscribe: function () {
var isValidFirstArg = arguments[0] === Channel.NAME;
self.redis.subscribeIsCalledWithValidArgs = isValidFirstArg;
},
on: function () {
if (arguments[0] === 'message') {
self.redis.onIsCalledWithValidArgs = true;
}
},
unsubscribe: function () {
var isValidFirstArg = arguments[0] === Channel.NAME;
self.redis.unsubscribeIsCalledWithValidArgs = isValidFirstArg;
},
scan: function (params, callback) {
return callback(null, ['0']);
},
removeAllListeners: function () {
return this;
},
smembers: function (key, callback) {
callback(null, []);
},
connected: true
};
this.pool = {
acquire: function () {
return Promise.resolve(self.redis);
},
release: function (/* db, client */) {
return Promise.resolve();
}
};
this.queueSeeker = {
seek: function () {
var callback = arguments[1];
callback(null, []);
}
};
this.jobSubscriber = new JobSubscriber(this.pool, this.queueSeeker);
});
it('.subscribe() should listen for incoming messages', function () {
this.jobSubscriber.subscribe(this.onMessageListener);
setImmediate(() => {
assert.ok(this.redis.onIsCalledWithValidArgs);
assert.ok(this.redis.subscribeIsCalledWithValidArgs);
});
});
it('.unsubscribe() should stop listening for incoming messages', function () {
this.jobSubscriber.subscribe(this.onMessageListener);
this.jobSubscriber.unsubscribe();
setImmediate(() => {
assert.ok(this.redis.unsubscribeIsCalledWithValidArgs);
});
});
});