Record completed training sessions, credit them, and add session-count goals
A driver completing the practice timer, "Jämna varv", or "Stegträning" now gets a permanent history entry instead of the outcome only existing as a one-off notification - visible on both their mobile profile and the admin Training page, so progress over past sessions is actually reviewable. Each completion earns a prominent emoji-badged credit. The completion is verified server-side against the driver's real recorded laps before being saved, reusing the same progress builders live tracking already uses - the client can only ask for a completion to be checked and recorded, never supply the outcome itself, so a driver can't fabricate a completed session (and the reward tied to it) any more than they could fabricate a lap time. Both per-driver and club-wide goals can now target "complete N sessions of one exercise kind" as an alternative to "N laps", sharing the existing reward/claim mechanism and forms. Fixes a real bug found while building this: a pre-existing two-argument wrapper around getTrainingGoalProgress in app.js silently dropped the new third argument, so every sessions-metric goal displayed 0 progress regardless of how many sessions were actually completed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -117,6 +117,14 @@ Verified 2026-09-09: `buildStepTrainingProgress` in `src/training_logic.js` (uni
|
||||
|
||||
Verified 2026-09-09: unit tests in `tests/public_training_profile.test.js` cover `savePublicEvenLapsConfig`/`savePublicStepTrainingConfig` (auth via share token, class-membership checks, invalid-input rejection) and the sanitized progress builders, including an explicit assertion that driver IDs never appear in the serialized response. A full end-to-end headless-browser run against an isolated temp SQLite instance (never the installation database) exercised the real mobile page: saving a config via the new `POST /public-training/api/:shareToken/even-laps` and `/step-training` endpoints, starting/stopping via the UI buttons, and confirming live progress (streak count, tolerance-based lap coloring, step pills) renders correctly from seeded lap data - with zero uncaught JS errors and zero raw driverId/transponder leakage in the API response.
|
||||
|
||||
**Exercise session history, completion credit, and session-count goals:** implemented 2026-09-09, per a follow-up request - the driver wanted to look back at guided-exercise/practice sessions they'd started and see improvement over time, get explicit recognition for a completed session (not just ongoing lap/pace stats), and be able to set a reward goal based on "complete N sessions" the same way a lap-count goal already works.
|
||||
- [x] Completing any of the three self-service sessions (the general timer, "Jämna varv", "Stegträning") is auto-detected client-side and recorded as a permanent history entry - visible on both the driver's mobile profile ("Träningshistorik") and the admin Training page, so a coach can review it too.
|
||||
- [x] A completion is verified server-side against the real ledger laps for that run, exactly the way live progress already is - the client can only *ask* for a completion to be recorded, never supply the outcome. A driver cannot fabricate a completed session (and therefore a reward) any more than they could fabricate a lap time.
|
||||
- [x] A completed session earns a prominent, emoji-badged credit ("Du har genomfört 1 träningspass idag 🪜") shown first in the existing credits list, plus its own history row per completed session (kind, date, outcome summary).
|
||||
- [x] Both per-driver goals and the club-wide shared goal can now target "N completed sessions of one exercise kind" as an alternative to "N laps", sharing the exact same reward/claim mechanism, editable from the same forms.
|
||||
|
||||
Verified 2026-09-09: unit tests across `tests/training_logic.test.js` (the new `exerciseSessions` log's normalization/dedup, `countExerciseSessions`/`countDriverExerciseSessions`, both goal-progress functions' new sessions branch) and `tests/public_training_profile.test.js` (server-side completion verification rejecting an unearned claim for all three kinds, accepting a genuine one, refusing a duplicate for the same run, and confirming driverId/classId never appear in the client-facing history). Two real bugs found and fixed while building this: `ensureSessionResult`-adjacent `getTrainingGoalProgress` had a pre-existing two-argument wrapper in `app.js` that silently dropped the new third `exerciseSessionCount` argument, so every sessions-metric goal displayed 0 progress regardless of real completions, until a real-browser check caught the mismatch between a debug log (computed correctly) and the rendered card (stuck at 0); and the club-goal creation form's fields were unreachable in a real click test because its `<details>` disclosure needed to be opened first, same as the per-driver goal form's. A full headless-browser run against an isolated temp SQLite instance covered: the mobile page auto-detecting and recording a real step-training completion with zero extra clicks, the credit and history section both rendering correctly, a second reload not duplicating the recorded session, and the admin Training page correctly computing goal progress and creating both a per-driver and a club sessions-metric goal through their real forms.
|
||||
|
||||
## 4. Results archive
|
||||
|
||||
Implemented 2026-09-09.
|
||||
|
||||
Reference in New Issue
Block a user