test(e2e): rework shared helpers + state spec to the queue + NEXT TURN model (1/3) (#44)
This commit is contained in:
+15
-8
@@ -1,7 +1,7 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
import path from 'node:path';
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { jumpToFreshSystem } from './helpers';
|
||||
import { jumpToFreshSystem, resolveAction } from './helpers';
|
||||
|
||||
// Repo root — docker-compose.yml lives here; `docker compose restart` runs on
|
||||
// this host (the test runner), browsers stay remote. CI points E2E_COMPOSE_ARGS at the
|
||||
@@ -13,6 +13,10 @@ const composeArgs = process.env.E2E_COMPOSE_ARGS ?? '';
|
||||
interface PlanetDto { id: number; name: string; type: string; hazard: boolean; explored: boolean; parent: number | null }
|
||||
interface SystemState { systemId: number; systemName: string; planets: PlanetDto[]; inventory: { kind: string; name: string; qty: number }[]; turn: number }
|
||||
interface CrewDto { id: number; name: string; role: string; traitGood: string; traitBad: string; origin: string }
|
||||
// Mirrors the task row of lib/game/tasks.ts minus saveId — GET /api/crew is the {crew, tasks}
|
||||
// object (Task 6 / JC-7): ACTIVE block first, then PENDING, DONE filtered.
|
||||
interface TaskDto { id: number; type: string; payload: string; leadCrewId: number; helpers: number[]; duration: number; remaining: number; status: string; queuedAtTurn: number }
|
||||
interface CrewState { crew: CrewDto[]; tasks: TaskDto[] }
|
||||
interface ShipSystemDto { id: number; type: string; level: number; capacity: number; built: boolean }
|
||||
interface ShipState { systems: ShipSystemDto[]; inventory: { kind: string; name: string; qty: number }[]; turn: number }
|
||||
interface TechDto { id: number; slug: string; name: string; costKind: string; costQty: number; prereqs: string[]; effect: string; state: string; missingPrereqs: string[] }
|
||||
@@ -39,13 +43,15 @@ test('app survives a container restart (stack + volume persistence)', async ({ p
|
||||
sysBefore = (await (await page.request.get('/api/system')).json()) as SystemState;
|
||||
}
|
||||
const targetPlanet = sysBefore.planets.find((p) => !p.explored)!;
|
||||
const exploreRes = await page.request.post('/api/explore', { data: { planetId: targetPlanet.id } });
|
||||
expect(exploreRes.status()).toBe(200);
|
||||
const sysExplored = (await exploreRes.json()) as SystemState;
|
||||
// The explore POST only queues — no turn bump, explored not yet flipped — so tick it to
|
||||
// completion and re-derive the baseline from the post-tick /api/system snapshot: the turn it
|
||||
// pins (compared after the restart) must be the resolved one, not the queue's.
|
||||
const sysExplored = (await resolveAction(page, '/api/explore', { planetId: targetPlanet.id })) as SystemState;
|
||||
expect(sysExplored.planets.find((p) => p.id === targetPlanet.id)?.explored).toBe(true); // the scan resolved before the baseline is pinned
|
||||
|
||||
// Crew baseline: the roster (starting crew + any finds so far) must survive too.
|
||||
const crewBefore = (await (await page.request.get('/api/crew')).json()) as CrewDto[];
|
||||
expect(crewBefore.length).toBeGreaterThanOrEqual(2); // starting crew is always seeded
|
||||
const crewBefore = (await (await page.request.get('/api/crew')).json()) as CrewState;
|
||||
expect(crewBefore.crew.length).toBeGreaterThanOrEqual(2); // starting crew is always seeded
|
||||
|
||||
// Ship baseline: the systems (levels/capacities) + cargo hold must survive too.
|
||||
const shipBefore = (await (await page.request.get('/api/ship')).json()) as ShipState;
|
||||
@@ -95,8 +101,9 @@ test('app survives a container restart (stack + volume persistence)', async ({ p
|
||||
expect(sysAfter.turn).toBe(sysExplored.turn);
|
||||
expect(sysAfter.planets.find((p) => p.id === targetPlanet.id)?.explored).toBe(true);
|
||||
|
||||
// Crew roster survived too: same members, traits and origins (no re-seed on restart).
|
||||
const crewAfter = (await (await page.request.get('/api/crew')).json()) as CrewDto[];
|
||||
// Crew roster survived too: same members, traits and origins (no re-seed on restart). The
|
||||
// {crew, tasks} object shape (JC-7) means the still-queued task rows survive with it too.
|
||||
const crewAfter = (await (await page.request.get('/api/crew')).json()) as CrewState;
|
||||
expect(crewAfter).toEqual(crewBefore);
|
||||
|
||||
// Ship state survived too: same systems, levels/capacities and cargo hold.
|
||||
|
||||
Reference in New Issue
Block a user