feat(houseofrc): fetch club events, classes and entries with transponders via the timing API (1.81.0)

This commit is contained in:
larssand committed 2026-11-08 15:53:57 +01:00
1 parent 9c1f5713e6
commit b0f2b92c04
15 files changed
+247 -149

No files matched your search

+17 -12
View File
@@ -74,12 +74,15 @@ export async function runHouseOfRcEventSmoke({ evaluate, navigate, savedState, w
const realFetch = window.fetch;
window.fetch = async (url, options) => {
const json = (data) => new Response(JSON.stringify(data), { status: 200, headers: { "Content-Type": "application/json" } });
if (String(url).includes("/api/houseofrc/events")) return json({ ok: true, events: [{ id: 2251, name: "HoR Deltävling 2", start: "2026-12-05T07:00:00Z", city: "Sundsvall", country: "SE", url: "https://houseofrc.com/events/2251" }] });
if (String(url).includes("/api/houseofrc/entries")) return json({ ok: true, event: { id: 2251, name: "HoR Deltävling 2", start: "2026-12-05T07:00:00Z", city: "Sundsvall", url: "https://houseofrc.com/events/2251" }, entries: [
{ houseOfRcId: 901, name: "HoR Anna", number: 7, club: "Sundsvall RC", car: "XRAY X12" },
{ houseOfRcId: 902, name: "HoR Bo", number: null, club: "", car: "" },
{ houseOfRcId: 903, name: "HoR Skipped", number: null, club: "", car: "" },
] });
if (String(url).includes("/api/houseofrc/events")) return json({ ok: true, organizationId: 233, events: [{ id: 2251, name: "HoR Deltävling 2", start: "2026-12-05T07:00:00Z", city: "Sundsvall", country: "SE", url: "https://houseofrc.com/events/2251" }] });
if (String(url).includes("/api/houseofrc/entries")) return json({ ok: true, event: { id: 2251, name: "HoR Deltävling 2", start: "2026-12-05T07:00:00Z", city: "Sundsvall", url: "https://houseofrc.com/events/2251" },
classes: [{ id: 555, name: "HoR 2wd" }, { id: 556, name: "HoR 4wd" }],
entries: [
{ entryId: 11, classId: 555, houseOfRcId: 901, name: "HoR Anna", number: 7, transponders: ["7710001"], club: "Sundsvall RC", car: "XRAY X12" },
{ entryId: 12, classId: 555, houseOfRcId: 902, name: "HoR Bo", number: null, transponders: [], club: "", car: "" },
{ entryId: 13, classId: 555, houseOfRcId: 903, name: "HoR Skipped", number: null, transponders: [], club: "", car: "" },
{ entryId: 14, classId: 556, houseOfRcId: 904, name: "HoR Other Class", number: null, transponders: [], club: "", car: "" },
] });
return realFetch(url, options);
};
})()`);
@@ -88,7 +91,8 @@ export async function runHouseOfRcEventSmoke({ evaluate, navigate, savedState, w
await evaluate(`document.querySelector('[data-hor-event="2251"]').click()`);
await waitFor(async () => evaluate(`Boolean(document.querySelector("[data-hor-apply]"))`), "the entries");
const statuses = await evaluate(`[...document.querySelectorAll("#houseOfRcEventOverlay tbody .pill")].map((pill) => pill.textContent.trim())`);
assert.equal(statuses.length, 3);
assert.equal(statuses.length, 3, "only the chosen House of RC class");
assert.equal(await evaluate(`document.querySelector("[data-hor-class]").value`), "__new__", "no class with that name: offered as a new class");
await evaluate(`(() => {
const select = document.querySelector("[data-hor-class]");
select.value = "test_class"; select.dispatchEvent(new Event("change", { bubbles: true }));
@@ -97,7 +101,7 @@ export async function runHouseOfRcEventSmoke({ evaluate, navigate, savedState, w
await waitFor(async () => (await savedState()).drivers.some((driver) => driver.name === "HoR Anna"), "new drivers saved");
const drivers = (await savedState()).drivers;
const anna = drivers.find((driver) => driver.name === "HoR Anna");
assert.deepEqual([anna.classId, anna.club, anna.brand, anna.houseOfRcId], ["test_class", "Sundsvall RC", "XRAY X12", "901"]);
assert.deepEqual([anna.classId, anna.club, anna.brand, anna.houseOfRcId, anna.transponder], ["test_class", "Sundsvall RC", "XRAY X12", "901", "7710001"], "the entry's transponder comes along");
assert.equal(drivers.some((driver) => driver.name === "HoR Skipped"), false, "an unticked entry is not created");
const ticked = await evaluate(`[...document.querySelectorAll(".wizard-participant:checked")].map((box) => box.value)`);
const ids = drivers.filter((driver) => ["HoR Anna", "HoR Bo"].includes(driver.name)).map((driver) => driver.id);
@@ -105,15 +109,16 @@ export async function runHouseOfRcEventSmoke({ evaluate, navigate, savedState, w
await evaluate(`document.getElementById("raceWizardNext").click()`);
await evaluate(`document.getElementById("raceWizardNext").click()`);
await evaluate(`document.getElementById("raceWizardCreate").click()`);
await waitFor(async () => (await savedState()).events.some((event) => event.name === "HoR Deltävling 2"), "the race is created");
const event = (await savedState()).events.find((item) => item.name === "HoR Deltävling 2");
assert.deepEqual([event.date, event.classId, event.houseOfRc?.eventId], ["2026-12-05", "test_class", 2251]);
await waitFor(async () => (await savedState()).events.some((event) => event.houseOfRc?.eventId === 2251), "the race is created");
const event = (await savedState()).events.find((item) => item.houseOfRc?.eventId === 2251);
assert.deepEqual([event.date, event.classId, event.houseOfRc?.eventId, event.houseOfRc?.classId], ["2026-12-05", "test_class", 2251, 555]);
assert.deepEqual(Object.values(event.houseOfRc.entryIds).sort(), [11, 12], "each driver's House of RC entry, for the results");
assert.deepEqual([...event.raceConfig.driverIds].sort(), [...ids].sort());
console.log("PASS House of RC event import: pick an event and class, entered drivers fill the race wizard, the race keeps the House of RC event id");
} finally {
await evaluate(`document.getElementById("houseOfRcEventOverlay")?.remove()`).catch(() => {});
const current = await savedState();
const eventIds = current.events.filter((event) => event.name === "HoR Deltävling 2").map((event) => event.id);
const eventIds = current.events.filter((event) => event.houseOfRc?.eventId === 2251).map((event) => event.id);
Object.assign(current, {
drivers: current.drivers.filter((driver) => !String(driver.name).startsWith("HoR ")),
events: current.events.filter((event) => !eventIds.includes(event.id)),