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

15 lines
1.5 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {syncGamePermissions} from '../node/game-permission-sync.mjs';
test('Activated game sync sends central effective groups through the existing revision-confirmed bridge',async()=>{
const player={id:'11111111-1111-4111-8111-111111111111',role:'owners',username:'test',minecraft_uuid:'22222222-2222-4222-8222-222222222222'};
const db={organisationAccessEnabled:true,prepare(sql){assert(sql.includes('game_link_exempt'));return {all:async()=>({results:[player]})};}};
let posted;
await syncGamePermissions(db,{settings:{SERVER_CONTROL_TOKEN:'test'.repeat(16)},access:async()=>({organisation:{mode:'active'},ranks:[],nodes:['dune.staff.warn','web.bank.personal.view']}),fetcher:async(url,options)=>{
assert.equal(url,'http://127.0.0.1:15433/permissions/teams');posted=JSON.parse(options.body);return Response.json({ok:true,revision:posted.revision});
}});
assert.deepEqual(posted.ranks[0].permissions,{'dune.staff.warn':true,'dunebank.use':true});assert(!posted.users[0].ranks.includes('owners'));assert.equal(posted.users[0].uuid,player.minecraft_uuid);
});
test('A game bridge response with the wrong revision is never treated as successful',async()=>{
const db={organisationAccessEnabled:true,prepare(){return {all:async()=>({results:[]})};}};
await assert.rejects(syncGamePermissions(db,{settings:{SERVER_CONTROL_TOKEN:'test'.repeat(16)},fetcher:async()=>Response.json({ok:true,revision:'wrong'})}),/unconfirmed/);
});