forked from unimatrix/web
28 lines
3.2 KiB
JavaScript
28 lines
3.2 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';import {randomUUID} from 'node:crypto';
|
|
import {fixture} from './rebellion-fixture.mjs';import {REBELLION_COOLDOWN_MS} from '../node/rebellion-quests.mjs';
|
|
test('the previous declaration key enforces exactly fifteen days, including withdrawn keys, without a timer job',async()=>{
|
|
const f=await fixture();try{
|
|
await f.db.query('UPDATE political_office_terms SET expires_at=?',[f.now()+40*86400000]);await f.db.query('UPDATE jarvis_pol_progression_seasons SET ends_at=?',[f.now()+50*86400000]);
|
|
const q=await f.service.declare(f.winner,f.input);await f.service.cancel(f.winner,{questKeyId:q.keyId});
|
|
const next={...f.input,requestId:randomUUID()};await assert.rejects(f.service.declare(f.winner,next),/wait 15 days/);
|
|
const choice=(await f.service.options(f.winner,f.attacker)).find(c=>c.officeKey==='emperor');assert.equal(choice.eligible,false);assert.equal(choice.cooldownUntil,q.declaredAt+REBELLION_COOLDOWN_MS);
|
|
f.clock(q.declaredAt+REBELLION_COOLDOWN_MS-1);await assert.rejects(f.service.declare(f.winner,next),/wait 15 days/);
|
|
f.clock(q.declaredAt+REBELLION_COOLDOWN_MS);assert.equal((await f.service.declare(f.winner,next)).state,'issued');
|
|
}finally{f.db.close();}
|
|
});
|
|
for(const [officeKey,expectedSecond]of [['emperor',2],['atreides',1]])test('first successful '+officeKey+' rebellion receives six times base; the next '+(officeKey==='emperor'?'original-House counterchallenge receives double':'ordinary House victory returns to default'),async()=>{
|
|
const f=await fixture({officeKey});try{
|
|
const previousHouse=officeKey==='emperor'?'harkonnen':'atreides',previousIdentity=await f.db.first('SELECT minecraft_uuid FROM site_game_links WHERE user_id=?',[f.incumbent.id]);
|
|
await f.db.query('INSERT INTO site_character_choices VALUES(?,?,?)',[f.incumbent.id,previousIdentity.minecraft_uuid,previousHouse]);
|
|
const first=await f.service.declare(f.winner,f.input),firstEvidence=await f.capture(first),a=await f.service.applyCapture(f.producer,firstEvidence);
|
|
assert.equal(a.rewardMultiplier,6);assert.equal(a.firstSuccessBonus,true);
|
|
const second=await f.service.declare(f.incumbent,{clanId:f.defender,officeKey,expectedTermId:first.keyId,expectedHomeBlockId:f.home,requestId:randomUUID(),confirmed:true});
|
|
assert.equal(second.rewardMultiplier,expectedSecond);if(officeKey==='emperor')assert.equal(second.counterChallengeOf,first.keyId);
|
|
const evidence=await f.capture(second,{attackerClanId:f.defender,defenderClanId:f.attacker,homeBlockId:f.home,worldUuid:f.world,winnerUuid:previousIdentity.minecraft_uuid,sourceTermId:first.keyId});
|
|
const b=await f.service.applyCapture(f.producer,evidence);assert.equal(b.rewardMultiplier,expectedSecond);assert.equal(b.firstSuccessBonus,false);
|
|
const base=officeKey==='emperor'?10000:2500;assert.equal(a.reputationXP,base*6);assert.equal(b.reputationXP,base*expectedSecond);
|
|
assert.equal((await f.db.first("SELECT COUNT(*) n FROM jarvis_rebellion_rewards WHERE bonus_marker='inaugural'")).n,1);
|
|
assert.equal((await f.db.first('SELECT COUNT(*) n FROM jarvis_rebellion_rewards')).n,2);
|
|
assert.equal((await f.service.applyCapture(f.producer,evidence)).replayed,true);
|
|
}finally{f.db.close();}
|
|
});
|

Staff