Part of per-user profile isolation: profile rows are no longer a global singleton, so every read/write requires the caller's userID. This also requires scoping ListActivities, ListWorkoutKinds, UpsertActivity, CreateWorkoutKind, GetSyncState, UpdateSyncState, and ResetAllSyncedData to userID, plus updating all related tests in the store package.
73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestWorkoutTaxonomy_SeededWithEightFixedTypes(t *testing.T) {
|
|
db := openTestDB(t)
|
|
ctx := context.Background()
|
|
userID, err := db.ProvisionUser(ctx, "test-sub", "Test User")
|
|
if err != nil {
|
|
t.Fatalf("ProvisionUser: %v", err)
|
|
}
|
|
|
|
kinds, err := db.ListWorkoutKinds(ctx, userID, true)
|
|
if err != nil {
|
|
t.Fatalf("ListWorkoutKinds: %v", err)
|
|
}
|
|
if len(kinds) != 8 {
|
|
t.Fatalf("expected 8 seeded workout kinds, got %d: %+v", len(kinds), kinds)
|
|
}
|
|
|
|
wantNames := map[string]bool{
|
|
"Easy": false, "Long": false, "60' Threshold": false, "30' Threshold": false,
|
|
"Tempo": false, "Intervals": false, "MAS Test": false, "Race": false,
|
|
}
|
|
for _, k := range kinds {
|
|
if _, ok := wantNames[k.Name]; !ok {
|
|
t.Errorf("unexpected seeded kind name %q", k.Name)
|
|
continue
|
|
}
|
|
wantNames[k.Name] = true
|
|
}
|
|
for name, found := range wantNames {
|
|
if !found {
|
|
t.Errorf("expected seeded kind %q, not found", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Every list of training types (Activities filters, Progression's kind
|
|
// picker, Profile's Training types card) relies on ListWorkoutKinds' own
|
|
// ORDER BY priority DESC, name to already be in this exact fixed order --
|
|
// none of them re-sort client-side.
|
|
func TestWorkoutTaxonomy_ListedInFixedDisplayOrder(t *testing.T) {
|
|
db := openTestDB(t)
|
|
ctx := context.Background()
|
|
userID, err := db.ProvisionUser(ctx, "test-sub", "Test User")
|
|
if err != nil {
|
|
t.Fatalf("ProvisionUser: %v", err)
|
|
}
|
|
|
|
kinds, err := db.ListWorkoutKinds(ctx, userID, true)
|
|
if err != nil {
|
|
t.Fatalf("ListWorkoutKinds: %v", err)
|
|
}
|
|
|
|
want := []string{"Easy", "Long", "60' Threshold", "30' Threshold", "Tempo", "Intervals", "MAS Test", "Race"}
|
|
if len(kinds) != len(want) {
|
|
t.Fatalf("expected %d kinds, got %d", len(want), len(kinds))
|
|
}
|
|
for i, name := range want {
|
|
if kinds[i].Name != name {
|
|
got := make([]string, len(kinds))
|
|
for j, k := range kinds {
|
|
got[j] = k.Name
|
|
}
|
|
t.Fatalf("position %d: got %q, want %q (full order: %v)", i, kinds[i].Name, name, got)
|
|
}
|
|
}
|
|
}
|