refactor(backend): replace resetTestData with SetupTestDB and add new tests
Migrate all test files from resetTestData(t) to testutils.SetupTestDB(t) for isolated per-package test databases. - Add new feature tests: name history assertions, referral discount preview, time blockers, email validation, GDPR export, loyalty manual redemption - Update existing tests to use batch queries and SetupTestDB - Remove test_helpers.go resetTestData infrastructure - Add comprehensive user profile tests (442 new lines) Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -74,15 +74,21 @@ func TestDevClient_CreateCheckout_PendingThenCompleted(t *testing.T) {
|
||||
t.Error("expected checkout ID to be set")
|
||||
}
|
||||
|
||||
time.Sleep(4 * time.Second)
|
||||
|
||||
completed, err := client.GetCheckout(ctx, result.ID)
|
||||
// Poll until the background goroutine completes — avoids any timing assumptions
|
||||
var completed *PaymentResult
|
||||
for i := 0; i < 20; i++ {
|
||||
completed, err = client.GetCheckout(ctx, result.ID)
|
||||
if err == nil && completed.Status == "COMPLETED" {
|
||||
break
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("GetCheckout failed: %v", err)
|
||||
}
|
||||
|
||||
if completed.Status != "COMPLETED" {
|
||||
t.Errorf("expected status COMPLETED after wait, got %s", completed.Status)
|
||||
t.Errorf("expected status COMPLETED, got %s", completed.Status)
|
||||
}
|
||||
|
||||
if completed.Amount != 8000 {
|
||||
@@ -115,9 +121,18 @@ func TestDevClient_CreateCheckout_NoTip(t *testing.T) {
|
||||
t.Errorf("expected status PENDING, got %s", result.Status)
|
||||
}
|
||||
|
||||
time.Sleep(4 * time.Second)
|
||||
if result.ID == "" {
|
||||
t.Error("expected checkout ID to be set")
|
||||
}
|
||||
|
||||
completed, err := client.GetCheckout(ctx, result.ID)
|
||||
var completed *PaymentResult
|
||||
for i := 0; i < 20; i++ {
|
||||
completed, err = client.GetCheckout(ctx, result.ID)
|
||||
if err == nil && completed.Status == "COMPLETED" {
|
||||
break
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("GetCheckout failed: %v", err)
|
||||
}
|
||||
|
||||
@@ -189,3 +189,74 @@ func TestParseCursor_EmptyCursor(t *testing.T) {
|
||||
t.Fatal("expected error for empty cursor, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCursor3_Valid(t *testing.T) {
|
||||
count, tm, id, err := ParseCursor3("5|2026-06-15T10:30:00Z|abc123def456")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if count != 5 {
|
||||
t.Errorf("expected count 5, got %d", count)
|
||||
}
|
||||
if tm.Year() != 2026 || tm.Month() != 6 || tm.Day() != 15 {
|
||||
t.Errorf("unexpected time: %v", tm)
|
||||
}
|
||||
if id != "abc123def456" {
|
||||
t.Errorf("expected id 'abc123def456', got %q", id)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCursor3_InvalidFormat(t *testing.T) {
|
||||
_, _, _, err := ParseCursor3("not-a-valid-cursor")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for invalid cursor format, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCursor3_InvalidCount(t *testing.T) {
|
||||
_, _, _, err := ParseCursor3("not-a-number|2026-06-15T10:30:00Z|abc123def456")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for invalid count, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCursor3_InvalidTimestamp(t *testing.T) {
|
||||
_, _, _, err := ParseCursor3("5|not-a-time|abc123def456")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for invalid timestamp, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCursor3_EmptyCursor(t *testing.T) {
|
||||
_, _, _, err := ParseCursor3("")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for empty cursor, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCursor3_ZeroCount(t *testing.T) {
|
||||
count, _, _, err := ParseCursor3("0|2026-06-15T10:30:00Z|abc123def456")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if count != 0 {
|
||||
t.Errorf("expected count 0, got %d", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCursor3_LargeCount(t *testing.T) {
|
||||
count, _, _, err := ParseCursor3("999|2026-06-15T10:30:00Z|abc123def456")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if count != 999 {
|
||||
t.Errorf("expected count 999, got %d", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCursor3_NegativeCount(t *testing.T) {
|
||||
_, _, _, err := ParseCursor3("-1|2026-06-15T10:30:00Z|abc123def456")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error for negative count: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user