deadhead-space-freight-tycoon/packages/sim/test/record.test.ts

81 lines
2.2 KiB
TypeScript

import { content } from "@deadhead/content";
import { describe, expect, it } from "vitest";
import {
createDispatchRecord,
MS_PER_HOUR,
travelTimeGameHours,
type Contract,
type RecordInput,
} from "../src/index";
const now = Date.parse("2100-01-01T00:30:00Z");
const contract: Contract = {
id: "c1",
originId: "earth",
destinationId: "moon",
cargoTypeId: "standard",
tier: 0,
massTonnes: 10,
payout: 2000,
requiredSkill: null,
requiredLongHaulLevel: 0,
offeredAt: Date.parse("2100-01-01T00:00:00Z"),
expiresAt: Date.parse("2100-01-01T01:00:00Z"),
firstContact: false,
};
const input: RecordInput = {
id: "d1",
ship: { id: "s1", modelId: "courier", locationId: "earth", inFlight: false },
pilot: {
id: "p1",
isAvatar: false,
assignedShipId: "s1",
inFlight: false,
skills: {},
restEndsAt: null,
},
contract,
tutorial: false,
now,
worldSeed: 7,
};
describe("dispatch record", () => {
it("arrives after exactly the travel time converted to real time", () => {
const record = createDispatchRecord(input, content);
const courier = content.shipModel("courier")!;
const travelGameMs =
travelTimeGameHours(courier, record.distanceMillionKm, contract.massTonnes, content.config) *
MS_PER_HOUR;
expect(record.arrivalAt - record.departureAt).toBe(
Math.round(travelGameMs / content.config.timeCompression),
);
});
it("copies the route, payout and parties, and charges fuel", () => {
const record = createDispatchRecord(input, content);
expect(record).toMatchObject({
id: "d1",
shipId: "s1",
pilotId: "p1",
originId: "earth",
destinationId: "moon",
departureAt: now,
expectedPayout: 2000,
tutorial: false,
});
expect(record.fuelCost).toBeGreaterThan(0);
});
it("charges no fuel on a tutorial run", () => {
expect(createDispatchRecord({ ...input, tutorial: true }, content).fuelCost).toBe(0);
});
it("is identical for identical inputs and seeded per dispatch", () => {
expect(createDispatchRecord(input, content)).toEqual(createDispatchRecord(input, content));
expect(createDispatchRecord({ ...input, id: "d2" }, content).seed).not.toBe(
createDispatchRecord(input, content).seed,
);
});
});