mirror of
https://github.com/Unleash/unleash.git
synced 2025-11-10 01:19:53 +01:00
We're migrating to ESM, which will allow us to import the latest versions of our dependencies. Co-Authored-By: Christopher Kolstad <chriswk@getunleash.io>
122 lines
3.7 KiB
TypeScript
122 lines
3.7 KiB
TypeScript
import { canGrantProjectRole } from './can-grant-project-role.js';
|
|
|
|
describe('canGrantProjectRole', () => {
|
|
test('should return true if the granter has all the permissions the receiver needs', () => {
|
|
const granterPermissions = [
|
|
{
|
|
project: 'test',
|
|
environment: undefined,
|
|
permission: 'CREATE_FEATURE',
|
|
},
|
|
{
|
|
project: 'test',
|
|
environment: 'production',
|
|
permission: 'UPDATE_FEATURE_ENVIRONMENT',
|
|
},
|
|
{
|
|
project: 'test',
|
|
environment: 'production',
|
|
permission: 'APPROVE_CHANGE_REQUEST',
|
|
},
|
|
];
|
|
|
|
const receiverPermissions = [
|
|
{
|
|
id: 28,
|
|
name: 'UPDATE_FEATURE_ENVIRONMENT',
|
|
environment: 'production',
|
|
displayName: 'Enable/disable flags',
|
|
type: 'environment',
|
|
},
|
|
{
|
|
id: 29,
|
|
name: 'APPROVE_CHANGE_REQUEST',
|
|
environment: 'production',
|
|
displayName: 'Enable/disable flags',
|
|
type: 'environment',
|
|
},
|
|
];
|
|
|
|
canGrantProjectRole(granterPermissions, receiverPermissions);
|
|
});
|
|
|
|
test('should return false if the granter and receiver permissions have different environments', () => {
|
|
const granterPermissions = [
|
|
{
|
|
project: 'test',
|
|
environment: 'production',
|
|
permission: 'UPDATE_FEATURE_ENVIRONMENT',
|
|
},
|
|
{
|
|
project: 'test',
|
|
environment: 'production',
|
|
permission: 'APPROVE_CHANGE_REQUEST',
|
|
},
|
|
];
|
|
|
|
const receiverPermissions = [
|
|
{
|
|
id: 28,
|
|
name: 'UPDATE_FEATURE_ENVIRONMENT',
|
|
environment: 'development',
|
|
displayName: 'Enable/disable flags',
|
|
type: 'environment',
|
|
},
|
|
{
|
|
id: 29,
|
|
name: 'APPROVE_CHANGE_REQUEST',
|
|
environment: 'development',
|
|
displayName: 'Enable/disable flags',
|
|
type: 'environment',
|
|
},
|
|
];
|
|
|
|
expect(
|
|
canGrantProjectRole(granterPermissions, receiverPermissions),
|
|
).toBeFalsy();
|
|
});
|
|
|
|
test('should return false if the granter does not have all receiver permissions', () => {
|
|
const granterPermissions = [
|
|
{
|
|
project: 'test',
|
|
environment: 'production',
|
|
permission: 'UPDATE_FEATURE_ENVIRONMENT',
|
|
},
|
|
{
|
|
project: 'test',
|
|
environment: 'production',
|
|
permission: 'APPROVE_CHANGE_REQUEST',
|
|
},
|
|
];
|
|
|
|
const receiverPermissions = [
|
|
{
|
|
id: 28,
|
|
name: 'UPDATE_FEATURE_ENVIRONMENT',
|
|
environment: 'production',
|
|
displayName: 'Enable/disable flags',
|
|
type: 'environment',
|
|
},
|
|
{
|
|
id: 29,
|
|
name: 'APPROVE_CHANGE_REQUEST',
|
|
environment: 'production',
|
|
displayName: 'Enable/disable flags',
|
|
type: 'environment',
|
|
},
|
|
{
|
|
id: 26,
|
|
name: 'UPDATE_FEATURE_STRATEGY',
|
|
environment: 'production',
|
|
displayName: 'Update activation strategies',
|
|
type: 'environment',
|
|
},
|
|
];
|
|
|
|
expect(
|
|
canGrantProjectRole(granterPermissions, receiverPermissions),
|
|
).toBeFalsy();
|
|
});
|
|
});
|