0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/client/tests/unit/helpers/gh-user-can-test.js
cobbspur 453833cd11 Hide Nav Settings based on permissions
closes #5403

- adds gh-user-can helper to group user by minimum permissions
- hide Nav settings menu for users below admin level
2015-06-17 19:20:57 +01:00

97 lines
2.9 KiB
JavaScript

import {
describeModule,
it
} from 'ember-mocha';
import {
ghUserCan
} from 'ghost/helpers/gh-user-can';
describe ('GhUserCanHelper', function () {
// Mock up roles and test for truthy
describe ('Owner role', function () {
var user = {get: function (role) {
if (role === 'isOwner') {
return true;
} else if (role === 'isAdmin') {
return false;
} else if (role === 'isEditor') {
return false;
}
}
};
it(' - can be Admin', function () {
var result = ghUserCan([user, 'admin']);
expect(result).to.equal(true);
});
it(' - can be Editor', function () {
var result = ghUserCan([user, 'editor']);
expect(result).to.equal(true);
});
});
describe ('Administrator role', function () {
var user = {
get: function (role) {
if (role === 'isOwner') {
return false;
} else if (role === 'isAdmin') {
return true;
} else if (role === 'isEditor') {
return false;
}
}
};
it(' - can be Admin', function () {
var result = ghUserCan([user, 'admin']);
expect(result).to.equal(true);
});
it(' - can be Editor', function () {
var result = ghUserCan([user, 'editor']);
expect(result).to.equal(true);
});
});
describe ('Editor role', function () {
var user = {
get: function (role) {
if (role === 'isOwner') {
return false;
} else if (role === 'isAdmin') {
return false;
} else if (role === 'isEditor') {
return true;
}
}
};
it(' - cannot be Admin', function () {
var result = ghUserCan([user, 'admin']);
expect(result).to.equal(false);
});
it(' - can be Editor', function () {
var result = ghUserCan([user, 'editor']);
expect(result).to.equal(true);
});
});
describe ('Author role', function () {
var user = {
get: function (role) {
if (role === 'isOwner') {
return false;
} else if (role === 'isAdmin') {
return false;
} else if (role === 'isEditor') {
return false;
}
}
};
it(' - cannot be Admin', function () {
var result = ghUserCan([user, 'admin']);
expect(result).to.equal(false);
});
it(' - cannot be Editor', function () {
var result = ghUserCan([user, 'editor']);
expect(result).to.equal(false);
});
});
});