Fix tests

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-06-11 16:40:07 +02:00 committed by Alexandre Bodin
parent 99dac93f27
commit 9cb4e76830
2 changed files with 29 additions and 4 deletions

View File

@ -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) {

View File

@ -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();
});
});