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

17 lines
2.1 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {projectOrganisationGameUsers} from '../node/organisation-game-projection.mjs';
const account=(id='11111111-1111-4111-8111-111111111111')=>({id,minecraft_uuid:id});
const rights={organisation:{mode:'active'},ranks:['user','org_officer'],nodes:['dune.staff.warn','web.bank.personal.view','worldedit.*','luckperms.editor','minecraft.command.op']};
const options={access:async()=>rights,citizenGameNodes:async()=>['duneess.basics','dunebank.staff.manage'],gameNodes:new Set(['dune.staff.warn','duneess.basics','dunebank.use','dunebank.staff.manage','worldedit.*','luckperms.editor','minecraft.command.op']),bankMap:{'dunebank.use':'web.bank.personal.view','dunebank.staff.manage':'web.bank.staff.manage'}};
test('Game groups contain explicit effective rights, no stale staff labels or privileged citizen banking',async()=>{
const result=await projectOrganisationGameUsers([account()],options);assert.deepEqual(result.ranks[0].permissions,{'dune.staff.warn':true,'dunebank.use':true,'duneess.basics':true});assert.match(result.ranks[0].id,/^org_[a-f0-9]{20}$/);assert.deepEqual(result.users[0].ranks,[result.ranks[0].id]);
});
test('Identical effective rights reuse one stable group independent of node order',async()=>{
const accounts=[account(),account('22222222-2222-4222-8222-222222222222')];const first=await projectOrganisationGameUsers(accounts,options);assert.equal(first.ranks.length,1);
const second=await projectOrganisationGameUsers(accounts,{...options,access:async()=>({...rights,nodes:[...rights.nodes].reverse()})});assert.deepEqual(first,second);
});
test('Dev service never receives a player group; duplicate player UUIDs and legacy fallback abort',async()=>{
assert.deepEqual(await projectOrganisationGameUsers([account('f7b88778-f0bc-41cc-9227-d8ef2f52264d')],options),{ranks:[],users:[]});
await assert.rejects(projectOrganisationGameUsers([account(),account()],options),/unique verified/);
await assert.rejects(projectOrganisationGameUsers([account()],{...options,access:async()=>({...rights,organisation:undefined})}),/active organisation/);
});