store: scope GetProfile/UpdateProfile to a user_id
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.
This commit is contained in:
@@ -41,6 +41,10 @@ func TestMigrateIsIdempotent(t *testing.T) {
|
||||
func TestUpsertActivity_InsertThenUpdateIsIdempotent(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)
|
||||
}
|
||||
|
||||
a := Activity{
|
||||
GarminActivityID: 23554066504,
|
||||
@@ -51,13 +55,13 @@ func TestUpsertActivity_InsertThenUpdateIsIdempotent(t *testing.T) {
|
||||
RawJSON: `{"activityId":23554066504,"activityName":"Auriol - W2-5-Base Endurance","activityType":{"typeKey":"running"}}`,
|
||||
}
|
||||
|
||||
id, err := db.UpsertActivity(ctx, a)
|
||||
id, err := db.UpsertActivity(ctx, userID, a)
|
||||
if err != nil {
|
||||
t.Fatalf("UpsertActivity (insert): %v", err)
|
||||
}
|
||||
|
||||
a.AvgHR = f(150) // simulate a re-sync with a corrected value
|
||||
id2, err := db.UpsertActivity(ctx, a)
|
||||
id2, err := db.UpsertActivity(ctx, userID, a)
|
||||
if err != nil {
|
||||
t.Fatalf("UpsertActivity (update): %v", err)
|
||||
}
|
||||
@@ -73,7 +77,7 @@ func TestUpsertActivity_InsertThenUpdateIsIdempotent(t *testing.T) {
|
||||
t.Errorf("AvgHR = %v, want 150 (update should have applied)", *got.AvgHR)
|
||||
}
|
||||
|
||||
all, err := db.ListActivities(ctx, ActivityFilter{})
|
||||
all, err := db.ListActivities(ctx, userID, ActivityFilter{})
|
||||
if err != nil {
|
||||
t.Fatalf("ListActivities: %v", err)
|
||||
}
|
||||
@@ -85,8 +89,12 @@ func TestUpsertActivity_InsertThenUpdateIsIdempotent(t *testing.T) {
|
||||
func TestKindAssignment_AppendOnlyHistoryAndCurrentView(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)
|
||||
}
|
||||
|
||||
activityID, err := db.UpsertActivity(ctx, Activity{
|
||||
activityID, err := db.UpsertActivity(ctx, userID, Activity{
|
||||
GarminActivityID: 1,
|
||||
StartTimeUTC: "2026-07-11 05:00:00",
|
||||
RawJSON: "{}",
|
||||
@@ -95,7 +103,7 @@ func TestKindAssignment_AppendOnlyHistoryAndCurrentView(t *testing.T) {
|
||||
t.Fatalf("UpsertActivity: %v", err)
|
||||
}
|
||||
|
||||
kindID, err := db.CreateWorkoutKind(ctx, WorkoutKind{
|
||||
kindID, err := db.CreateWorkoutKind(ctx, userID, WorkoutKind{
|
||||
Name: "Test Assignment Custom",
|
||||
RuleJSON: `{"match":"all","conditions":[]}`,
|
||||
IsActive: true,
|
||||
@@ -169,8 +177,12 @@ func TestKindAssignment_AppendOnlyHistoryAndCurrentView(t *testing.T) {
|
||||
func TestReplaceLapsIsIdempotent(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)
|
||||
}
|
||||
|
||||
activityID, err := db.UpsertActivity(ctx, Activity{
|
||||
activityID, err := db.UpsertActivity(ctx, userID, Activity{
|
||||
GarminActivityID: 2,
|
||||
StartTimeUTC: "2026-07-11 05:00:00",
|
||||
RawJSON: "{}",
|
||||
@@ -245,8 +257,13 @@ func TestForeignKeyEnforcementPostMigration(t *testing.T) {
|
||||
// migrations 0023/0024/0025) is properly scoped and re-enabled after each
|
||||
// table rebuild.
|
||||
|
||||
userID, err := db.ProvisionUser(ctx, "test-sub", "Test User")
|
||||
if err != nil {
|
||||
t.Fatalf("ProvisionUser: %v", err)
|
||||
}
|
||||
|
||||
// Insert an activity that we can reference.
|
||||
activityID, err := db.UpsertActivity(ctx, Activity{
|
||||
activityID, err := db.UpsertActivity(ctx, userID, Activity{
|
||||
GarminActivityID: 1001,
|
||||
StartTimeUTC: "2026-07-11 05:00:00",
|
||||
RawJSON: "{}",
|
||||
|
||||
Reference in New Issue
Block a user