fix: add ShouldFail to Square MockClient for testing payment error paths
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user