-
Notifications
You must be signed in to change notification settings - Fork 5
/
capture_test.go
114 lines (101 loc) · 2.11 KB
/
capture_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
package zooz
import (
"context"
"testing"
)
func TestCaptureClient_New(t *testing.T) {
caller := &callerMock{
t: t,
expectedMethod: "POST",
expectedPath: "payments/payment_id/captures",
expectedHeaders: map[string]string{
headerIdempotencyKey: "idempotency_key",
},
expectedReqObj: &CaptureParams{
ReconciliationID: "reconciliation_id",
},
returnRespObj: &Capture{
ID: "id",
},
}
c := &CaptureClient{Caller: caller}
capture, err := c.New(
context.Background(),
"idempotency_key",
"payment_id",
&CaptureParams{
ReconciliationID: "reconciliation_id",
},
)
if err != nil {
t.Error("Error must be nil")
}
if capture == nil {
t.Errorf("Capture is nil")
}
if capture.ID != "id" {
t.Errorf("Capture is not as expected: %+v", capture)
}
}
func TestCaptureClient_Get(t *testing.T) {
caller := &callerMock{
t: t,
expectedMethod: "GET",
expectedPath: "payments/payment_id/captures/id",
expectedHeaders: map[string]string{},
returnRespObj: &Capture{
ID: "id",
},
}
c := &CaptureClient{Caller: caller}
capture, err := c.Get(
context.Background(),
"payment_id",
"id",
)
if err != nil {
t.Error("Error must be nil")
}
if capture == nil {
t.Errorf("Capture is nil")
}
if capture.ID != "id" {
t.Errorf("Capture is not as expected: %+v", capture)
}
}
func TestCaptureClient_GetList(t *testing.T) {
caller := &callerMock{
t: t,
expectedMethod: "GET",
expectedPath: "payments/payment_id/captures",
expectedHeaders: map[string]string{},
returnRespObj: &[]Capture{
{
ID: "id1",
},
{
ID: "id2",
},
},
}
c := &CaptureClient{Caller: caller}
captures, err := c.GetList(
context.Background(),
"payment_id",
)
if err != nil {
t.Error("Error must be nil")
}
if captures == nil {
t.Errorf("Captures is nil")
}
if len(captures) != 2 {
t.Errorf("Count of captures is wrong: %d", len(captures))
}
if captures[0].ID != "id1" {
t.Errorf("Capture is not as expected: %+v", captures[0])
}
if captures[1].ID != "id2" {
t.Errorf("Capture is not as expected: %+v", captures[1])
}
}