feat(houseofrc): preview and send results to the event's entries, heats or final placings (1.83.0)

This commit is contained in:
larssand committed 2026-11-08 20:44:23 +01:00
1 parent f4a62b92d2
commit ebdc6104e6
17 files changed
+295 -15

No files matched your search

@@ -733,6 +733,20 @@ test("House of RC: the key is stored server-side only, never returned, and the t
const mock = createServer((req, res) => {
seen.push({ url: req.url, auth: req.headers.authorization });
const ok = req.headers.authorization === "Bearer hrc_test_secret_key_1234";
if (ok && req.method === "POST" && req.url === "/v1/timing/events/2251/entries") {
let raw = "";
req.on("data", (chunk) => { raw += chunk; });
req.on("end", () => {
const body = JSON.parse(raw);
seen.at(-1).body = body;
const bad = body.entries.filter((entry) => entry.id !== 98765);
res.writeHead(bad.length ? 422 : 200, { "Content-Type": "application/json" });
res.end(JSON.stringify(bad.length
? { message: "The given data was invalid.", errors: { "entries.0.id": ["Not an entry of this event."] } }
: { data: { updated: 1, entries: [{ id: 98765, ranking: body.entries[0].ranking ?? null, user_id: 68 }] } }));
});
return;
}
const forbidden = ok && req.url === "/v1/timing/events/3001/entries";
const missing = ok && req.url.startsWith("/v1/timing/events/") && !forbidden && req.url !== "/v1/timing/events/2251/entries";
res.writeHead(!ok ? 401 : forbidden ? 403 : missing ? 404 : 200, { "Content-Type": "application/json" });
@@ -810,6 +824,16 @@ test("House of RC: the key is stored server-side only, never returned, and the t
assert.equal((await (await post("/api/houseofrc/entries", { eventId: "999" })).json()).error, "event_not_found");
assert.equal((await (await post("/api/houseofrc/entries", { eventId: "3001" })).json()).error, "not_your_event");
const sent = await post("/api/houseofrc/results", { eventId: 2251, entries: [{ id: 98765, ranking: 1, qualification: 2, tq: false, laps_time: "22/5:03.412", data: { result: { main: "A", main_position: 1 } }, name: "dropped" }] });
assert.equal(sent.status, 200);
assert.deepEqual(await sent.json(), { ok: true, status: 200, updated: 1, entries: [{ id: 98765, ranking: 1 }] });
assert.equal(seen.at(-1).auth, "Bearer hrc_test_secret_key_1234");
assert.deepEqual(Object.keys(seen.at(-1).body.entries[0]), ["id", "ranking", "qualification", "tq", "laps_time", "data"], "only result fields go out");
const refused = await (await post("/api/houseofrc/results", { eventId: 2251, entries: [{ id: 111, ranking: 1 }] })).json();
assert.equal(refused.error, "rejected");
assert.deepEqual(refused.errors, { "entries.0.id": ["Not an entry of this event."] });
assert.equal((await post("/api/houseofrc/results", { eventId: 2251, entries: [] })).status, 400);
const keyFile = join(dataDir, "houseofrc.json");
assert.equal(statSync(keyFile).mode & 0o777, 0o600, "only the server user can read the key file");
for (const path of ["/api/houseofrc/status", "/api/state"]) {