deadhead-space-freight-tycoon/packages/engine/test/fleet-sleep.test.ts

33 lines
1.4 KiB
TypeScript

import { content } from "@deadhead/content";
import { describe, expect, it } from "vitest";
import { encodeSave } from "../src/index";
import { newTestApp, readSave, signUp, TEST_NOW } from "./support";
const HOUR = 60 * 60_000;
describe("fleet sleep in the save (Step 24.1, decisions 0.5.136, 0.5.137)", () => {
it("starts a new company with its creation as the last decision and the default threshold", async () => {
const { app } = newTestApp();
await signUp(app);
const { company } = await readSave(app);
expect(company.lastManualDecisionAt).toBe(TEST_NOW);
expect(company.sleepAfterHours).toBe(content.config.fleetSleep.defaultHours);
});
it("stamps a migrated save's last decision with the time the engine first opens it", async () => {
const { app } = newTestApp();
await signUp(app);
const current = await readSave(app);
// As version 8 wrote it: no sleep fields.
const { lastManualDecisionAt: _at, sleepAfterHours: _hours, ...company } = current.company;
const v8 = { ...current, saveVersion: 8, company };
const device = newTestApp();
device.clock.now = TEST_NOW + 30 * HOUR;
await device.app.call("importSave", { code: await encodeSave(v8 as never) });
const imported = (await readSave(device.app)).company;
expect(imported.lastManualDecisionAt).toBe(TEST_NOW + 30 * HOUR);
expect(imported.sleepAfterHours).toBe(24);
});
});