deadhead-space-freight-tycoon/apps/server/test/tutorial-flow.ts

32 lines
1.2 KiB
TypeScript

import {
contractBoardResponseSchema,
dispatchResponseSchema,
type PlayerState,
} from "@deadhead/schema";
import { call, getState, type Guest, type TestApp } from "./game";
/** The tutorial board the player sees now. */
export async function tutorialBoard(app: TestApp["app"], guest: Guest) {
const response = await call(app, guest, "GET", "/api/tutorial/board");
if (response.statusCode !== 200) throw new Error(`board failed: ${response.body}`);
return contractBoardResponseSchema.parse(response.json()).contracts;
}
/** Flies one tutorial run (the given slot, light by default) and lets it land. */
export async function flyTutorialRun(
testApp: TestApp,
guest: Guest,
slot = 0,
): Promise<PlayerState> {
const { app, clock } = testApp;
const contract = (await tutorialBoard(app, guest))[slot]!;
const response = await call(app, guest, "POST", "/api/dispatches", {
kind: "tutorial",
contractId: contract.id,
});
if (response.statusCode !== 200) throw new Error(`dispatch failed: ${response.body}`);
const { dispatch } = dispatchResponseSchema.parse(response.json());
clock.now = dispatch.arrivalAt;
return getState(app, guest);
}