Add class-specific driver training profiles and metadata

This commit is contained in:
larssand
2026-08-24 22:05:50 +02:00
parent 3aeb77a042
commit 6f02e955a5
14 changed files with 559 additions and 128 deletions

View File

@@ -20,12 +20,13 @@ const DISABLED_TOKEN = "disabled-token-123456789012345678901";
function buildState(now = Date.now()) {
return {
drivers: [
{ id: "driver_1", name: "Driver One", brand: "Associated", classId: "class_1", transponder: "secret-transponder-one" },
{ id: "driver_2", name: "Driver Two", brand: "Xray", classId: "class_2", transponder: "secret-transponder-two" },
{ id: "driver_1", profileId: "profile_1", name: "Driver One", brand: "Associated 2WD", classId: "class_1", transponder: "secret-transponder-one" },
{ id: "driver_1_4wd", profileId: "profile_1", name: "Driver One", brand: "Associated 4WD", classId: "class_2", transponder: "secret-transponder-four" },
{ id: "driver_2", profileId: "profile_2", name: "Driver Two", brand: "Xray", classId: "class_1", transponder: "secret-transponder-two" },
],
classes: [
{ id: "class_1", name: "Modified" },
{ id: "class_2", name: "Stock" },
{ id: "class_1", name: "2WD" },
{ id: "class_2", name: "4WD" },
],
settings: {
clubName: "Test Club",
@@ -49,6 +50,8 @@ function buildState(now = Date.now()) {
{ driverId: "driver_1", sessionId: "free", timestamp: now - 12000, lapMs: 16500 },
{ driverId: "driver_1", sessionId: "free", timestamp: now - 4000, lapMs: 16000 },
{ driverId: "driver_1", sessionId: "free", timestamp: now - 2000, lapMs: 500 },
{ driverId: "driver_1_4wd", sessionId: "free", timestamp: now - 11000, lapMs: 14500 },
{ driverId: "driver_1_4wd", sessionId: "free", timestamp: now - 5000, lapMs: 14000 },
{ driverId: "driver_2", sessionId: "free", timestamp: now - 3000, lapMs: 12000 },
],
},
@@ -68,8 +71,8 @@ test("public profile contains only the selected driver's sanitized aggregates",
const profile = buildPublicTrainingProfile(buildState(now), DRIVER_ONE_TOKEN, "2026-08-24T12:00:00.000Z", now - 30000, 30000);
assert.equal(profile.profile.name, "Driver One");
assert.equal(profile.profile.brand, "Associated");
assert.equal(profile.profile.className, "Modified");
assert.equal(profile.profile.brand, "Associated 2WD");
assert.equal(profile.profile.className, "2WD");
assert.equal(profile.profile.clubRank, 1);
assert.equal(profile.profile.rankedDrivers, 2);
assert.equal(profile.branding.clubName, "Test Club");
@@ -80,6 +83,11 @@ test("public profile contains only the selected driver's sanitized aggregates",
assert.equal(profile.goals.length, 1);
assert.equal(profile.goals[0].title, "Bronze");
assert.equal(profile.goals[0].percent, 80);
assert.equal(profile.classProfiles.length, 2);
assert.equal(profile.classProfiles[0].stats.totalLaps, 4);
assert.equal(profile.classProfiles[1].className, "4WD");
assert.equal(profile.classProfiles[1].stats.totalLaps, 2);
assert.equal(profile.classProfiles[1].stats.bestLapMs, 14000);
const serialized = JSON.stringify(profile);
assert.equal(serialized.includes("Driver Two"), false);