This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import { describe, it } from 'node:test';
|
||||
import { permissionGranted, resolvePermissionGrants } from '../src/permissions';
|
||||
|
||||
describe('role permissions', () => {
|
||||
it('keeps deal writes on the side where the person is a member', () => {
|
||||
const grants = resolvePermissionGrants({
|
||||
isPlatformAdmin: false,
|
||||
teams: [{ team: 'demand', role: 'member' }],
|
||||
});
|
||||
|
||||
assert.equal(permissionGranted(grants, 'deal:write', 'demand'), true);
|
||||
assert.equal(permissionGranted(grants, 'deal:write', 'supply'), false);
|
||||
assert.equal(permissionGranted(grants, 'commitment:write', 'demand'), false);
|
||||
});
|
||||
|
||||
it('allows supply leads to commit capacity without letting them sign contracts', () => {
|
||||
const grants = resolvePermissionGrants({
|
||||
isPlatformAdmin: false,
|
||||
teams: [{ team: 'supply', role: 'lead' }],
|
||||
});
|
||||
|
||||
assert.equal(permissionGranted(grants, 'commitment:write', 'supply'), true);
|
||||
assert.equal(permissionGranted(grants, 'contract:sign', 'supply'), false);
|
||||
});
|
||||
|
||||
it('keeps signing and bulk import at team-admin level', () => {
|
||||
const grants = resolvePermissionGrants({
|
||||
isPlatformAdmin: false,
|
||||
teams: [{ team: 'demand', role: 'admin' }],
|
||||
});
|
||||
|
||||
assert.equal(permissionGranted(grants, 'contract:sign', 'demand'), true);
|
||||
assert.equal(permissionGranted(grants, 'contract:sign', 'supply'), false);
|
||||
assert.equal(permissionGranted(grants, 'data:import', 'demand'), true);
|
||||
assert.equal(permissionGranted(grants, 'data:import', 'research'), false);
|
||||
assert.equal(permissionGranted(grants, 'settings:admin'), false);
|
||||
});
|
||||
|
||||
it('gives platform admins global grants without synthetic team memberships', () => {
|
||||
const grants = resolvePermissionGrants({ isPlatformAdmin: true, teams: [] });
|
||||
|
||||
assert.equal(permissionGranted(grants, 'deal:write', 'demand'), true);
|
||||
assert.equal(permissionGranted(grants, 'commitment:write', 'supply'), true);
|
||||
assert.equal(permissionGranted(grants, 'data:import', 'research'), true);
|
||||
assert.equal(permissionGranted(grants, 'settings:admin'), true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user