feat: add single-profile settings table and store layer

Add Profile table to store Garmin credentials and engine configuration
parameters. Implements GetProfile() and UpdateProfile() store methods with
comprehensive test coverage. The profile singleton row is automatically
initialized on migration and persists all configuration state.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 18:41:37 +02:00
parent 5fbc574d34
commit 4748917a25
3 changed files with 195 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package store
import (
"context"
"testing"
)
func TestProfile_DefaultsThenUpdate(t *testing.T) {
db := openTestDB(t)
ctx := context.Background()
p, err := db.GetProfile(ctx)
if err != nil {
t.Fatalf("GetProfile: %v", err)
}
if p.RollingWindowDays != 90 {
t.Errorf("RollingWindowDays = %d, want 90 (migration default)", p.RollingWindowDays)
}
if p.HRZone1MinPct != 50 || p.HRZone5MaxPct != 100 {
t.Errorf("zone defaults = %+v, want Z1 min=50, Z5 max=100", p)
}
maxHR, restingHR := 190.0, 50.0
p.GarminEmail = "runner@example.com"
p.GarminPassword = "hunter2"
p.RollingWindowDays = 120
p.MaxHeartRate = &maxHR
p.RestingHeartRate = &restingHR
p.IntervalWarmupMinutes = 8
if err := db.UpdateProfile(ctx, p); err != nil {
t.Fatalf("UpdateProfile: %v", err)
}
got, err := db.GetProfile(ctx)
if err != nil {
t.Fatalf("GetProfile after update: %v", err)
}
if got.GarminEmail != "runner@example.com" || got.RollingWindowDays != 120 {
t.Errorf("got = %+v, want updated email/window", got)
}
if got.MaxHeartRate == nil || *got.MaxHeartRate != 190 {
t.Errorf("MaxHeartRate = %v, want 190", got.MaxHeartRate)
}
if got.IntervalWarmupMinutes != 8 {
t.Errorf("IntervalWarmupMinutes = %v, want 8", got.IntervalWarmupMinutes)
}
}