Support Advanced Truthtrance ally funding
Verify and publish checkpoint container / container (push) Successful in 11m4s
Verify and publish checkpoint container / container (push) Successful in 11m4s
This commit is contained in:
1 parent
e1209083e6
commit
b3843bf18e
10 files changed
+383
-11
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {registerHooks} from 'node:module';
|
||||
import {readFileSync} from 'node:fs';
|
||||
import {createElement} from 'react';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {viewGame, type Game} from '../game/engine';
|
||||
import {actTruthAlliance as act, advanceTruthAlliance as advance, createTruthAllianceFixture,
|
||||
truthAllianceClean as clean, truthAlliancePlayer as player} from './fixture-truth-alliance';
|
||||
import {declareTruthBribe} from './fixture-truth-bribe';
|
||||
|
||||
const aliases = registerHooks({
|
||||
resolve(specifier, context, next) {
|
||||
return next(specifier === 'next/image' ? 'vinext/shims/image' :
|
||||
specifier === 'next/link' ? 'vinext/shims/link' : specifier, context);
|
||||
},
|
||||
load(url, context, next) {
|
||||
if (!url.endsWith('.module.css')) return next(url, context);
|
||||
const css = readFileSync(new URL(url), 'utf8');
|
||||
const classes = Object.fromEntries([...css.matchAll(/\.([a-zA-Z_][\w-]*)/g)].map(match => [match[1], match[1]]));
|
||||
return {format:'module', source:`export default ${JSON.stringify(classes)}`, shortCircuit:true};
|
||||
},
|
||||
});
|
||||
const {Truthtrance} = await import('../components/truthtrance');
|
||||
aliases.deregister();
|
||||
|
||||
/** Native Advanced setup, ordinary worm and consensual alliance. The only
|
||||
* staged inputs are the fixture's unopened physical deal and Spice order. */
|
||||
function asked(phase: 3 | 5, tooMuch: boolean) {
|
||||
const f = createTruthAllianceFixture({advanced:true, consent:'allied'});
|
||||
let game = advance(f.game, state => state.phase === phase && (phase !== 3 || !!state.auction) && clean(state));
|
||||
const minimum = tooMuch ? player(game, f.target).spice + (game.aid[f.target]?.amount ?? 0) + 1 : 1;
|
||||
game = declareTruthBribe(f, game).game;
|
||||
assert.ok(viewGame(game, f.asker).truthPledgeTargets.includes(f.target));
|
||||
game = act(game, f.asker, {type:'truthAsk', question:{kind:'pledgeAid',target:f.target,
|
||||
turn:game.turn,phase,ally:f.partner,minimum}});
|
||||
return {game, target:f.target, asker:f.asker};
|
||||
}
|
||||
|
||||
function markup(game:Game, actor:string, busy = false) {
|
||||
return renderToStaticMarkup(createElement(Truthtrance, {game:viewGame(game,actor),busy,act() {
|
||||
assert.fail('Rendering must not send an answer');
|
||||
}}));
|
||||
}
|
||||
|
||||
for (const phase of [3,5] as const) void test(`Advanced phase ${phase} shows only legal Truthtrance funding answers`, () => {
|
||||
const available = asked(phase,false);
|
||||
const view = viewGame(available.game,available.target);
|
||||
assert.ok(view.truthPledgeAnswers?.includes('yes')); assert.ok(view.truthPledgeAnswers?.includes('no'));
|
||||
assert.equal(viewGame(available.game,available.asker).truthPledgeAnswers,null);
|
||||
const html = markup(available.game,available.target);
|
||||
assert.match(html,/Answer Yes/); assert.match(html,/Answer No/);
|
||||
assert.match(html,/future funding update/);
|
||||
const unavailable = asked(phase,true);
|
||||
assert.deepEqual(viewGame(unavailable.game,unavailable.target).truthPledgeAnswers,['no']);
|
||||
const noOnly = markup(unavailable.game,unavailable.target);
|
||||
assert.doesNotMatch(noOnly,/Answer Yes/); assert.match(noOnly,/Answer No/);
|
||||
});
|
||||
Reference in new issue
Block a user