MC/website/tests/rebellion-homeblock-required.test.mjs
2026-11-27 23:43:05 +00:00

9 lines
2 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {fixture} from './rebellion-fixture.mjs';
async function removeHomeBlock(f,id){const kind=id===f.officeId?'protected':'clan';const row=await f.db.first("SELECT snapshot_json FROM site_claim_registry WHERE organisation_kind=? AND organisation_id=?",[kind,id]),snapshot=JSON.parse(row.snapshot_json);snapshot.homeBlock=null;await f.db.query("UPDATE site_claim_registry SET snapshot_json=?,revision=revision+1 WHERE organisation_kind=? AND organisation_id=?",[JSON.stringify(snapshot),kind,id]);}
for(const side of ['attacker','defender'])test('no '+side+' Home Block automatically denies rebellion without issuing a key',async()=>{
const f=await fixture();try{const before=(await f.keys.list(f.winner.id)).length;await removeHomeBlock(f,side==='defender'?f.officeId:f.attacker);await assert.rejects(f.service.declare(f.winner,f.input),/Home Block is not registered/);assert.equal((await f.keys.list(f.winner.id)).length,before);assert.equal((await f.db.first('SELECT COUNT(*) n FROM jarvis_generated_instructions')).n,0);assert.equal((await f.db.first('SELECT COUNT(*) n FROM jarvis_rebellion_rewards')).n,0);assert.equal((await f.db.first('SELECT outcome FROM political_office_terms WHERE id=?',[f.term])).outcome,'winner');}finally{f.db.close();}
});
test('removing the incumbent Home Block after declaration stops the existing chain before office transfer or rewards',async()=>{
const f=await fixture();try{const q=await f.service.declare(f.winner,f.input),evidence=await f.capture(q);await removeHomeBlock(f,f.officeId);await assert.rejects(f.service.applyCapture(f.producer,evidence),/Home Block is not registered/);assert.equal((await f.keys.list(f.winner.id)).find(k=>k.id===q.keyId).status,'available');assert.equal((await f.db.first('SELECT user_id FROM political_office_terms WHERE id=?',[f.term])).user_id,f.incumbent.id);assert.equal((await f.db.first('SELECT COUNT(*) n FROM jarvis_rebellion_rewards')).n,0);}finally{f.db.close();}
});