mirror of
https://github.com/strapi/strapi.git
synced 2025-09-09 08:39:45 +00:00
99 lines
2.4 KiB
JavaScript
99 lines
2.4 KiB
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const { getActionsByRoleId } = require('../action');
|
||
|
const { AUTHOR_CODE, PUBLISH_ACTION } = require('../constants');
|
||
|
|
||
|
const fixtures = [
|
||
|
{
|
||
|
actionId: 'test.action',
|
||
|
},
|
||
|
{
|
||
|
actionId: PUBLISH_ACTION,
|
||
|
},
|
||
|
{
|
||
|
actionId: 'plugins::test.action',
|
||
|
},
|
||
|
];
|
||
|
|
||
|
describe('Action', () => {
|
||
|
describe('getActionByRoleId', () => {
|
||
|
test('returns every action if role is not provided', async () => {
|
||
|
global.strapi = {
|
||
|
admin: {
|
||
|
services: {
|
||
|
permission: {
|
||
|
actionProvider: {
|
||
|
values() {
|
||
|
return fixtures;
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
};
|
||
|
|
||
|
const actions = await getActionsByRoleId();
|
||
|
expect(actions.length).toBe(fixtures.length);
|
||
|
expect(actions).toEqual(expect.arrayContaining(fixtures));
|
||
|
});
|
||
|
|
||
|
test('returns every action if role is not the author role', async () => {
|
||
|
const findOneRoleMock = jest.fn(() => ({ code: 'custom-code ' }));
|
||
|
const roleId = 1;
|
||
|
|
||
|
global.strapi = {
|
||
|
admin: {
|
||
|
services: {
|
||
|
role: {
|
||
|
findOne: findOneRoleMock,
|
||
|
},
|
||
|
permission: {
|
||
|
actionProvider: {
|
||
|
values() {
|
||
|
return fixtures;
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
};
|
||
|
|
||
|
const actions = await getActionsByRoleId(roleId);
|
||
|
|
||
|
expect(findOneRoleMock).toHaveBeenCalledWith({ id: roleId });
|
||
|
expect(actions.length).toBe(fixtures.length);
|
||
|
expect(actions).toEqual(expect.arrayContaining(fixtures));
|
||
|
});
|
||
|
|
||
|
test('excludes publish action for author role', async () => {
|
||
|
const findOneRoleMock = jest.fn(() => ({ code: AUTHOR_CODE }));
|
||
|
const roleId = 1;
|
||
|
|
||
|
global.strapi = {
|
||
|
admin: {
|
||
|
services: {
|
||
|
role: {
|
||
|
findOne: findOneRoleMock,
|
||
|
},
|
||
|
permission: {
|
||
|
actionProvider: {
|
||
|
values() {
|
||
|
return fixtures;
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
};
|
||
|
|
||
|
const actions = await getActionsByRoleId(roleId);
|
||
|
|
||
|
expect(findOneRoleMock).toHaveBeenCalledWith({ id: roleId });
|
||
|
expect(actions.length).toBe(fixtures.length - 1);
|
||
|
expect(actions).toEqual(
|
||
|
expect.arrayContaining(fixtures.filter(f => f.actionId !== PUBLISH_ACTION))
|
||
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|