MC/website/tests/organisation-default-policies.test.mjs
2026-11-27 23:43:05 +00:00

20 lines
2.1 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {defaultOrganisationPolicies} from '../node/organisation-default-policies.mjs';
import {effectiveOrganisationAccess} from '../node/organisation-effective.mjs';
import {NODES} from '../node/permissions.mjs';
const policies=defaultOrganisationPolicies();
test('All nine branches, two departments and executive functions have registered explicit policies',()=>{
assert.equal(policies.length,22);assert.equal(new Set(policies.map(p=>p.scopeType+':'+p.scopeKey+':'+p.role)).size,22);
for(const p of policies)for(const n of p.nodes){assert(Object.hasOwn(NODES,n));assert(!n.includes('*'));assert(!n.endsWith('.op'));assert.notEqual(n,'web.luckperms.edit');}
});
test('Bank management belongs to department/executive policies and payroll only to the Big Four policy',()=>{
for(const p of policies){if(p.scopeType==='branch')assert(!p.nodes.includes('web.bank.staff.manage'));if(p.scopeType!=='organisation')assert(!p.nodes.includes('web.payroll.manage'));}
});
test('Job-specific rights do not leak between news, support and technical officers',()=>{
const by=key=>policies.find(p=>p.scopeKey===key&&p.role==='officer').nodes;
assert(by('news_media').includes('web.posts.edit'));assert(!by('news_media').includes('web.posts.publish'));assert(!by('customer_support').includes('dune.staff.ban.network'));assert(!by('sales_accounts').includes('web.servers.console'));assert(by('it_operations').includes('web.servers.console'));
});
test('Lead policy plus own officer policy yields a complete branch role',()=>{
const result=effectiveOrganisationAccess({assignments:[{id:'news',scope_type:'branch',scope_key:'news_media',role_key:'branch_lead',status:'active',starts_at:1,ends_at:null}],policies:policies.map(p=>({scope_type:p.scopeType,scope_key:p.scopeKey,role_key:p.role,permissions_json:JSON.stringify(p.nodes),version:1})),registry:NODES,now:2});
assert(result.nodes.includes('web.posts.edit'));assert(result.nodes.includes('web.posts.publish'));assert(!result.nodes.includes('web.bank.staff.manage'));assert.equal(result.blocked.length,0);
});