70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
// Ported from apps/server/test (CR-014 Step 14.5): now runs on the engine.
|
|
import { errorResponseSchema } from "@deadhead/schema";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import {
|
|
useTestApp,
|
|
signUp,
|
|
call,
|
|
readSave,
|
|
setCredits,
|
|
testContract,
|
|
putBoard,
|
|
makeOwner,
|
|
addShip,
|
|
addPilot,
|
|
} from "../support";
|
|
const randomUUID = () => globalThis.crypto.randomUUID();
|
|
|
|
// Every base-game ship is atmospheric (decision 0.5.1), so `cannot-land` needs
|
|
// a test-only vacuum ship in the content the server sees.
|
|
vi.mock("@deadhead/content", async (importOriginal) => {
|
|
const original = await importOriginal<typeof import("@deadhead/content")>();
|
|
const courier = original.content.shipModel("courier")!;
|
|
const shipModels = [
|
|
...original.content.shipModels,
|
|
{ ...courier, id: "test-vacuum", landingClass: "vacuum" as const },
|
|
];
|
|
return {
|
|
...original,
|
|
content: {
|
|
...original.content,
|
|
shipModels,
|
|
shipModel: (id: string) => shipModels.find((s) => s.id === id),
|
|
},
|
|
};
|
|
});
|
|
|
|
const testApp = useTestApp();
|
|
|
|
describe("contract dispatch landing check", () => {
|
|
it("rejects cannot-land and changes nothing", async () => {
|
|
const { app } = testApp();
|
|
const guest = await signUp(app);
|
|
await makeOwner(app, guest.avatarId);
|
|
await setCredits(app, 10_000);
|
|
|
|
// A vacuum-only ship at the Moon, crewed by a pilot, offered a Moon→Earth job.
|
|
const shipId = randomUUID();
|
|
await addShip(app, {
|
|
id: shipId,
|
|
modelId: "test-vacuum",
|
|
name: "Moon Crawler",
|
|
locationId: "moon",
|
|
});
|
|
const pilotId = randomUUID();
|
|
await addPilot(app, { id: pilotId, name: "Vac Pilot", assignedShipId: shipId });
|
|
const contract = testContract({ originId: "moon", destinationId: "earth" });
|
|
await putBoard(app, [contract]);
|
|
|
|
const response = await call(app, guest, "POST", "/api/dispatches", {
|
|
kind: "contract",
|
|
contractId: contract.id,
|
|
shipId,
|
|
pilotId,
|
|
});
|
|
expect(response.statusCode).toBe(409);
|
|
expect(errorResponseSchema.parse(response.json()).error.code).toBe("cannot-land");
|
|
expect((await readSave(app)).dispatches).toEqual([]);
|
|
});
|
|
});
|