mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
1db3aefb9b
refs https://github.com/TryGhost/Ghost/issues/9865 - schema migrations - adds `integrations` and `api_keys` tables - inserts `integration` and `api_key` permissions and Administrator role relationships - inserts `Admin Integration` role and permissions - adds `Integration` model - adds `ApiKey` model - creates default secret if not given - hardcodes associated role based on key type - `admin` = `Admin API Client` - `content` = no role - updates `Role` model to use `bookshelf-relations` for auto cleanup of permission relationships on destroy
28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
const models = require('../../../server/models');
|
|
const ghostBookshelf = require('../../../server/models/base');
|
|
const testUtils = require('../../utils');
|
|
const should = require('should');
|
|
|
|
describe('Unit: models/role', function () {
|
|
before(testUtils.teardown);
|
|
before(testUtils.setup('roles', 'perms:role'));
|
|
|
|
describe('destroy', function () {
|
|
it('cleans up permissions join table', function () {
|
|
const adminRole = {id: testUtils.DataGenerator.Content.roles[0].id};
|
|
|
|
function checkRolePermissionsCount(count) {
|
|
return ghostBookshelf.knex.select().table('permissions_roles').where('role_id', adminRole.id)
|
|
.then((rolePermissions) => {
|
|
rolePermissions.length.should.eql(count);
|
|
});
|
|
}
|
|
|
|
return models.Role.findOne(adminRole)
|
|
.then(role => should.exist(role, 'Administrator role not found'))
|
|
.then(() => checkRolePermissionsCount(2))
|
|
.then(() => models.Role.destroy(adminRole))
|
|
.then(() => checkRolePermissionsCount(0));
|
|
});
|
|
});
|
|
});
|