-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmerchant_test.go
More file actions
108 lines (99 loc) · 2.91 KB
/
Copy pathsubmerchant_test.go
File metadata and controls
108 lines (99 loc) · 2.91 KB
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
package squad_test
import (
"context"
"net/http"
"testing"
"github.com/kingztech2019/go-squad"
)
func TestSubMerchant_Create_Success(t *testing.T) {
srv, teardown := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
t.Errorf("expected POST, got %s", r.Method)
}
if r.URL.Path != "/merchant/sub-merchant" {
t.Errorf("expected /merchant/sub-merchant, got %s", r.URL.Path)
}
writeJSON(w, 200, "success", squad.SubMerchant{
ID: "sub_001",
MerchantID: "merch_abc",
DisplayName: "Vendor Store",
AccountName: "Emeka Obi",
AccountNumber: "0123456789",
BankCode: "057",
BankName: "Zenith Bank",
Email: "emeka@vendor.ng",
Status: "active",
})
})
defer teardown()
client := newTestClient(t, srv.URL)
resp, err := client.SubMerchants.Create(context.Background(), &squad.CreateSubMerchantParams{
DisplayName: "Vendor Store",
AccountName: "Emeka Obi",
AccountNumber: "0123456789",
BankCode: "057",
Email: "emeka@vendor.ng",
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if resp.ID != "sub_001" {
t.Errorf("expected sub_001, got %s", resp.ID)
}
if resp.Status != "active" {
t.Errorf("expected active, got %s", resp.Status)
}
}
func TestSubMerchant_Get_Success(t *testing.T) {
srv, teardown := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
writeJSON(w, 200, "success", squad.SubMerchant{
ID: "sub_001",
DisplayName: "Vendor Store",
})
})
defer teardown()
client := newTestClient(t, srv.URL)
resp, err := client.SubMerchants.Get(context.Background(), "sub_001")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if resp.DisplayName != "Vendor Store" {
t.Errorf("expected Vendor Store, got %s", resp.DisplayName)
}
}
func TestSubMerchant_List_Success(t *testing.T) {
srv, teardown := newTestServer(t, func(w http.ResponseWriter, _ *http.Request) {
writeJSON(w, 200, "success", squad.SubMerchantListResponse{
Merchants: []squad.SubMerchant{
{ID: "sub_001", DisplayName: "Vendor A"},
{ID: "sub_002", DisplayName: "Vendor B"},
},
Total: 2,
Page: 1,
PerPage: 20,
})
})
defer teardown()
client := newTestClient(t, srv.URL)
resp, err := client.SubMerchants.List(context.Background(), nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(resp.Merchants) != 2 {
t.Errorf("expected 2 merchants, got %d", len(resp.Merchants))
}
}
func TestSubMerchant_EmptyMerchantID(t *testing.T) {
client := squad.New("sandbox_sk_test")
_, err := client.SubMerchants.Get(context.Background(), "")
if err == nil {
t.Fatal("expected error for empty merchantID")
}
_, err = client.SubMerchants.Delete(context.Background(), "")
if err == nil {
t.Fatal("expected error for empty merchantID on delete")
}
}