mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
1421c92ba5
refs #6413 - PUT endpoint to publish a post/page for the scheduler - fn endpoint to get all scheduled posts (with from/to query params) for the scheduler - hardcoded permission handling for scheduler client - fix event bug: unscheduled - basic structure for scheduling - post scheduling basics - offer easy option to change adapter - integrate the default scheduler adapter - update scheduled posts when blog TZ changes - safety check before scheduler can publish a post (not allowed to publish in the future or past) - add force flag to allow publishing in the past - invalidate cache header for /schedules/posts/:id
86 lines
3.4 KiB
JavaScript
86 lines
3.4 KiB
JavaScript
/*globals describe, it*/
|
|
|
|
var should = require('should'),
|
|
fs = require('fs'),
|
|
config = require(__dirname + '/../../../server/config'),
|
|
errors = require(config.paths.corePath + '/server/errors'),
|
|
schedulingUtils = require(config.paths.corePath + '/server/scheduling/utils');
|
|
|
|
describe('Scheduling: utils', function () {
|
|
describe('success', function () {
|
|
it('create good adapter', function (done) {
|
|
schedulingUtils.createAdapter({
|
|
active: __dirname + '/../../../server/scheduling/SchedulingDefault'
|
|
}).then(function (adapter) {
|
|
should.exist(adapter);
|
|
done();
|
|
}).catch(done);
|
|
});
|
|
|
|
it('create good adapter', function (done) {
|
|
var jsFile = '' +
|
|
'var util = require(\'util\');' +
|
|
'var SchedulingBase = require(__dirname + \'/../../../server/scheduling/SchedulingBase\');' +
|
|
'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';
|
|
|
|
fs.writeFileSync(__dirname + '/another-scheduler.js', jsFile);
|
|
schedulingUtils.createAdapter({
|
|
active: 'another-scheduler',
|
|
path: __dirname + '/'
|
|
}).then(function (adapter) {
|
|
should.exist(adapter);
|
|
done();
|
|
}).finally(function () {
|
|
fs.unlinkSync(__dirname + '/another-scheduler.js');
|
|
}).catch(done);
|
|
});
|
|
});
|
|
|
|
describe('error', function () {
|
|
it('create without adapter path', function (done) {
|
|
schedulingUtils.createAdapter()
|
|
.catch(function (err) {
|
|
should.exist(err);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('create with unknown adapter', function (done) {
|
|
schedulingUtils.createAdapter({
|
|
active: '/follow/the/heart'
|
|
}).catch(function (err) {
|
|
should.exist(err);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('create with adapter, but missing fn\'s', function (done) {
|
|
var jsFile = '' +
|
|
'var util = require(\'util\');' +
|
|
'var SchedulingBase = require(__dirname + \'/../../../server/scheduling/SchedulingBase\');' +
|
|
'var BadAdapter = function (){ SchedulingBase.call(this); };' +
|
|
'util.inherits(BadAdapter, SchedulingBase);' +
|
|
'BadAdapter.prototype.schedule = function (){};' +
|
|
'module.exports = BadAdapter';
|
|
|
|
fs.writeFileSync(__dirname + '/bad-adapter.js', jsFile);
|
|
|
|
schedulingUtils.createAdapter({
|
|
active: __dirname + '/bad-adapter'
|
|
}).catch(function (err) {
|
|
should.exist(err);
|
|
(err instanceof errors.IncorrectUsage).should.eql(true);
|
|
done();
|
|
}).finally(function () {
|
|
fs.unlinkSync(__dirname + '/bad-adapter.js');
|
|
});
|
|
});
|
|
});
|
|
});
|