workout_kinds gains a real user_id column (Task 1); workout_type_paces has none of its own and is scoped via a join to workout_kinds instead, since it's always accessed through a specific kind. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestWorkoutTypePaces_SeededOnePerKindThenUpdate(t *testing.T) {
|
|
db := openTestDB(t)
|
|
ctx := context.Background()
|
|
|
|
userID, err := db.ProvisionUser(ctx, "test-sub", "Test")
|
|
if err != nil {
|
|
t.Fatalf("ProvisionUser: %v", err)
|
|
}
|
|
|
|
all, err := db.ListWorkoutTypePaces(ctx, userID)
|
|
if err != nil {
|
|
t.Fatalf("ListWorkoutTypePaces: %v", err)
|
|
}
|
|
if len(all) != 8 {
|
|
t.Fatalf("expected 8 seeded pace rows (one per taxonomy kind), got %d", len(all))
|
|
}
|
|
for _, p := range all {
|
|
if p.PaceMinSecPerKm != nil || p.PaceMaxSecPerKm != nil || p.HRMinPctHRR != nil || p.HRMaxPctHRR != nil {
|
|
t.Errorf("expected all-nil seeded pace row for kind %d, got %+v", p.WorkoutKindID, p)
|
|
}
|
|
}
|
|
|
|
target := all[0]
|
|
minPace, maxPace, hrMin, hrMax := 330.0, 420.0, 70.0, 80.0
|
|
target.PaceMinSecPerKm = &minPace
|
|
target.PaceMaxSecPerKm = &maxPace
|
|
target.HRMinPctHRR = &hrMin
|
|
target.HRMaxPctHRR = &hrMax
|
|
|
|
if err := db.UpdateWorkoutTypePace(ctx, userID, target); err != nil {
|
|
t.Fatalf("UpdateWorkoutTypePace: %v", err)
|
|
}
|
|
|
|
got, err := db.GetWorkoutTypePace(ctx, userID, target.WorkoutKindID)
|
|
if err != nil {
|
|
t.Fatalf("GetWorkoutTypePace: %v", err)
|
|
}
|
|
if got.PaceMinSecPerKm == nil || *got.PaceMinSecPerKm != 330 {
|
|
t.Errorf("PaceMinSecPerKm = %v, want 330", got.PaceMinSecPerKm)
|
|
}
|
|
if got.HRMinPctHRR == nil || *got.HRMinPctHRR != 70 {
|
|
t.Errorf("HRMinPctHRR = %v, want 70", got.HRMinPctHRR)
|
|
}
|
|
if got.HRMaxPctHRR == nil || *got.HRMaxPctHRR != 80 {
|
|
t.Errorf("HRMaxPctHRR = %v, want 80", got.HRMaxPctHRR)
|
|
}
|
|
}
|