v1.0.0: players table + migration from singleton account (ISS-105)
CI / build + unit + e2e (pull_request) Successful in 14m25s
CI / build + unit + e2e (pull_request) Successful in 14m25s
This commit is contained in:
@@ -62,43 +62,43 @@ describe('admin rows CRUD', () => {
|
||||
adminSession = await createSession(await getGameDb(), 'admin-kamilkrzywda');
|
||||
});
|
||||
|
||||
it('GET returns columns + rows with __rowid for the PK-less account table', async () => {
|
||||
const res = await getRows('account');
|
||||
it('GET returns columns + rows with __rowid for the PK-less sim_state table', async () => {
|
||||
const res = await getRows('sim_state');
|
||||
expect(res.status).toBe(200);
|
||||
const body = (await res.json()) as { columns: string[]; rows: Array<Record<string, unknown>> };
|
||||
expect(body.columns[0]).toBe('__rowid');
|
||||
for (const col of ['cash', 'reputation']) expect(body.columns).toContain(col);
|
||||
expect(body.rows).toHaveLength(1); // the single seeded account row
|
||||
for (const col of ['clock_ms', 'time_scale']) expect(body.columns).toContain(col);
|
||||
expect(body.rows).toHaveLength(1); // the single seeded sim_state row
|
||||
expect(typeof body.rows[0].__rowid).toBe('number');
|
||||
expect(typeof body.rows[0].cash).toBe('number');
|
||||
expect(typeof body.rows[0].clock_ms).toBe('number');
|
||||
});
|
||||
|
||||
it('PUT updates a cell and the change survives a re-fetch', async () => {
|
||||
const before = await (await getRows('account')).json();
|
||||
const originalCash = (before as { rows: Array<Record<string, unknown>> }).rows[0].cash;
|
||||
const before = await (await getRows('sim_state')).json();
|
||||
const originalClockMs = (before as { rows: Array<Record<string, unknown>> }).rows[0].clock_ms;
|
||||
|
||||
const res = await putRow('account', { rowid: 1, values: { cash: 424_242 } });
|
||||
const res = await putRow('sim_state', { rowid: 1, values: { clock_ms: 424_242 } });
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({ ok: true });
|
||||
|
||||
// Re-fetch through the same route — the persisted value is back.
|
||||
const body = await (await getRows('account')).json();
|
||||
expect((body as { rows: Array<Record<string, unknown>> }).rows[0].cash).toBe(424_242);
|
||||
const body = await (await getRows('sim_state')).json();
|
||||
expect((body as { rows: Array<Record<string, unknown>> }).rows[0].clock_ms).toBe(424_242);
|
||||
|
||||
// Restore the original cash so later tests see a sane world.
|
||||
const restore = await putRow('account', { rowid: 1, values: { cash: originalCash } });
|
||||
// Restore the original clock so later tests see a sane world.
|
||||
const restore = await putRow('sim_state', { rowid: 1, values: { clock_ms: originalClockMs } });
|
||||
expect(restore.status).toBe(200);
|
||||
});
|
||||
|
||||
it('PUT rejects unknown columns and empty values with 400', async () => {
|
||||
const badCol = await putRow('account', { rowid: 1, values: { no_such_column: 1 } });
|
||||
const badCol = await putRow('sim_state', { rowid: 1, values: { no_such_column: 1 } });
|
||||
expect(badCol.status).toBe(400);
|
||||
expect(((await badCol.json()) as { error: string }).error).toMatch(/unknown column/i);
|
||||
|
||||
const empty = await putRow('account', { rowid: 1, values: {} });
|
||||
const empty = await putRow('sim_state', { rowid: 1, values: {} });
|
||||
expect(empty.status).toBe(400);
|
||||
|
||||
const noRowid = await putRow('account', { values: { cash: 1 } });
|
||||
const noRowid = await putRow('sim_state', { values: { clock_ms: 1 } });
|
||||
expect(noRowid.status).toBe(400);
|
||||
});
|
||||
|
||||
|
||||
@@ -74,8 +74,8 @@ function sqlError(err: unknown): Response {
|
||||
}
|
||||
|
||||
// GET /api/admin/tables/{name}/rows?limit=500 — column headers + up to `limit` rows (default
|
||||
// 500, cap 1000). rowid is exposed as __rowid so the PK-less tables (account, sim_state) are
|
||||
// editable like any other. Unknown table → 404; bad limit → 400.
|
||||
// 500, cap 1000). rowid is exposed as __rowid so the PK-less tables (sim_state) are editable
|
||||
// like any other. Unknown table → 404; bad limit → 400.
|
||||
export async function GET(req: Request, ctx: { params: Promise<{ name: string }> }) {
|
||||
const guard = await requireAdmin(req);
|
||||
if (!guard.ok) return guard.response;
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('GET /api/admin/tables', () => {
|
||||
expect(res.status).toBe(200);
|
||||
const names = ((await res.json()) as Array<{ name: string }>).map((t) => t.name);
|
||||
|
||||
for (const expected of ['account', 'packages', 'planes', 'sessions', 'sim_state', 'users']) {
|
||||
for (const expected of ['packages', 'players', 'planes', 'sessions', 'sim_state', 'users']) {
|
||||
expect(names, `missing ${expected}`).toContain(expected);
|
||||
}
|
||||
expect(names.some((n) => n.startsWith('sqlite_'))).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user