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,