mirror of
https://github.com/strapi/strapi.git
synced 2025-12-24 21:54:24 +00:00
Fix tests
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
99dac93f27
commit
9cb4e76830
@ -17,7 +17,7 @@ const findMatchingPermissions = (userPermissions, permissions) => {
|
||||
};
|
||||
|
||||
const shouldCheckPermissions = permissions =>
|
||||
permissions.every(perm => perm.conditions && perm.conditions.length);
|
||||
permissions.every(perm => perm.conditions && perm.conditions.length) && permissions.length;
|
||||
|
||||
const hasPermissions = async (userPermissions, permissions) => {
|
||||
if (!permissions.length) {
|
||||
|
||||
@ -73,7 +73,7 @@ describe('STRAPI-HELPER_PLUGIN | utils ', () => {
|
||||
expect(shouldCheckPermissions([])).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return true if there is no condition in the array of permissions', () => {
|
||||
it('should return false if there is no condition in the array of permissions', () => {
|
||||
const data = [
|
||||
{
|
||||
action: 'admin::marketplace.read',
|
||||
@ -83,10 +83,10 @@ describe('STRAPI-HELPER_PLUGIN | utils ', () => {
|
||||
},
|
||||
];
|
||||
|
||||
expect(shouldCheckPermissions(data)).toBeTruthy();
|
||||
expect(shouldCheckPermissions(data)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return true if there is at least one item that has a condition in the array of permissions', () => {
|
||||
it('should return false if there is at least one item that does not have a condition in the array of permissions', () => {
|
||||
const data = [
|
||||
{
|
||||
action: 'admin::marketplace.read',
|
||||
@ -108,6 +108,31 @@ describe('STRAPI-HELPER_PLUGIN | utils ', () => {
|
||||
},
|
||||
];
|
||||
|
||||
expect(shouldCheckPermissions(data)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return true otherwise', () => {
|
||||
const data = [
|
||||
{
|
||||
action: 'admin::marketplace.read',
|
||||
subject: null,
|
||||
fields: null,
|
||||
conditions: ['test'],
|
||||
},
|
||||
{
|
||||
action: 'admin::marketplace.plugins.uninstall',
|
||||
subject: null,
|
||||
fields: null,
|
||||
conditions: ['customCondition'],
|
||||
},
|
||||
{
|
||||
action: 'admin::marketplace.plugins.install',
|
||||
subject: null,
|
||||
fields: null,
|
||||
conditions: ['test'],
|
||||
},
|
||||
];
|
||||
|
||||
expect(shouldCheckPermissions(data)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user