Add new ghost-scheduler client

refs #6301, #6399

- new scheduler client will be used by any web app that handles time and calls back to the scheduling API at the right time
- new scheduler client will need to be confidential, rather than public, hence the 'web' type instead of 'ua'
- adds validation to client type that it must have a type of 'ua', 'web', or 'native'
This commit is contained in:
Hannah Wolfe 2016-04-10 19:22:00 +01:00
parent 739977a368
commit 8b9734ea31
7 changed files with 72 additions and 8 deletions

View File

@ -0,0 +1,16 @@
// Create a new `ghost-scheduler` client for use in themes
var models = require('../../../../models'),
schedulerClient = require('../utils').findModelFixtureEntry('Client', {slug: 'ghost-scheduler'}),
message = 'Add ghost-scheduler client fixture';
module.exports = function addGhostFrontendClient(options, logger) {
return models.Client.findOne({slug: schedulerClient.slug}).then(function (client) {
if (!client) {
logger.info(message);
return models.Client.add(schedulerClient, options);
} else {
logger.warn(message);
}
});
};

View File

@ -1,4 +1,6 @@
module.exports = [
// add jquery setting and privacy info
require('./01-update-ghost-client-secrets')
require('./01-update-ghost-client-secrets'),
// add ghost-scheduler client
require('./02-add-ghost-scheduler-client')
];

View File

@ -42,6 +42,12 @@
"name": "Ghost Frontend",
"slug": "ghost-frontend",
"status": "enabled"
},
{
"name": "Ghost Scheduler",
"slug": "ghost-scheduler",
"status": "enabled",
"type": "web"
}
]
},

View File

@ -172,7 +172,7 @@ module.exports = {
redirection_uri: {type: 'string', maxlength: 2000, nullable: true},
logo: {type: 'string', maxlength: 2000, nullable: true},
status: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'development'},
type: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'ua'},
type: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'ua', validations: {isIn: [['ua', 'web', 'native']]}},
description: {type: 'string', maxlength: 200, nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'integer', nullable: false},

View File

@ -159,9 +159,10 @@ describe('Database Migration (special functions)', function () {
// Clients
should.exist(result.clients);
result.clients.length.should.eql(2);
result.clients.length.should.eql(3);
result.clients.at(0).get('name').should.eql('Ghost Admin');
result.clients.at(1).get('name').should.eql('Ghost Frontend');
result.clients.at(2).get('name').should.eql('Ghost Scheduler');
// User (Owner)
should.exist(result.users);

View File

@ -718,8 +718,9 @@ describe('Fixtures', function () {
sequenceStub.firstCall.args[0][0].should.be.a.Function().with.property('name', 'runVersionTasks');
sequenceStub.secondCall.calledWith(sinon.match.array, sinon.match.object, loggerStub).should.be.true();
sequenceStub.secondCall.args[0].should.be.an.Array().with.lengthOf(1);
sequenceStub.secondCall.args[0].should.be.an.Array().with.lengthOf(2);
sequenceStub.secondCall.args[0][0].should.be.a.Function().with.property('name', 'updateGhostClientsSecrets');
sequenceStub.secondCall.args[0][1].should.be.a.Function().with.property('name', 'addGhostFrontendClient');
// Reset
sequenceReset();
@ -730,7 +731,7 @@ describe('Fixtures', function () {
describe('Tasks:', function () {
it('should have tasks for 005', function () {
should.exist(fixtures005);
fixtures005.should.be.an.Array().with.lengthOf(1);
fixtures005.should.be.an.Array().with.lengthOf(2);
});
describe('01-update-ghost-client-secrets', function () {
@ -774,6 +775,44 @@ describe('Fixtures', function () {
}).catch(done);
});
});
describe('02-add-ghost-scheduler-client', function () {
var clientOneStub;
beforeEach(function () {
clientOneStub = sandbox.stub(models.Client, 'findOne').returns(Promise.resolve({}));
});
it('tries to add client correctly', function (done) {
var clientAddStub = sandbox.stub(models.Client, 'add').returns(Promise.resolve());
clientOneStub.returns(Promise.resolve());
fixtures005[1]({}, loggerStub).then(function () {
clientOneStub.calledOnce.should.be.true();
clientOneStub.calledWith({slug: 'ghost-scheduler'}).should.be.true();
clientAddStub.calledOnce.should.be.true();
loggerStub.info.calledOnce.should.be.true();
loggerStub.warn.called.should.be.false();
sinon.assert.callOrder(clientOneStub, loggerStub.info, clientAddStub);
done();
}).catch(done);
});
it('does not try to add client if it already exists', function (done) {
var clientAddStub = sandbox.stub(models.Client, 'add').returns(Promise.resolve());
fixtures005[1]({}, loggerStub).then(function () {
clientOneStub.calledOnce.should.be.true();
clientOneStub.calledWith({slug: 'ghost-scheduler'}).should.be.true();
clientAddStub.called.should.be.false();
loggerStub.info.called.should.be.false();
loggerStub.warn.calledOnce.should.be.true();
done();
}).catch(done);
});
});
});
});
});
@ -821,8 +860,8 @@ describe('Fixtures', function () {
tagAddStub.calledOnce.should.be.true();
roleOneStub.callCount.should.be.aboveOrEqual(4);
roleAddStub.callCount.should.eql(4);
clientOneStub.calledTwice.should.be.true();
clientAddStub.calledTwice.should.be.true();
clientOneStub.calledThrice.should.be.true();
clientAddStub.calledThrice.should.be.true();
permOneStub.callCount.should.eql(30);
permsAddStub.called.should.be.true();

View File

@ -33,7 +33,7 @@ describe('DB version integrity', function () {
// Only these variables should need updating
var currentDbVersion = '005',
currentSchemaHash = 'be706cdbeb06103d90703ee733efc556',
currentFixturesHash = '77ebb081539f9e0c49f487faf7fd929e';
currentFixturesHash = '21dd859601c8e1c12eaff9eccfbe966a';
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
// and the values above will need updating as confirmation