fix: phase 1 bugs — CSS tokens, pluralization, error handling, cross-platform tests
Some checks failed
CI / build-and-test (pull_request) Has been cancelled
Some checks failed
CI / build-and-test (pull_request) Has been cancelled
- Add missing --space-1 CSS token used by filter and detail components - Fix active nav link losing styles on hover (CSS specificity) - Correct Russian day pluralization (21 день, 22 дня, 25 дней) - Show filter error banner even when stale race data is present - Add cross-env for Windows-compatible npm test - Add global JSON error handler in Express for malformed request bodies - Replace stateless mock DB with in-memory store for correct DELETE/UPDATE behavior Made-with: Cursor
This commit is contained in:
@@ -69,6 +69,8 @@ function createMockPool(): Pool {
|
||||
fields: [],
|
||||
}) as QueryResult<T>;
|
||||
|
||||
const store = new Map<string, RaceRow>();
|
||||
|
||||
const mockQuery = async <T extends QueryResultRow>(
|
||||
text: string,
|
||||
params?: unknown[],
|
||||
@@ -76,11 +78,9 @@ function createMockPool(): Pool {
|
||||
const sql = text.replace(/\s+/g, " ").trim();
|
||||
const p = params ?? [];
|
||||
|
||||
if (sql.includes("DELETE FROM races")) {
|
||||
return emptyResult();
|
||||
}
|
||||
if (sql.includes("INSERT INTO races") && sql.includes("RETURNING")) {
|
||||
const row = mockRowFromInsert(text, p);
|
||||
store.set(row.id, row);
|
||||
return {
|
||||
rows: [row as unknown as T],
|
||||
rowCount: 1,
|
||||
@@ -89,12 +89,49 @@ function createMockPool(): Pool {
|
||||
fields: [],
|
||||
} as QueryResult<T>;
|
||||
}
|
||||
|
||||
if (sql.includes("DELETE FROM races")) {
|
||||
const id = String(p[0] ?? "");
|
||||
const existed = store.delete(id);
|
||||
return {
|
||||
rows: [],
|
||||
rowCount: existed ? 1 : 0,
|
||||
command: "DELETE",
|
||||
oid: 0,
|
||||
fields: [],
|
||||
} as QueryResult<T>;
|
||||
}
|
||||
|
||||
if (sql.includes("UPDATE races") && sql.includes("RETURNING")) {
|
||||
return emptyResult();
|
||||
const id = String(p[p.length - 1] ?? "");
|
||||
const existing = store.get(id);
|
||||
if (!existing) {
|
||||
return emptyResult();
|
||||
}
|
||||
const updated = { ...existing, updated_at: new Date().toISOString() };
|
||||
store.set(id, updated);
|
||||
return {
|
||||
rows: [updated as unknown as T],
|
||||
rowCount: 1,
|
||||
command: "UPDATE",
|
||||
oid: 0,
|
||||
fields: [],
|
||||
} as QueryResult<T>;
|
||||
}
|
||||
|
||||
if (sql.includes("SELECT * FROM races WHERE id =")) {
|
||||
const id = String(p[0] ?? "");
|
||||
const row = store.get(id);
|
||||
return row
|
||||
? { rows: [row as unknown as T], rowCount: 1, command: "SELECT", oid: 0, fields: [] } as QueryResult<T>
|
||||
: emptyResult();
|
||||
}
|
||||
|
||||
if (sql.includes("SELECT * FROM races")) {
|
||||
return emptyResult();
|
||||
const rows = Array.from(store.values());
|
||||
return { rows: rows as unknown as T[], rowCount: rows.length, command: "SELECT", oid: 0, fields: [] } as QueryResult<T>;
|
||||
}
|
||||
|
||||
return emptyResult();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user