add more stats to mobile and fix refresh stint

This commit is contained in:
larssand
2026-09-04 16:41:51 +02:00
parent 4068cc7c19
commit 285babcfcf
10 changed files with 370 additions and 23 deletions

View File

@@ -11,6 +11,7 @@ const {
normalizePublicTrainingSince,
normalizePublicTrainingWindow,
splitPublicTrainingStints,
addPublicTrainingMarker,
} = require("../server/public_training_profile.js");
const DRIVER_ONE_TOKEN = "driver-one-token-12345678901234567890";
@@ -81,6 +82,16 @@ test("public share lookup rejects short, disabled, and unknown tokens", () => {
assert.equal(hasPublicTrainingShare(state, DRIVER_ONE_TOKEN), true);
});
test("public mobile marker is restricted to the shared profile and selected class", () => {
const state = buildState();
const marker = addPublicTrainingMarker(state, DRIVER_ONE_TOKEN, { classId: "class_2", type: "tires", note: " New rear tires " }, 123456);
assert.deepEqual({ driverId: marker.driverId, classId: marker.classId, type: marker.type, note: marker.note, timestamp: marker.timestamp }, { driverId: "driver_1_4wd", classId: "class_2", type: "tires", note: "New rear tires", timestamp: 123456 });
assert.equal(state.training.markers.length, 1);
assert.equal(addPublicTrainingMarker(state, DRIVER_TWO_TOKEN, { classId: "class_2" }, 123457), null);
assert.equal(addPublicTrainingMarker(state, DISABLED_TOKEN, { classId: "class_1" }, 123458), null);
});
test("public profile contains only the selected driver's sanitized aggregates", () => {
const now = Date.now();
const profile = buildPublicTrainingProfile(buildState(now), DRIVER_ONE_TOKEN, "2026-08-24T12:00:00.000Z", now - 30000, 30000);
@@ -101,6 +112,7 @@ test("public profile contains only the selected driver's sanitized aggregates",
assert.equal(profile.classProfiles.length, 2);
assert.equal(profile.classProfiles[0].stats.totalLaps, 4);
assert.equal(profile.classProfiles[0].stats.achievements.find((item) => item.id === "first_session").unlocked, true);
assert.ok(Array.isArray(profile.classProfiles[0].stats.paceBuckets));
assert.deepEqual(profile.classProfiles[0].channelStats, {
splitCount: 2,
bestSplitMs: 7000,

View File

@@ -26,7 +26,8 @@ function waitForServer(child, timeoutMs = 10000) {
return new Promise((resolve, reject) => {
let output = "";
const timeout = setTimeout(() => {
reject(new Error(`Server startup timed out. Output:\n${output}`));
reject(new Error(`Server startup timed out. Output:
${output}`));
}, timeoutMs);
const onData = (chunk) => {
output += chunk.toString();
@@ -42,7 +43,8 @@ function waitForServer(child, timeoutMs = 10000) {
});
child.once("exit", (code, signal) => {
clearTimeout(timeout);
reject(new Error(`Server exited before startup (code=${code}, signal=${signal}). Output:\n${output}`));
reject(new Error(`Server exited before startup (code=${code}, signal=${signal}). Output:
${output}`));
});
});
}
@@ -211,6 +213,28 @@ test("SQLite API persists state, passings, and overlay session results", { timeo
const storedPayload = await storedResponse.json();
assert.deepEqual(storedPayload.state, initialState);
const markerResponse = await fetch(baseUrl + "/public-training/api/" + shareToken + "/markers", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ classId: "class_1", type: "car", note: "Ride height change" }),
});
const markerPayload = await markerResponse.json();
assert.equal(markerResponse.status, 201);
assert.equal(markerPayload.marker.type, "car");
const markerStateResponse = await fetch(baseUrl + "/api/state");
const markerState = await markerStateResponse.json();
assert.equal(markerState.state.training.markers.length, 1);
assert.equal(markerState.state.training.markers[0].driverId, "driver_1");
assert.equal(markerState.state.training.markers[0].classId, "class_1");
assert.equal(markerState.state.training.markers[0].note, "Ride height change");
const invalidMarkerResponse = await fetch(baseUrl + "/public-training/api/" + shareToken + "/markers", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ classId: "unknown_class", type: "car" }),
});
assert.equal(invalidMarkerResponse.status, 404);
const sessionResult = {
competitors: {
driver_1: { key: "driver_1", driverName: "Driver One", laps: 1, bestLapMs: 16500 },