fix: add ShouldFail to Square MockClient for testing payment error paths

This commit is contained in:
2026-07-11 16:07:05 +01:00
parent ce0bb43ebf
commit 05c5d73d30
2 changed files with 50 additions and 0 deletions
@@ -361,6 +361,49 @@ func TestDevClient_CreateCardOnFileRaw_UnknownBrand(t *testing.T) {
assert.True(t, card.IsDefault)
}
func TestCreatePayment_ShouldFail(t *testing.T) {
client := NewDevClient().(*MockClient)
client.ShouldFail = true
ctx := context.Background()
req := CreatePaymentReq{
Amount: 5000,
Currency: "GBP",
SourceID: "cnon:test-card",
IdempotencyKey: "test-key-fail",
ReferenceID: "booking-fail",
}
result, err := client.CreatePayment(ctx, req)
if err == nil {
t.Fatal("expected error when ShouldFail is true, got nil")
}
if result != nil {
t.Errorf("expected nil result, got %+v", result)
}
}
func TestRefundPayment_ShouldFail(t *testing.T) {
client := NewDevClient().(*MockClient)
client.ShouldFail = true
ctx := context.Background()
req := RefundPaymentReq{
PaymentID: "pay_mock_fail",
Amount: 5000,
IdempotencyKey: "refund-key-fail",
Reason: "simulated failure",
}
result, err := client.RefundPayment(ctx, req)
if err == nil {
t.Fatal("expected error when ShouldFail is true, got nil")
}
if result != nil {
t.Errorf("expected nil result, got %+v", result)
}
}
func TestDevClient_ConcurrentPayments(t *testing.T) {
client := NewDevClient().(*MockClient)