-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoid_test.go
92 lines (78 loc) · 1.44 KB
/
void_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
package zooz
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestVoidClient_New(t *testing.T) {
cli := &httpClientMock{
t: t,
expectedMethod: "POST",
expectedURL: "/payments/payment_id/voids",
expectedHeaders: map[string]string{
headerIdempotencyKey: "idempotency_key",
},
responseBody: `{
"id": "id"
}`,
}
c := &VoidClient{Caller: New(OptHTTPClient(cli))}
void, err := c.New(
context.Background(),
"idempotency_key",
"payment_id",
)
require.NoError(t, err)
require.Equal(t, &Void{
ID: "id",
}, void)
}
func TestVoidClient_Get(t *testing.T) {
cli := &httpClientMock{
t: t,
expectedMethod: "GET",
expectedURL: "/payments/payment_id/voids/id",
responseBody: `{
"id": "id"
}`,
}
c := &VoidClient{Caller: New(OptHTTPClient(cli))}
void, err := c.Get(
context.Background(),
"payment_id",
"id",
)
require.NoError(t, err)
require.Equal(t, &Void{
ID: "id",
}, void)
}
func TestVoidClient_GetList(t *testing.T) {
cli := &httpClientMock{
t: t,
expectedMethod: "GET",
expectedURL: "/payments/payment_id/voids",
responseBody: `[
{
"id": "id1"
},
{
"id": "id2"
}
]`,
}
c := &VoidClient{Caller: New(OptHTTPClient(cli))}
voids, err := c.GetList(
context.Background(),
"payment_id",
)
require.NoError(t, err)
require.Equal(t, []Void{
{
ID: "id1",
},
{
ID: "id2",
},
}, voids)
}