Registering or editing a driver with a transponder already assigned to a different driver (e.g. a wrong-class typo) previously saved silently - the only symptom was that driver's laps never registering during their heat, with no indication why. Now a confirm dialog names the conflicting driver and their class before saving; the same person's own multiple class entries sharing one physical transponder are correctly never flagged. Also confirms two things the user asked to verify: the race clock already counts down for all timed session types (only open practice counts up unbounded), and a driver not entered in a heat already has their laps fully discarded rather than recorded - both were already correct, no changes needed there. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
39 lines
2.0 KiB
JavaScript
39 lines
2.0 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { findTransponderConflict } from "../src/driver_profile_logic.js";
|
|
|
|
// Regression coverage for a real scenario the user described: a driver registered with the
|
|
// wrong transponder number by mistake - one that's actually assigned to a completely
|
|
// different person (a driver in another class). Before this, nothing warned about it; the
|
|
// only symptom was that driver's laps silently never registering during their heat.
|
|
test("findTransponderConflict flags a transponder already used by a driver from a different profile", () => {
|
|
const drivers = [
|
|
{ id: "d1", name: "Erik Andersson", transponder: "1000001", profileId: "p1" },
|
|
{ id: "d2", name: "Marcus Dahl", transponder: "1000009", profileId: "p2" },
|
|
];
|
|
const conflict = findTransponderConflict(drivers, { transponder: "1000009", profileId: "p1" });
|
|
assert.equal(conflict?.id, "d2");
|
|
});
|
|
|
|
test("findTransponderConflict does not flag the same person's own multi-class entries (same profile)", () => {
|
|
const drivers = [
|
|
{ id: "d1", name: "Erik Andersson", transponder: "1000001", profileId: "p1" },
|
|
{ id: "d2", name: "Erik Andersson", transponder: "1000001", profileId: "p1" },
|
|
];
|
|
const conflict = findTransponderConflict(drivers, { transponder: "1000001", profileId: "p1" });
|
|
assert.equal(conflict, null);
|
|
});
|
|
|
|
test("findTransponderConflict excludes the driver being edited from its own conflict check", () => {
|
|
const drivers = [
|
|
{ id: "d1", name: "Erik Andersson", transponder: "1000001", profileId: "p1" },
|
|
];
|
|
const conflict = findTransponderConflict(drivers, { transponder: "1000001", profileId: "p1", excludeDriverId: "d1" });
|
|
assert.equal(conflict, null);
|
|
});
|
|
|
|
test("findTransponderConflict is a no-op for an empty transponder", () => {
|
|
const drivers = [{ id: "d1", name: "Erik Andersson", transponder: "", profileId: "p1" }];
|
|
assert.equal(findTransponderConflict(drivers, { transponder: "", profileId: "p2" }), null);
|
|
});
|