2017-03-21 11:24:11 +03:00
|
|
|
var should = require('should'),
|
2017-01-25 16:47:49 +03:00
|
|
|
sinon = require('sinon'),
|
2017-03-21 11:24:11 +03:00
|
|
|
testUtils = require('../utils'),
|
2017-01-25 16:47:49 +03:00
|
|
|
_ = require('lodash'),
|
|
|
|
Promise = require('bluebird'),
|
|
|
|
Models = require('../../server/models'),
|
|
|
|
sandbox = sinon.sandbox.create();
|
2015-08-18 16:08:52 +03:00
|
|
|
|
|
|
|
describe('Database Migration (special functions)', function () {
|
|
|
|
before(testUtils.teardown);
|
|
|
|
afterEach(testUtils.teardown);
|
2016-02-25 10:10:36 +03:00
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Fixtures', function () {
|
|
|
|
// Custom assertion for detection that a permissions is assigned to the correct roles
|
|
|
|
should.Assertion.add('AssignedToRoles', function (roles) {
|
|
|
|
var roleNames;
|
|
|
|
this.params = {operator: 'to have role'};
|
|
|
|
|
|
|
|
should.exist(this.obj);
|
|
|
|
|
|
|
|
this.obj.should.be.an.Object().with.property(['roles']);
|
|
|
|
this.obj.roles.should.be.an.Array();
|
2016-03-15 21:27:03 +03:00
|
|
|
|
|
|
|
// Ensure the roles are in id order
|
2016-06-11 21:23:27 +03:00
|
|
|
roleNames = _(this.obj.roles).sortBy('id').map('name').value();
|
2016-02-25 10:10:36 +03:00
|
|
|
roleNames.should.eql(roles);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Custom assertion to wrap all permissions
|
|
|
|
should.Assertion.add('CompletePermissions', function () {
|
|
|
|
this.params = {operator: 'to have a complete set of permissions'};
|
|
|
|
var permissions = this.obj;
|
|
|
|
|
|
|
|
// DB
|
|
|
|
permissions[0].name.should.eql('Export database');
|
|
|
|
permissions[0].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
permissions[1].name.should.eql('Import database');
|
|
|
|
permissions[1].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
permissions[2].name.should.eql('Delete all content');
|
|
|
|
permissions[2].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
|
|
|
|
// Mail
|
|
|
|
permissions[3].name.should.eql('Send mail');
|
|
|
|
permissions[3].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
|
|
|
|
// Notifications
|
|
|
|
permissions[4].name.should.eql('Browse notifications');
|
|
|
|
permissions[4].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
permissions[5].name.should.eql('Add notifications');
|
|
|
|
permissions[5].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
permissions[6].name.should.eql('Delete notifications');
|
|
|
|
permissions[6].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
|
|
|
|
// Posts
|
|
|
|
permissions[7].name.should.eql('Browse posts');
|
|
|
|
permissions[7].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[8].name.should.eql('Read posts');
|
|
|
|
permissions[8].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[9].name.should.eql('Edit posts');
|
|
|
|
permissions[9].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
permissions[10].name.should.eql('Add posts');
|
|
|
|
permissions[10].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[11].name.should.eql('Delete posts');
|
|
|
|
permissions[11].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
permissions[12].name.should.eql('Browse settings');
|
|
|
|
permissions[12].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[13].name.should.eql('Read settings');
|
|
|
|
permissions[13].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[14].name.should.eql('Edit settings');
|
|
|
|
permissions[14].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
|
|
|
|
// Slugs
|
|
|
|
permissions[15].name.should.eql('Generate slugs');
|
|
|
|
permissions[15].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
|
|
|
|
// Tags
|
|
|
|
permissions[16].name.should.eql('Browse tags');
|
|
|
|
permissions[16].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[17].name.should.eql('Read tags');
|
|
|
|
permissions[17].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[18].name.should.eql('Edit tags');
|
|
|
|
permissions[18].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
permissions[19].name.should.eql('Add tags');
|
|
|
|
permissions[19].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[20].name.should.eql('Delete tags');
|
|
|
|
permissions[20].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
|
|
|
|
// Themes
|
|
|
|
permissions[21].name.should.eql('Browse themes');
|
|
|
|
permissions[21].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
permissions[22].name.should.eql('Edit themes');
|
|
|
|
permissions[22].should.be.AssignedToRoles(['Administrator']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[23].name.should.eql('Activate themes');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[23].should.be.AssignedToRoles(['Administrator']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[24].name.should.eql('Upload themes');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[24].should.be.AssignedToRoles(['Administrator']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[25].name.should.eql('Download themes');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[25].should.be.AssignedToRoles(['Administrator']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[26].name.should.eql('Delete themes');
|
|
|
|
permissions[26].should.be.AssignedToRoles(['Administrator']);
|
2016-02-25 10:10:36 +03:00
|
|
|
|
|
|
|
// Users
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[27].name.should.eql('Browse users');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[27].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[28].name.should.eql('Read users');
|
|
|
|
permissions[28].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[29].name.should.eql('Edit users');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[29].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[30].name.should.eql('Add users');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[30].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[31].name.should.eql('Delete users');
|
|
|
|
permissions[31].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
2015-08-18 16:08:52 +03:00
|
|
|
|
2016-02-25 10:10:36 +03:00
|
|
|
// Roles
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[32].name.should.eql('Assign a role');
|
|
|
|
permissions[32].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
permissions[33].name.should.eql('Browse roles');
|
|
|
|
permissions[33].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
2016-04-08 12:09:26 +03:00
|
|
|
|
|
|
|
// Clients
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[34].name.should.eql('Browse clients');
|
2016-04-08 12:09:26 +03:00
|
|
|
permissions[34].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[35].name.should.eql('Read clients');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[35].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[36].name.should.eql('Edit clients');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[36].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[37].name.should.eql('Add clients');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[37].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[38].name.should.eql('Delete clients');
|
|
|
|
permissions[38].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
2016-04-19 17:12:18 +03:00
|
|
|
|
|
|
|
// Subscribers
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[39].name.should.eql('Browse subscribers');
|
2016-04-19 17:12:18 +03:00
|
|
|
permissions[39].should.be.AssignedToRoles(['Administrator']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[40].name.should.eql('Read subscribers');
|
2016-08-23 15:07:25 +03:00
|
|
|
permissions[40].should.be.AssignedToRoles(['Administrator']);
|
2017-03-13 14:44:44 +03:00
|
|
|
permissions[41].name.should.eql('Edit subscribers');
|
|
|
|
permissions[41].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
permissions[42].name.should.eql('Add subscribers');
|
|
|
|
permissions[42].should.be.AssignedToRoles(['Administrator', 'Editor', 'Author']);
|
|
|
|
permissions[43].name.should.eql('Delete subscribers');
|
|
|
|
permissions[43].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
|
|
|
|
// Invites
|
|
|
|
permissions[44].name.should.eql('Browse invites');
|
|
|
|
permissions[44].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
permissions[45].name.should.eql('Read invites');
|
|
|
|
permissions[45].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
permissions[46].name.should.eql('Edit invites');
|
|
|
|
permissions[46].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
permissions[47].name.should.eql('Add invites');
|
|
|
|
permissions[47].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
|
|
|
permissions[48].name.should.eql('Delete invites');
|
|
|
|
permissions[48].should.be.AssignedToRoles(['Administrator', 'Editor']);
|
2017-09-21 18:01:03 +03:00
|
|
|
|
|
|
|
// Redirects
|
|
|
|
permissions[49].name.should.eql('Download redirects');
|
|
|
|
permissions[49].should.be.AssignedToRoles(['Administrator']);
|
|
|
|
permissions[50].name.should.eql('Upload redirects');
|
|
|
|
permissions[50].should.be.AssignedToRoles(['Administrator']);
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
|
2016-04-08 12:09:26 +03:00
|
|
|
describe('Populate', function () {
|
2017-01-25 16:47:49 +03:00
|
|
|
beforeEach(testUtils.setup('default'));
|
2016-04-14 18:54:49 +03:00
|
|
|
|
2016-04-08 12:09:26 +03:00
|
|
|
it('should populate all fixtures correctly', function (done) {
|
2017-01-25 16:47:49 +03:00
|
|
|
var props = {
|
|
|
|
posts: Models.Post.findAll({include: ['tags']}),
|
|
|
|
tags: Models.Tag.findAll(),
|
|
|
|
users: Models.User.findAll({
|
|
|
|
filter: 'status:inactive',
|
|
|
|
context: {internal: true},
|
|
|
|
include: ['roles']
|
|
|
|
}),
|
|
|
|
clients: Models.Client.findAll(),
|
|
|
|
roles: Models.Role.findAll(),
|
|
|
|
permissions: Models.Permission.findAll({include: ['roles']})
|
|
|
|
};
|
|
|
|
|
|
|
|
return Promise.props(props).then(function (result) {
|
|
|
|
should.exist(result);
|
|
|
|
|
|
|
|
// Post
|
|
|
|
should.exist(result.posts);
|
2017-06-08 18:36:14 +03:00
|
|
|
result.posts.length.should.eql(7);
|
|
|
|
result.posts.at(0).get('title').should.eql('Setting up your own Ghost theme');
|
2017-01-25 16:47:49 +03:00
|
|
|
|
|
|
|
// Tag
|
|
|
|
should.exist(result.tags);
|
|
|
|
result.tags.length.should.eql(1);
|
|
|
|
result.tags.at(0).get('name').should.eql('Getting Started');
|
|
|
|
|
|
|
|
// Post Tag relation
|
|
|
|
result.posts.at(0).related('tags').length.should.eql(1);
|
|
|
|
result.posts.at(0).related('tags').at(0).get('name').should.eql('Getting Started');
|
|
|
|
|
|
|
|
// Clients
|
|
|
|
should.exist(result.clients);
|
2017-08-22 13:15:40 +03:00
|
|
|
result.clients.length.should.eql(4);
|
2017-01-25 16:47:49 +03:00
|
|
|
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');
|
2017-08-22 13:15:40 +03:00
|
|
|
result.clients.at(3).get('name').should.eql('Ghost Backup');
|
2017-01-25 16:47:49 +03:00
|
|
|
|
|
|
|
// User (Owner)
|
|
|
|
should.exist(result.users);
|
|
|
|
result.users.length.should.eql(1);
|
2017-05-29 20:25:19 +03:00
|
|
|
result.users.at(0).get('name').should.eql('Ghost');
|
2017-01-25 16:47:49 +03:00
|
|
|
result.users.at(0).get('status').should.eql('inactive');
|
|
|
|
result.users.at(0).related('roles').length.should.eql(1);
|
|
|
|
result.users.at(0).related('roles').at(0).get('name').should.eql('Owner');
|
|
|
|
|
|
|
|
// Roles
|
|
|
|
should.exist(result.roles);
|
|
|
|
result.roles.length.should.eql(4);
|
|
|
|
result.roles.at(0).get('name').should.eql('Administrator');
|
|
|
|
result.roles.at(1).get('name').should.eql('Editor');
|
|
|
|
result.roles.at(2).get('name').should.eql('Author');
|
|
|
|
result.roles.at(3).get('name').should.eql('Owner');
|
|
|
|
|
|
|
|
// Permissions
|
2017-09-21 18:01:03 +03:00
|
|
|
result.permissions.length.should.eql(51);
|
2017-01-25 16:47:49 +03:00
|
|
|
result.permissions.toJSON().should.be.CompletePermissions();
|
|
|
|
|
|
|
|
done();
|
2017-03-13 14:44:44 +03:00
|
|
|
}).catch(done);
|
2016-04-08 12:09:26 +03:00
|
|
|
});
|
2015-08-18 16:08:52 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|