53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
// Ported from apps/server/test (CR-014 Step 14.5): now runs on the engine.
|
|
import { acknowledgeSummariesResponseSchema } from "@deadhead/schema";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
useTestApp,
|
|
signUp,
|
|
call,
|
|
getState,
|
|
setCredits,
|
|
insertDispatch,
|
|
makeOwner,
|
|
} from "../support";
|
|
|
|
const testApp = useTestApp();
|
|
|
|
describe("acknowledging summaries", () => {
|
|
it("clears unacknowledged summaries while keeping the resolved effects", async () => {
|
|
const { app, clock } = testApp();
|
|
const guest = await signUp(app);
|
|
const { shipId } = await makeOwner(testApp().app, guest.avatarId);
|
|
await setCredits(testApp().app, 1000);
|
|
const record = await insertDispatch(testApp().app, {
|
|
shipId,
|
|
pilotId: guest.avatarId,
|
|
departAt: clock.now,
|
|
});
|
|
clock.now = record.arrivalAt;
|
|
|
|
const before = await getState(app, guest);
|
|
expect(before.summaries.map((s) => s.dispatchId)).toEqual([record.id]);
|
|
|
|
const response = await call(app, guest, "POST", "/api/summaries/acknowledge", {
|
|
dispatchIds: [record.id, "not-a-real-dispatch"],
|
|
});
|
|
expect(response.statusCode).toBe(200);
|
|
expect(acknowledgeSummariesResponseSchema.parse(response.json())).toEqual({ acknowledged: 1 });
|
|
|
|
const after = await getState(app, guest);
|
|
expect(after.summaries).toEqual([]);
|
|
expect(after.company.credits).toBe(before.company.credits);
|
|
expect(after.pilots[0]!.xp).toBe(before.pilots[0]!.xp);
|
|
expect(after.ships[0]!.locationId).toBe("moon");
|
|
|
|
// Acknowledging again changes nothing.
|
|
const again = await call(app, guest, "POST", "/api/summaries/acknowledge", {
|
|
dispatchIds: [record.id],
|
|
});
|
|
expect(again.json()).toEqual({ acknowledged: 0 });
|
|
});
|
|
|
|
// "Does not acknowledge another player's dispatches" no longer applies: one company per save (CR-014).
|
|
});
|