v1.2.0: planes.owner_id + ownership checks + per-player onboarding (ISS-108, ISS-109)
CI / build + unit + e2e (pull_request) Successful in 13m46s
CI / build + unit + e2e (pull_request) Successful in 13m46s
This commit is contained in:
@@ -36,32 +36,52 @@ describe('POST /api/test/mint-player-session', () => {
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
|
||||
it('creates the default test account + player row and mints a session when enabled', async () => {
|
||||
it('mints a session for the seeded local player by default (v1.2.0: e2e plays with backfilled planes)', async () => {
|
||||
vi.stubEnv('FLIGHT_TEST_HOOKS', '1');
|
||||
const res = await post(); // no body → DEFAULT_USERNAME
|
||||
const res = await post(); // no body → DEFAULT_USERNAME 'kamilkrzywda'
|
||||
expect(res.status).toBe(200);
|
||||
const body = (await res.json()) as { sessionId: string };
|
||||
expect(body.sessionId).toMatch(/^[0-9a-f-]{36}$/);
|
||||
|
||||
const inst = await getGameDb();
|
||||
// The session resolves to the EXISTING admin user — no new users/players rows are created.
|
||||
const sess = inst.raw.exec('SELECT user_id FROM sessions WHERE id = ?', [body.sessionId])[0].values[0];
|
||||
expect(String(sess[0])).toBe('admin-kamilkrzywda');
|
||||
expect(Number(inst.raw.exec('SELECT COUNT(*) FROM users')[0].values[0][0])).toBe(1);
|
||||
expect(Number(inst.raw.exec('SELECT COUNT(*) FROM players')[0].values[0][0])).toBe(1);
|
||||
});
|
||||
|
||||
it('creates a fresh test account WITH onboarding (starter plane at EDDF) for a custom username', async () => {
|
||||
vi.stubEnv('FLIGHT_TEST_HOOKS', '1');
|
||||
const res = await post({ username: 'e2e-tester' });
|
||||
expect(res.status).toBe(200);
|
||||
const body = (await res.json()) as { sessionId: string };
|
||||
|
||||
const inst = await getGameDb();
|
||||
const userRow = inst.raw.exec("SELECT id FROM users WHERE username = 'e2e-tester'")[0].values[0];
|
||||
expect(userRow.length).toBe(1);
|
||||
const playerRow = inst.raw.exec("SELECT id, cash FROM players WHERE username = 'e2e-tester'")[0].values[0];
|
||||
expect(String(playerRow[0])).toBe(String(userRow[0])); // one UUID for both rows
|
||||
|
||||
// v1.2.0 (ISS-108): the new test player gets a starter plane at EDDF owned by them.
|
||||
const planes = inst.raw.exec('SELECT id, owner_id, location_icao FROM planes WHERE owner_id = ?', [String(userRow[0])])[0].values;
|
||||
expect(planes).toHaveLength(1);
|
||||
expect(String(planes[0][2])).toBe('EDDF');
|
||||
|
||||
// The minted session resolves to the new user.
|
||||
const sess = inst.raw.exec('SELECT user_id FROM sessions WHERE id = ?', [body.sessionId])[0].values[0];
|
||||
expect(String(sess[0])).toBe(String(userRow[0]));
|
||||
});
|
||||
|
||||
it('is idempotent — re-minting an existing username mints another session, no duplicate rows', async () => {
|
||||
it('is idempotent — re-minting an existing username mints another session, no duplicate rows or planes', async () => {
|
||||
vi.stubEnv('FLIGHT_TEST_HOOKS', '1');
|
||||
const count = async () => Number((await getGameDb()).raw.exec("SELECT COUNT(*) FROM users WHERE username = 'e2e-tester'")[0].values[0][0]);
|
||||
expect(await count()).toBe(1);
|
||||
const count = async (sql: string) => Number((await getGameDb()).raw.exec(sql)[0].values[0][0]);
|
||||
expect(await count("SELECT COUNT(*) FROM users WHERE username = 'e2e-tester'")).toBe(1);
|
||||
|
||||
const res = await post();
|
||||
const res = await post({ username: 'e2e-tester' });
|
||||
expect(res.status).toBe(200);
|
||||
expect(await count()).toBe(1); // still one account…
|
||||
expect(await count("SELECT COUNT(*) FROM users WHERE username = 'e2e-tester'")).toBe(1); // still one account…
|
||||
expect(await count("SELECT COUNT(*) FROM planes p JOIN players pl ON p.owner_id = pl.id WHERE pl.username = 'e2e-tester'")).toBe(1); // …and exactly one onboarding plane
|
||||
});
|
||||
|
||||
it('rejects bad usernames and unknown fields with 400', async () => {
|
||||
|
||||
Reference in New Issue
Block a user