import test from 'node:test';import assert from 'node:assert/strict'; import {projectClanTreasury,loadClanMail,projectOfficeTreasury} from '../control-panel/public/clan-dashboard-data.mjs'; import {projectClanActivity} from '../node/clan-activity.mjs'; test('treasury never substitutes another clan, personal funds or blocked accounts',()=>{ const account={id:'a',number:'DR00105123456789',type:'105',state:'active',available:'12.34'}; const view={entities:[{kind:'person',clanId:'ours',accounts:[account]},{kind:'clan',clanId:'other',accounts:[account]},{kind:'clan',clanId:'ours',state:'active',accounts:[account,{...account,id:'blocked',type:'106'},{...account,id:'closed',state:'closed'}]}]}; assert.deepEqual(projectClanTreasury(view,'ours'),{state:'active',accounts:[{id:'a',number:account.number,available:'12.34'}]});assert.throws(()=>projectClanTreasury(view,'missing'));assert.throws(()=>projectClanTreasury({entities:[{kind:'clan',clanId:'ours',accounts:[{...account,available:1234}]}]},'ours')); }); test('clan activity projects only scoped public events and never raw audit/private requests',()=>{ const make=(action,detail={},extra={})=>({action,actor_name:'Captain',details:JSON.stringify({clanId:'ours',secret:'never expose',...detail}),created_at:100,...extra}); const data=projectClanActivity([make('clan-review',{target:'NewMember',decision:'accept'}),make('clan-review',{target:'Hidden',decision:'decline'}),make('clan-request'),make('clan-leave'),make('clan-role',{target:'Officer',role:'officer'}),make('clan-remove',{target:'Other',clanId:'other'}),make('clan-edit',{}, {details:'broken'})],'ours'); assert.equal(data.length,3);assert.equal(data[0].message,'NewMember joined the clan.');assert.equal(data[1].message,'Captain left the clan.');assert.doesNotMatch(JSON.stringify(data),/never expose|Hidden|actor_id|details/); }); test('mail summary uses existing authorised clan scope without opening or marking messages read',async()=>{ let options;assert.equal(await loadClanMail({fetcher:async(path,opts)=>{assert.equal(path,'/api/internal-mail/messages/list');options=opts;return Response.json({total:3});}}),3);assert.deepEqual(JSON.parse(options.body),{scope:'clan',folder:'INBOX',offset:0,limit:1,unread:true});assert.equal(options.credentials,'same-origin');await assert.rejects(loadClanMail({fetcher:async()=>Response.json({total:-1})})); }); test('office treasury uses its exact authorised civic account, never another office or personal funds',()=>{ const account={id:'civic',number:'DR00107123456789',type:'107',state:'active',available:'25.00'}; const view={entities:[{id:'office-a',kind:'person',accounts:[account]},{id:'office-b',kind:'office',accounts:[account]},{id:'office-a',kind:'office',state:'active',accounts:[account,{...account,id:'collateral',type:'106'},{...account,id:'closed',state:'closed'}]}]}; assert.deepEqual(projectOfficeTreasury(view,'office-a'),{state:'active',accounts:[{id:'civic',number:account.number,available:'25.00'}]});assert.throws(()=>projectOfficeTreasury(view,'missing'));assert.throws(()=>projectOfficeTreasury(view,null));assert.throws(()=>projectOfficeTreasury({entities:[{id:'office-a',kind:'office',accounts:[{...account,available:25}]}]},'office-a')); });