2019-01-02 12:58:55 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {expect} from 'chai';
|
2016-11-14 16:16:51 +03:00
|
|
|
import {ghUserCanAdmin} from 'ghost-admin/helpers/gh-user-can-admin';
|
2015-06-30 16:21:03 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
describe('Unit: Helper: gh-user-can-admin', function () {
|
2015-06-30 16:21:03 +03:00
|
|
|
// Mock up roles and test for truthy
|
2019-01-22 19:44:49 +03:00
|
|
|
describe('Owner or admin roles', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let user = {
|
|
|
|
get(role) {
|
2021-07-12 15:55:56 +03:00
|
|
|
if (role === 'isAdmin') {
|
2015-06-30 16:21:03 +03:00
|
|
|
return true;
|
|
|
|
}
|
2021-07-12 15:55:56 +03:00
|
|
|
throw new Error('unsupported'); // Make sure we only call get('isAdmin')
|
2015-06-30 16:21:03 +03:00
|
|
|
}
|
|
|
|
};
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2015-06-30 16:21:03 +03:00
|
|
|
it(' - can be Admin', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let result = ghUserCanAdmin([user]);
|
2015-06-30 16:21:03 +03:00
|
|
|
expect(result).to.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-02-07 12:42:46 +03:00
|
|
|
describe('Editor, Author & Contributor roles', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let user = {
|
|
|
|
get(role) {
|
2021-07-12 15:55:56 +03:00
|
|
|
if (role === 'isAdmin') {
|
2015-06-30 16:21:03 +03:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-12 15:55:56 +03:00
|
|
|
throw new Error('unsupported'); // Make sure we only call get('isAdmin')
|
2015-06-30 16:21:03 +03:00
|
|
|
}
|
|
|
|
};
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2015-06-30 16:21:03 +03:00
|
|
|
it(' - cannot be Admin', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let result = ghUserCanAdmin([user]);
|
2015-06-30 16:21:03 +03:00
|
|
|
expect(result).to.equal(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|