forked from unimatrix/web
7 lines
2 KiB
JavaScript
7 lines
2 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';
|
|
import {projectGovernment,createPublicGovernment,publicElectionCalendar} from '../node/public-government.mjs';
|
|
const now=Date.parse('2026-11-15T10:00:00Z');
|
|
test('every office remains present before the first election',()=>{const offices=projectGovernment([],now);assert.equal(offices.length,11);assert.ok(offices.every(o=>o.state==='vacant'&&o.holder===null));assert.equal(offices.filter(o=>o.kind==='imperial').length,1);});
|
|
test('only a single active elected term can supply an officeholder',()=>{const term={kind:'imperial',faction:'imperium',office:'emperor',outcome:'winner',starts_at:now-1,expires_at:now+1,username:'citizen_one',display_name:'Citizen One',player_uuid:'private'};const office=projectGovernment([term],now)[0];assert.equal(office.state,'occupied');assert.equal(office.holder.profile,'/people/citizen_one');assert.ok(!JSON.stringify(office).includes('private'));for(const row of [{...term,expires_at:now},{...term,starts_at:now+1},{...term,outcome:'no_votes'}])assert.equal(projectGovernment([row],now)[0].state,'vacant');assert.equal(projectGovernment([term,term],now)[0].state,'verification_pending');});
|
|
test('public calendar includes the currently open voting window',()=>{const calendar=publicElectionCalendar(now);assert.equal(calendar[0].phase,'voting');assert.equal(calendar[0].termWeeks,4);assert.equal(calendar[1].phase,'applications');});
|
|
test('public office read rejects overrides and never invents vacancies on a database outage',async()=>{const api=createPublicGovernment({prepare(){throw Error('DB unavailable');}},{clock:()=>now});assert.equal((await api(new Request('https://www.dunerealms.com/api/public/government?user=other'))).status,400);assert.equal((await api(new Request('https://www.dunerealms.com/api/public/government',{method:'POST'}))).status,405);const response=await api(new Request('https://www.dunerealms.com/api/public/government'));assert.equal(response.status,503);assert.equal((await response.json()).offices,undefined);});
|

Staff