SMARTRUN_BACKFILL_HORIZON_DAYS was a server-startup-only env var with no UI, defaulting to 3 years -- so editing the unrelated "Rolling window" profile field (for classification, not sync) had no effect on how far back Sync Now reached. Backfill horizon is now Profile.BackfillHorizonDays, read fresh on every Backfill call, with its own field on the Profile page.
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
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)
|
|
}
|
|
if p.WarmupMinutes != 10 || p.CooldownMinutes != 5 {
|
|
t.Errorf("phase-minute defaults = %+v, want warmup=10, cooldown=5", p)
|
|
}
|
|
if p.BackfillHorizonDays != 1095 {
|
|
t.Errorf("BackfillHorizonDays = %d, want 1095 (migration default)", p.BackfillHorizonDays)
|
|
}
|
|
|
|
maxHR, restingHR := 190.0, 50.0
|
|
p.GarminEmail = "runner@example.com"
|
|
p.GarminPassword = "hunter2"
|
|
p.RollingWindowDays = 120
|
|
p.MaxHeartRate = &maxHR
|
|
p.RestingHeartRate = &restingHR
|
|
p.WarmupMinutes = 8
|
|
p.BackfillHorizonDays = 14
|
|
|
|
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.WarmupMinutes != 8 {
|
|
t.Errorf("WarmupMinutes = %v, want 8", got.WarmupMinutes)
|
|
}
|
|
if got.BackfillHorizonDays != 14 {
|
|
t.Errorf("BackfillHorizonDays = %v, want 14", got.BackfillHorizonDays)
|
|
}
|
|
}
|