Harden gameplay timing and map loading

This commit is contained in:
2026-10-05 15:15:35 +05:00
parent 8b31891776
commit dcc3779262
36 changed files with 1050 additions and 205 deletions

View File

@@ -0,0 +1,18 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { checkServiceError, ServiceError } from "../lib/service-error";
test("backend failures use 503 and keep database internals out of browser errors", (t) => {
t.mock.method(console, "error", () => {});
assert.throws(() => checkServiceError({ code: "42P01", message: 'relation "private_table" does not exist' }), (error) => {
assert.ok(error instanceof ServiceError);
assert.equal(error.status, 503);
assert.doesNotMatch(error.message, /private_table|42P01/);
return true;
});
});
test("missing records and expected RPC validation keep actionable statuses and messages", () => {
assert.throws(() => checkServiceError({ code: "PGRST116", message: "no rows" }), (error) => error instanceof ServiceError && error.status === 404);
assert.throws(() => checkServiceError({ code: "P0001", message: "Guess outside map" }), /Guess outside map/);
assert.doesNotThrow(() => checkServiceError(null));
});