Harden gameplay timing and map loading
This commit is contained in:
18
tests/service-error.test.ts
Normal file
18
tests/service-error.test.ts
Normal 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));
|
||||
});
|
||||
Reference in New Issue
Block a user