74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
// Ported from apps/server/test (CR-014 Step 14.5): guest sign-up is now
|
|
// "Start your company" on the device; session and cookie tests no longer apply.
|
|
import { content } from "@deadhead/content";
|
|
import {
|
|
createGuestResponseSchema,
|
|
errorResponseSchema,
|
|
playerStateSchema,
|
|
} from "@deadhead/schema";
|
|
import { describe, expect, it } from "vitest";
|
|
import { newTestApp, useTestApp, call } from "../support";
|
|
|
|
const testApp = useTestApp();
|
|
|
|
describe("starting a company (was guest accounts)", () => {
|
|
it("creates a new tutorial company", async () => {
|
|
const response = await call(testApp().app, null, "POST", "/api/guest");
|
|
expect(response.statusCode).toBe(200);
|
|
const body = createGuestResponseSchema.parse(response.json());
|
|
expect(body.state.company.credits).toBe(content.config.startingCredits);
|
|
expect(body.state.tutorial).toMatchObject({ loanerLocationId: "earth", runInFlight: false });
|
|
});
|
|
|
|
it("returns the new company's state afterwards", async () => {
|
|
await call(testApp().app, null, "POST", "/api/guest");
|
|
const response = await call(testApp().app, null, "GET", "/api/state");
|
|
expect(response.statusCode).toBe(200);
|
|
const state = playerStateSchema.parse(response.json());
|
|
|
|
expect(state.company.credits).toBe(content.config.startingCredits);
|
|
expect(
|
|
state.locations
|
|
.filter((l) => l.discovered)
|
|
.map((l) => l.id)
|
|
.sort(),
|
|
).toEqual(["earth", "moon"]);
|
|
expect(state.pilots).toHaveLength(1);
|
|
expect(state.pilots[0]).toMatchObject({
|
|
isAvatar: true,
|
|
level: 0,
|
|
xp: 0,
|
|
locationId: "earth",
|
|
status: "idle",
|
|
});
|
|
expect(state.ships).toHaveLength(0);
|
|
expect(state.tutorial).not.toBeNull();
|
|
});
|
|
|
|
it("gives each device its own company", async () => {
|
|
const a = createGuestResponseSchema.parse(
|
|
(await call(newTestApp().app, null, "POST", "/api/guest")).json(),
|
|
);
|
|
const b = createGuestResponseSchema.parse(
|
|
(await call(newTestApp().app, null, "POST", "/api/guest")).json(),
|
|
);
|
|
expect(a.playerId).not.toBe(b.playerId);
|
|
});
|
|
|
|
it("keeps the same company if started again", async () => {
|
|
const first = createGuestResponseSchema.parse(
|
|
(await call(testApp().app, null, "POST", "/api/guest")).json(),
|
|
);
|
|
const again = createGuestResponseSchema.parse(
|
|
(await call(testApp().app, null, "POST", "/api/guest")).json(),
|
|
);
|
|
expect(again.playerId).toBe(first.playerId);
|
|
});
|
|
|
|
it("has no state before a company exists", async () => {
|
|
const response = await call(testApp().app, null, "GET", "/api/state");
|
|
expect(response.statusCode).toBe(401);
|
|
expect(errorResponseSchema.parse(response.json()).error.code).toBe("unauthorized");
|
|
});
|
|
});
|