diff --git a/backend/handlers/payments/till_test.go b/backend/handlers/payments/till_test.go index e887fe3..a204a80 100644 --- a/backend/handlers/payments/till_test.go +++ b/backend/handlers/payments/till_test.go @@ -540,10 +540,18 @@ func TestGetTillCheckoutStatus_Completed(t *testing.T) { t.Fatal("expected checkout_id to be set for card_machine payment") } - // Wait for the mock goroutine to complete. The mock's goroutine sleeps 3s - // by default (mockSleep is only skipped when isTesting is set before the - // square package initializes, which depends on init ordering with db). - time.Sleep(3500 * time.Millisecond) + // Wait for the mock goroutine to complete the checkout with polling. + deadline := time.Now().Add(5 * time.Second) + for { + _, err := SquareClient.GetCheckout(context.Background(), *createResp.CheckoutID) + if err == nil { + break + } + if time.Now().After(deadline) { + t.Fatalf("timed out waiting for checkout to complete: %v", err) + } + time.Sleep(100 * time.Millisecond) + } // Now call GetTillCheckoutStatus — should return COMPLETED. statusReq := httptest.NewRequest("GET", "/api/admin/till/checkout/"+*createResp.CheckoutID+"/status", nil)