feat(houseofrc): create a race from a House of RC event and its entries (1.80.0)

This commit is contained in:
larssand committed 2026-11-08 11:52:57 +01:00
1 parent 42df6a786f
commit 9c1f5713e6
18 files changed
+444 -21

No files matched your search

+32 -4
View File
@@ -6,22 +6,25 @@ const members = {
"1001": { id: 68, name: "Anna Andersson", brand: "Associated", model: "B7" },
"1002": { id: 70, name: "Bo Berg", brand: "Xray", model: "XB4" },
"1003": { id: 71, name: "Cecilia Carlsson", brand: "", model: "" },
"1004": { id: 68, name: "Anders Larsson", brand: "", model: "Xray XB4 2025" },
};
const drivers = () => [
{ id: "a", name: "1001", transponder: "1001", brand: "" },
{ id: "b", name: "Bosse", transponder: "1002", brand: "Team Berg" },
{ id: "c", name: "cecilia carlsson", transponder: "1003", brand: "" },
{ id: "d", name: "Dan", transponder: "9999", brand: "" },
{ id: "e", name: "anders larsson", transponder: "1004", brand: "" },
{ id: "g", name: "", transponder: "1001", brand: "", guestEventId: "e1" },
];
test("House of RC plan: only matched drivers, pre-ticked only where our field is empty or just the transponder number", () => {
const plan = planHouseOfRcDriverUpdates(drivers(), members);
assert.deepEqual(plan.map((row) => row.driverId), ["a", "b", "c"], "unknown transponders and sponsor guests are left out");
const [a, b, c] = plan;
assert.deepEqual(plan.map((row) => row.driverId), ["a", "b", "c", "e"], "unknown transponders and sponsor guests are left out");
const [a, b, c, e] = plan;
assert.deepEqual([a.nameDiffers, a.nameDefault, a.brandDiffers, a.brandDefault], [true, true, true, true]);
assert.deepEqual([b.nameDiffers, b.nameDefault, b.brandDiffers, b.brandDefault], [true, false, true, false], "an existing name or brand is never pre-ticked");
assert.deepEqual([c.nameDiffers, c.brandDiffers], [false, false], "same name ignoring case and spaces; no brand from HoR");
assert.deepEqual([c.nameDiffers, c.nameDefault, c.brandDiffers], [true, true, false], "only case/spacing differs: offered and pre-ticked; no brand from HoR");
assert.deepEqual([e.nameDefault, e.brandDefault, e.member.brand], [true, true, "Xray XB4 2025"], "no brand object: the model name is the make");
});
test("House of RC apply: writes only the ticked fields and links drivers whose name matches", () => {
@@ -32,5 +35,30 @@ test("House of RC apply: writes only the ticked fields and links drivers whose n
assert.deepEqual([byId.b.name, byId.b.brand, byId.b.houseOfRcId], ["Bosse", "Xray", undefined], "name kept, so not linked (could be a borrowed transponder)");
assert.deepEqual([byId.c.name, byId.c.houseOfRcId], ["cecilia carlsson", "71"], "same person: linked without renaming");
assert.equal(byId.g.name, "", "sponsor guests untouched");
assert.equal(changed, 3);
assert.equal(changed, 4, "c and e are linked by name even without ticks");
});
test("House of RC entries: linked, same name, other class and new drivers", async () => {
const { planHouseOfRcEntries, applyHouseOfRcEntries } = await import("../src/houseofrc_logic.js");
const register = [
{ id: "d1", name: "Anna Andersson", classId: "2wd", transponder: "111", houseOfRcId: "5" },
{ id: "d2", name: "Bo Berg", classId: "2wd", transponder: "222" },
{ id: "d3", name: "Cid Ceder", classId: "4wd", transponder: "333", houseOfRcId: "7", profileId: "p3", club: "ÖRC" },
];
const entries = [
{ houseOfRcId: 5, name: "Anna A.", club: "ÖRC", car: "Xray XB2" },
{ houseOfRcId: 6, name: "bo berg", club: "", car: "" },
{ houseOfRcId: 7, name: "Cid Ceder", club: "ÖRC", car: "Associated B7" },
{ houseOfRcId: 8, name: "Dan Ny", club: "Sundsvall RC", car: "Mugen MSB1" },
];
const plan = planHouseOfRcEntries(entries, register, "2wd");
assert.deepEqual(plan.map((row) => row.status), ["linked", "name", "copy", "new"]);
let n = 0;
const ids = applyHouseOfRcEntries(register, plan, { classId: "2wd", selected: new Set([0, 1, 2, 3]), makeDriver: (fields) => ({ id: `new${++n}`, ...fields }) });
assert.deepEqual(ids, ["d1", "d2", "new1", "new2"], "existing drivers reused, the others created, in entry order");
assert.equal(register.find((d) => d.id === "d2").houseOfRcId, "6", "same name gets linked");
const cid = register.find((d) => d.id === "new1");
assert.deepEqual([cid.classId, cid.transponder, cid.profileId, cid.brand], ["2wd", "333", "p3", "Associated B7"], "other class: same person, profile and transponder, car from the entry");
const dan = register.find((d) => d.id === "new2");
assert.deepEqual([dan.name, dan.transponder, dan.club, dan.houseOfRcId], ["Dan Ny", "", "Sundsvall RC", "8"]);
});