feat(auth): add user profile, phone login, and account deletion
This commit is contained in:
@@ -121,6 +121,46 @@ func testAuth(t *testing.T, ctx context.Context, r Repos) {
|
||||
if _, err := r.Auth.GetUserByEmail(ctx, "missing@test.local"); !errors.Is(err, auth.ErrNotFound) {
|
||||
t.Fatalf("missing email err = %v, want ErrNotFound", err)
|
||||
}
|
||||
if _, err := r.Auth.GetUserByPhone(ctx, "+15550000000"); !errors.Is(err, auth.ErrNotFound) {
|
||||
t.Fatalf("missing phone err = %v, want ErrNotFound", err)
|
||||
}
|
||||
|
||||
// A phone-only account stores NULL email and is retrievable by phone.
|
||||
phoneUser := &models.User{ID: newID(), Phone: "+15550000001", PasswordHash: "x", Name: "Phone Only"}
|
||||
if err := r.Auth.CreateUser(ctx, phoneUser); err != nil {
|
||||
t.Fatalf("create phone-only user: %v", err)
|
||||
}
|
||||
byPhone, err := r.Auth.GetUserByPhone(ctx, phoneUser.Phone)
|
||||
if err != nil || byPhone.ID != phoneUser.ID || byPhone.Email != "" {
|
||||
t.Fatalf("get by phone: %v %+v", err, byPhone)
|
||||
}
|
||||
|
||||
// Adding the missing identifier fills only the empty column.
|
||||
if err := r.Auth.AddIdentifier(ctx, phoneUser.ID, "added@test.local", ""); err != nil {
|
||||
t.Fatalf("add identifier: %v", err)
|
||||
}
|
||||
withEmail, _ := r.Auth.GetUserByID(ctx, phoneUser.ID)
|
||||
if withEmail.Email != "added@test.local" || withEmail.Phone != phoneUser.Phone {
|
||||
t.Fatalf("identifier not added: %+v", withEmail)
|
||||
}
|
||||
|
||||
if err := r.Auth.UpdateName(ctx, u.ID, "Renamed"); err != nil {
|
||||
t.Fatalf("update name: %v", err)
|
||||
}
|
||||
if err := r.Auth.UpdatePasswordHash(ctx, u.ID, "newhash"); err != nil {
|
||||
t.Fatalf("update password: %v", err)
|
||||
}
|
||||
renamed, _ := r.Auth.GetUserByID(ctx, u.ID)
|
||||
if renamed.Name != "Renamed" || renamed.PasswordHash != "newhash" {
|
||||
t.Fatalf("user updates not applied: %+v", renamed)
|
||||
}
|
||||
|
||||
if err := r.Auth.DeleteUser(ctx, phoneUser.ID); err != nil {
|
||||
t.Fatalf("delete user: %v", err)
|
||||
}
|
||||
if _, err := r.Auth.GetUserByID(ctx, phoneUser.ID); !errors.Is(err, auth.ErrNotFound) {
|
||||
t.Fatalf("deleted user still present")
|
||||
}
|
||||
|
||||
if err := r.Auth.UpdatePreferences(ctx, u.ID, []byte(`{"theme":"dark"}`)); err != nil {
|
||||
t.Fatalf("update preferences: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user