2016-05-19 14:49:22 +03:00
|
|
|
var should = require('should'),
|
2017-12-13 21:15:29 +03:00
|
|
|
fs = require('fs-extra'),
|
2020-04-05 19:52:48 +03:00
|
|
|
configUtils = require('../../../utils/configUtils'),
|
2020-03-30 18:26:47 +03:00
|
|
|
config = require('../../../../core/server/config'),
|
|
|
|
schedulingUtils = require('../../../../core/server/adapters/scheduling/utils');
|
2016-05-19 14:49:22 +03:00
|
|
|
|
2020-04-05 19:52:48 +03:00
|
|
|
const schedulingPath = configUtils.config.getContentPath('adapters') + 'scheduling/';
|
2016-05-19 14:49:22 +03:00
|
|
|
describe('Scheduling: utils', function () {
|
2020-04-05 19:52:48 +03:00
|
|
|
var scope = {adapter: null};
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
if (!fs.existsSync(schedulingPath)) {
|
|
|
|
fs.mkdirSync(schedulingPath);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
if (scope.adapter) {
|
|
|
|
fs.unlinkSync(scope.adapter);
|
|
|
|
scope.adapter = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
2016-05-19 14:49:22 +03:00
|
|
|
describe('success', function () {
|
|
|
|
it('create good adapter', function (done) {
|
2020-04-05 19:52:48 +03:00
|
|
|
schedulingUtils.createAdapter().then(function (adapter) {
|
2016-05-19 14:49:22 +03:00
|
|
|
should.exist(adapter);
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('create good adapter', function (done) {
|
2020-04-05 19:52:48 +03:00
|
|
|
scope.adapter = schedulingPath + 'another-scheduler.js';
|
|
|
|
|
|
|
|
configUtils.set({
|
|
|
|
scheduling: {
|
|
|
|
active: 'another-scheduler'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-19 14:49:22 +03:00
|
|
|
var jsFile = '' +
|
|
|
|
'var util = require(\'util\');' +
|
2020-04-05 19:52:48 +03:00
|
|
|
'var SchedulingBase = require(\'../../../core/server/adapters/scheduling/SchedulingBase\');' +
|
2016-05-19 14:49:22 +03:00
|
|
|
'var AnotherAdapter = function (){ SchedulingBase.call(this); };' +
|
|
|
|
'util.inherits(AnotherAdapter, SchedulingBase);' +
|
|
|
|
'AnotherAdapter.prototype.run = function (){};' +
|
|
|
|
'AnotherAdapter.prototype.schedule = function (){};' +
|
|
|
|
'AnotherAdapter.prototype.reschedule = function (){};' +
|
|
|
|
'AnotherAdapter.prototype.unschedule = function (){};' +
|
|
|
|
'module.exports = AnotherAdapter';
|
|
|
|
|
2020-04-05 19:52:48 +03:00
|
|
|
fs.writeFileSync(scope.adapter, jsFile);
|
2016-09-13 23:24:57 +03:00
|
|
|
|
2020-04-05 19:52:48 +03:00
|
|
|
schedulingUtils.createAdapter().then(function (adapter) {
|
2016-05-19 14:49:22 +03:00
|
|
|
should.exist(adapter);
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error', function () {
|
|
|
|
it('create with adapter, but missing fn\'s', function (done) {
|
2020-04-05 19:52:48 +03:00
|
|
|
scope.adapter = schedulingPath + 'bad-adapter.js';
|
2016-05-19 14:49:22 +03:00
|
|
|
var jsFile = '' +
|
|
|
|
'var util = require(\'util\');' +
|
2020-04-05 19:52:48 +03:00
|
|
|
'var SchedulingBase = require(\'../../../core/server/adapters/scheduling/SchedulingBase\');' +
|
2016-05-19 14:49:22 +03:00
|
|
|
'var BadAdapter = function (){ SchedulingBase.call(this); };' +
|
|
|
|
'util.inherits(BadAdapter, SchedulingBase);' +
|
|
|
|
'BadAdapter.prototype.schedule = function (){};' +
|
|
|
|
'module.exports = BadAdapter';
|
|
|
|
|
2020-04-05 19:52:48 +03:00
|
|
|
fs.writeFileSync(scope.adapter, jsFile);
|
2016-05-19 14:49:22 +03:00
|
|
|
|
2020-04-05 19:52:48 +03:00
|
|
|
configUtils.set({
|
|
|
|
scheduling: {
|
|
|
|
active: 'bad-adapter'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
schedulingUtils.createAdapter().catch(function (err) {
|
2016-05-19 14:49:22 +03:00
|
|
|
should.exist(err);
|
2020-04-05 19:52:48 +03:00
|
|
|
should.equal(err.errorType, 'IncorrectUsageError');
|
2016-05-19 14:49:22 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|