feat(houseofrc): send heats automatically after every heat, show send status, warn before sending (1.85.0)

This commit is contained in:
larssand committed 2026-11-08 23:19:43 +01:00
1 parent 38cfa7ff2d
commit 3870510d8c
15 files changed
+189 -18

No files matched your search

+28
View File
@@ -146,3 +146,31 @@ test("House of RC results: heats and qualifying without placings, then final pla
const noQual = buildHouseOfRcResults(event, { phases: [] }, { drivers });
assert.ok(!("qualification" in noQual.entries[0]), "before any qualifying, House of RC's value is left alone");
});
test("House of RC auto-send: due after a finished heat, once per change, retried a minute after a failure", async () => {
const { findHouseOfRcAutoSends, houseOfRcResultsSignature, checkHouseOfRcResults, HOUSE_OF_RC_RETRY_MS } = await import("../src/houseofrc_logic.js");
const event = { id: "e", houseOfRc: { eventId: 9, autoSend: true } };
const sessions = [
{ id: "p", eventId: "e", type: "practice", status: "finished", endedAt: 1 },
{ id: "q1", eventId: "e", type: "qualification", status: "ready" },
{ id: "f1", eventId: "e", type: "final", status: "ready", name: "A final 1" },
];
const state = { events: [event, { id: "off", houseOfRc: { eventId: 8 } }], sessions };
assert.deepEqual(findHouseOfRcAutoSends(state), [], "practice alone is not sent");
sessions[1].status = "finished"; sessions[1].endedAt = 100;
assert.deepEqual(findHouseOfRcAutoSends(state).map((item) => item.id), ["e"]);
const now = Date.parse("2026-11-08T20:00:00Z");
event.houseOfRc.lastSend = { ok: false, at: new Date(now - 10000).toISOString(), signature: "" };
assert.deepEqual(findHouseOfRcAutoSends(state, now), [], "failed 10 s ago: wait");
assert.deepEqual(findHouseOfRcAutoSends(state, now + HOUSE_OF_RC_RETRY_MS).map((item) => item.id), ["e"], "then try again");
event.houseOfRc.lastSend = { ok: true, at: new Date(now).toISOString(), signature: houseOfRcResultsSignature(event, sessions), final: false };
assert.deepEqual(findHouseOfRcAutoSends(state, now), [], "sent: nothing new");
assert.deepEqual(checkHouseOfRcResults(event, null, { final: false, sessions }).map((item) => item.key), ["unchanged"]);
const finalWarnings = checkHouseOfRcResults(event, null, { final: true, sessions, missing: ["Walk In"] });
assert.deepEqual(finalWarnings.map((item) => item.key), ["finals_left", "missing"]);
assert.equal(finalWarnings[0].params.names, "A final 1");
sessions[2].status = "running";
assert.equal(checkHouseOfRcResults(event, null, { sessions })[0].key, "running");
sessions[2].status = "finished"; sessions[2].endedAt = 200;
assert.deepEqual(findHouseOfRcAutoSends(state, now).map((item) => item.id), ["e"], "a new heat finished: due again");
});