-
Notifications
You must be signed in to change notification settings - Fork 5
/
preauth_txn_test.go
205 lines (194 loc) · 5.2 KB
/
preauth_txn_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package ravepay
import (
"net/http/httptest"
"reflect"
"testing"
)
func TestCapturePreAuthPayment(t *testing.T) {
handler := &testServer{}
server := httptest.NewServer(handler)
defer server.Close()
type args struct {
ref string
}
tests := []struct {
name string
args args
respBody string
want *ChargeResponse
wantErr bool
}{
{
name: "returns the capture response",
respBody: successfulPreAuthPaymentCaptureResponse,
args: args{
ref: "FLW-MOCK-839c1abc23b6a4bbb9da807d54c5bbda",
},
want: &ChargeResponse{
Status: "success",
Message: "Capture complete",
Data: chargeResponseData{
AccountID: 48,
Amount: 20,
Appfee: 0.25,
AuthModelUsed: "NOAUTH",
Authurl: "N/A",
// ChargedAmount: 20.25,
ChargeResponseMessage: "Approved",
ChargeResponseCode: "00",
ChargeType: "preauth",
CreatedAt: "2017-10-26T03:56:42.000Z",
Currency: "NGN",
CustomerID: 88067,
Cycle: "one-time",
DeviceFingerprint: "69e6b7f0b72037aa8428b70fbe03986c",
FlwRef: "FLW-MOCK-839c1abc23b6a4bbb9da807d54c5bbda",
FraudStatus: "ok",
ID: 194211,
IP: "::ffff:10.37.225.74",
Narration: "FLW-PBF CARD Transaction ",
PaymentID: "47433",
PaymentType: "card",
RedirectURL: "http://127.0.0",
Status: "successful",
TxRef: "MC-1508990174050",
UpdatedAt: "2017-10-26T04:20:21.000Z",
Vbvrespcode: "00",
Vbvrespmessage: "Approved",
Customer: Customer{
AccountID: 48,
CreatedAt: "2017-10-26T03:39:45.000Z",
Email: "tester@flutter.co",
FullName: "temi desola",
ID: 88067,
Phone: "08056552980",
UpdatedAt: "2017-10-26T03:39:45.000Z",
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
capturePreAuthURL = server.URL
handler.resp = []byte(tt.respBody)
got, err := CapturePreAuthPayment(tt.args.ref)
if (err != nil) != tt.wantErr {
t.Errorf("CapturePreAuthPayment() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("CapturePreAuthPayment() = %+v, want %+v", got, tt.want)
}
})
}
}
func TestRefundPreAuthPayment(t *testing.T) {
handler := &testServer{}
server := httptest.NewServer(handler)
defer server.Close()
type args struct {
ref string
}
tests := []struct {
name string
args args
respBody string
want *PreAuthResponse
wantErr bool
}{
{
name: "returns the refund preauth payment response if successful",
args: args{
ref: "FLW-MOCK-839c1abc23b6a4bbb9da807d54c5bbda",
},
respBody: successfulPreAuthPaymentRefundResponse,
want: &PreAuthResponse{
Message: "Refund or void complete",
Status: "success",
},
wantErr: false,
},
{
name: "returns the refund preauth payment response if unsuccessful",
args: args{
ref: "FLW-MOCK-839c1abc23b6a4bbb9da807d54c5bbda",
},
respBody: failedPreAuthPaymentRefundResponse,
want: &PreAuthResponse{
Message: "No transaction found",
Status: "error",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
voidorRefundPreAuthURL = server.URL
handler.resp = []byte(tt.respBody)
got, err := RefundPreAuthPayment(tt.args.ref)
if (err != nil) != tt.wantErr {
t.Errorf("RefundPreAuthPayment() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got.Message != tt.want.Message || got.Status != tt.want.Status {
t.Errorf("RefundPreAuthPayment() = %v, want %v", got, tt.want)
}
})
}
}
func TestVoidPreAuthPayment(t *testing.T) {
handler := &testServer{}
server := httptest.NewServer(handler)
defer server.Close()
type args struct {
ref string
}
tests := []struct {
name string
args args
respBody string
want *PreAuthResponse
wantErr bool
}{
{
name: "returns the refund preauth payment response if successful",
args: args{
ref: "FLW-MOCK-839c1abc23b6a4bbb9da807d54c5bbda",
},
respBody: successfulPreAuthPaymentRefundResponse,
want: &PreAuthResponse{
Message: "Refund or void complete",
Status: "success",
},
wantErr: false,
},
{
name: "returns the refund preauth payment response if unsuccessful",
args: args{
ref: "FLW-MOCK-839c1abc23b6a4bbb9da807d54c5bbda",
},
respBody: failedPreAuthPaymentRefundResponse,
want: &PreAuthResponse{
Message: "No transaction found",
Status: "error",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
voidorRefundPreAuthURL = server.URL
handler.resp = []byte(tt.respBody)
got, err := VoidPreAuthPayment(tt.args.ref)
if (err != nil) != tt.wantErr {
t.Errorf("RefundPreAuthPayment() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got.Message != tt.want.Message || got.Status != tt.want.Status {
t.Errorf("RefundPreAuthPayment() = %v, want %v", got, tt.want)
}
})
}
}