feat(houseofrc): fetch driver names and brands by transponder (1.79.0)
This commit is contained in:
1 parent
0c54e8b58a
commit
3829ca1cab
17 files changed
+319
-7
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { planHouseOfRcDriverUpdates, applyHouseOfRcDriverUpdates } from "../src/houseofrc_logic.js";
|
||||
|
||||
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: "" },
|
||||
};
|
||||
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: "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([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");
|
||||
});
|
||||
|
||||
test("House of RC apply: writes only the ticked fields and links drivers whose name matches", () => {
|
||||
const list = drivers();
|
||||
const changed = applyHouseOfRcDriverUpdates(list, members, { a: { name: true, brand: true }, b: { name: false, brand: true } });
|
||||
const byId = Object.fromEntries(list.map((driver) => [driver.id, driver]));
|
||||
assert.deepEqual([byId.a.name, byId.a.brand, byId.a.houseOfRcId], ["Anna Andersson", "Associated", "68"]);
|
||||
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);
|
||||
});
|
||||
Reference in new issue
Block a user