fix(sync): a browser that is not the race master can't change heats, laps or the active heat (1.89.38)
This commit is contained in:
1 parent
cea278518e
commit
5928ce847b
8 files changed
+76
-10
No files matched your search
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { keepStartedSessions } = require("../server/session_guard.js");
|
||||
const { keepStartedSessions, keepRaceControl } = require("../server/session_guard.js");
|
||||
|
||||
const stored = () => ({
|
||||
sessions: [
|
||||
@@ -51,3 +51,27 @@ test("normal progress, new and deleted heats pass through untouched", () => {
|
||||
assert.deepEqual(state.sessions.map((session) => session.id), ["a2", "a3", "new"], "a1 deleted on purpose stays deleted");
|
||||
assert.equal(keepStartedSessions(null, stored()).state, null);
|
||||
});
|
||||
|
||||
test("a save from the computer that is not master keeps the master's race control but its other edits", () => {
|
||||
const master = { ...stored(), activeSessionId: "a2", sessions: [...stored().sessions, { id: "q1", status: "finished", startedAt: 50, endedAt: 90 }] };
|
||||
master.resultsBySession.q1 = { competitors: { k: { laps: 9 } } };
|
||||
const slaveCopy = {
|
||||
activeSessionId: "a3",
|
||||
drivers: [{ id: "d1", name: "Renamed on the slave" }],
|
||||
// older copy: a2 not started yet, a3 picked to look at, q1 missing, a new heat added
|
||||
sessions: [{ id: "a1", status: "finished", startedAt: 100, endedAt: 400, name: "A final 1" }, { id: "a2", status: "ready", startedAt: null, driverIds: ["d1", "d2"] }, { id: "a3", status: "ready", calledAt: 5 }, { id: "b1", status: "ready" }],
|
||||
resultsBySession: {},
|
||||
};
|
||||
const state = keepRaceControl(slaveCopy, master);
|
||||
assert.equal(state.activeSessionId, "a2", "looking at a heat on the slave doesn't move the master's focus");
|
||||
assert.equal(state.drivers[0].name, "Renamed on the slave");
|
||||
const a2 = state.sessions.find((session) => session.id === "a2");
|
||||
assert.equal(a2.status, "running");
|
||||
assert.equal(a2.startedAt, 500);
|
||||
assert.deepEqual(a2.driverIds, ["d1", "d2"], "the grid edit from the slave is kept");
|
||||
assert.equal("calledAt" in state.sessions.find((session) => session.id === "a3"), false);
|
||||
assert.ok(state.sessions.some((session) => session.id === "b1"), "a heat added on the slave is kept");
|
||||
assert.ok(state.sessions.some((session) => session.id === "q1"), "a run heat missing from the old copy is not deleted");
|
||||
assert.equal(state.resultsBySession.q1.competitors.k.laps, 9);
|
||||
assert.equal(state.resultsBySession.a1.competitors.k.laps, 14);
|
||||
});
|
||||
Reference in new issue
Block a user