71 lines
3.8 KiB
TypeScript
71 lines
3.8 KiB
TypeScript
// @dune-suite integration
|
|
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import type { GameView } from '../game/engine';
|
|
import type { PublicDeal } from '../game/public-deals';
|
|
|
|
const base = process.env.DUNE_TEST_URL ?? 'http://localhost:3000';
|
|
async function request(path: string, cookie?: string, body?: unknown) {
|
|
const response = await fetch(base + path, {
|
|
method: body === undefined ? 'GET' : 'POST', signal: AbortSignal.timeout(15_000),
|
|
headers: {
|
|
...(body === undefined ? {} : {'Content-Type':'application/json'}),
|
|
...(cookie ? {cookie} : {}),
|
|
},
|
|
...(body === undefined ? {} : {body:JSON.stringify(body)}),
|
|
});
|
|
return {status:response.status, cookie:response.headers.get('set-cookie')?.split(';')[0],
|
|
data:await response.json() as GameView & {error?:string}};
|
|
}
|
|
|
|
/** A new two-seat room exercises the actual authenticated offer and consent;
|
|
* future terms need no staged counters, special cards, or existing saves. */
|
|
void test('authenticated multi-travel deal exposes each independently scheduled term', async () => {
|
|
const host = await request('/api/rooms',undefined,{
|
|
name:'Multiple journeys',faction:'harkonnen',advanced:false,expansions:[],
|
|
});
|
|
assert.equal(host.status,201,JSON.stringify(host.data)); assert.ok(host.cookie);
|
|
const path = `/api/rooms/${host.data.code}`;
|
|
const guest = await request(path,undefined,{type:'join',name:'Other traveler',faction:'atreides'});
|
|
assert.equal(guest.status,200,JSON.stringify(guest.data)); assert.ok(guest.cookie);
|
|
const seats = [{id:host.data.me,cookie:host.cookie},{id:guest.data.me,cookie:guest.cookie}];
|
|
let view = guest.data;
|
|
const act = async (cookie: string, action: object) => {
|
|
const next = await request(path,cookie,{version:view.version,action});
|
|
assert.equal(next.status,200,JSON.stringify(next.data)); view = next.data;
|
|
};
|
|
for (const seat of seats) await act(seat.cookie,{type:'ready'});
|
|
await act(host.cookie,{type:'start'});
|
|
for (const seat of seats) {
|
|
const own = await request(path,seat.cookie);
|
|
assert.equal(own.status,200,JSON.stringify(own.data)); view = own.data;
|
|
const choices = own.data.players.find(player => player.id === seat.id)?.traitorChoices;
|
|
if (choices?.length) await act(seat.cookie,{type:'traitor',leader:choices[0]});
|
|
}
|
|
assert.equal(view.status,'playing');
|
|
const travel = {kind:'ship',territory:'polar_sink',minimum:1,answer:true,dueTurn:view.turn+1};
|
|
const additionalTravel = [
|
|
{actor:host.data.me,kind:'move',territory:'imperial_basin',minimum:1,answer:true,dueTurn:view.turn+1},
|
|
{actor:guest.data.me,kind:'move',territory:'polar_sink',minimum:1,answer:false,dueTurn:view.turn+2},
|
|
];
|
|
await act(host.cookie,{type:'dealOffer',target:guest.data.me,
|
|
terms:'We each agree to the listed future journeys.',travel,additionalTravel});
|
|
const offered = view.deals.at(-1); assert.ok(offered);
|
|
assert.equal(offered.status,'offered');
|
|
assert.deepEqual(offered.travel,travel);
|
|
assert.deepEqual(offered.additionalTravel,additionalTravel);
|
|
assert.equal(view.dealTravelStatus[offered.id],undefined);
|
|
assert.equal(view.dealAdditionalTravelStatus[offered.id],undefined);
|
|
await act(guest.cookie,{type:'dealRespond',deal:offered.id,accept:true});
|
|
for (const seat of seats) {
|
|
const read = await request(path,seat.cookie);
|
|
assert.equal(read.status,200,JSON.stringify(read.data));
|
|
const active: PublicDeal | undefined = read.data.deals.find(deal => deal.id === offered.id);
|
|
assert.ok(active); assert.equal(active.status,'active');
|
|
assert.deepEqual(active.travel,travel);
|
|
assert.deepEqual(active.additionalTravel,additionalTravel);
|
|
assert.equal(read.data.dealTravelStatus[offered.id],'scheduled');
|
|
assert.deepEqual(read.data.dealAdditionalTravelStatus[offered.id],['scheduled','scheduled']);
|
|
}
|
|
});
|