feat(houseofrc): send heats automatically after every heat, show send status, warn before sending (1.85.0)
This commit is contained in:
1 parent
38cfa7ff2d
commit
3870510d8c
15 files changed
+189
-18
No files matched your search
@@ -70,7 +70,7 @@ export async function runHouseOfRcSmoke({ evaluate, navigate, savedState, waitFo
|
||||
export async function runHouseOfRcEventSmoke({ evaluate, navigate, savedState, waitFor, base }) {
|
||||
try {
|
||||
await navigate("race_setup", "raceWizardStepForm");
|
||||
await evaluate(`(() => {
|
||||
const installMock = `(() => {
|
||||
const realFetch = window.fetch;
|
||||
window.fetch = async (url, options) => {
|
||||
const json = (data) => new Response(JSON.stringify(data), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
@@ -89,7 +89,8 @@ export async function runHouseOfRcEventSmoke({ evaluate, navigate, savedState, w
|
||||
}
|
||||
return realFetch(url, options);
|
||||
};
|
||||
})()`);
|
||||
})()`;
|
||||
await evaluate(installMock);
|
||||
await evaluate(`document.getElementById("raceWizardHouseOfRc").click()`);
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector("[data-hor-event]"))`), "the event list");
|
||||
await evaluate(`document.querySelector('[data-hor-event="2251"]').click()`);
|
||||
@@ -154,9 +155,26 @@ export async function runHouseOfRcEventSmoke({ evaluate, navigate, savedState, w
|
||||
assert.equal(posted.eventId, 2251);
|
||||
assert.deepEqual(posted.entries.map((entry) => entry.id).sort(), [11, 16]);
|
||||
assert.ok(posted.entries.every((entry) => !("ranking" in entry)), "no placing sent before the finals");
|
||||
await waitFor(async () => Boolean((await savedState()).events.find((item) => item.houseOfRc?.eventId === 2251)?.houseOfRc.resultsSentAt), "when it was sent is saved");
|
||||
await waitFor(async () => Boolean((await savedState()).events.find((item) => item.houseOfRc?.eventId === 2251)?.houseOfRc.lastSend?.ok), "how it was sent is saved");
|
||||
await evaluate(`document.getElementById("houseOfRcResultsOverlay")?.remove()`);
|
||||
console.log("PASS House of RC results: preview in Manage, heats sent to the race's entries without placings");
|
||||
|
||||
// "Send heats automatically": a qualifying heat finishes, the race controller sends it.
|
||||
await evaluate(`document.getElementById("houseOfRcAutoSend").click()`);
|
||||
await waitFor(async () => (await savedState()).events.find((item) => item.houseOfRc?.eventId === 2251)?.houseOfRc.autoSend === true, "auto-send saved");
|
||||
{
|
||||
const saved = await savedState();
|
||||
const race = saved.events.find((item) => item.houseOfRc?.eventId === 2251);
|
||||
const heat = saved.sessions.find((session) => session.eventId === race.id && session.type === "qualification");
|
||||
Object.assign(heat, { status: "finished", startedAt: Date.now() - 400000, endedAt: Date.now() - 100000 });
|
||||
await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(saved) });
|
||||
}
|
||||
await navigate("race_day", "raceDaySessionSelect");
|
||||
await evaluate(installMock);
|
||||
await waitFor(async () => evaluate(`Boolean(window.__horPosted)`), "sent by itself after the heat", 30000);
|
||||
assert.ok((await evaluate(`window.__horPosted.entries`)).every((entry) => !("ranking" in entry)), "automatic sending never sends placings");
|
||||
await waitFor(async () => (await savedState()).events.find((item) => item.houseOfRc?.eventId === 2251)?.houseOfRc.lastSend?.signature, "the send is remembered");
|
||||
console.log("PASS House of RC auto-send: a finished heat is sent by the race controller without placings");
|
||||
} finally {
|
||||
await evaluate(`document.getElementById("houseOfRcEventOverlay")?.remove()`).catch(() => {});
|
||||
const current = await savedState();
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
Reference in new issue
Block a user