-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremittance_test.go
144 lines (123 loc) · 3.85 KB
/
remittance_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
package gomomo
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRemittanceServiceOp_GetToken(t *testing.T) {
t.Run("Get token returns a 200_OK", func(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc(remittancesTokenURL, func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"access_token": "token", "token_type": "tokenType", "expires_in": 0}`)
w.WriteHeader(http.StatusOK)
testMethod(t, r, http.MethodPost)
})
token, err := client.Remittance.GetToken(ctx, "234343434", "43434343434")
if err != nil {
t.Fatalf("unexpected error %s", err)
}
if token != "token" {
t.Errorf("Expected 'token' but got %s", token)
}
if client.Token != token {
t.Errorf("Expected 'token' to be set on client but got %s", token)
}
})
t.Run("GetToken returns a non 200_OK status", func(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc(remittancesTokenURL, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
testMethod(t, r, http.MethodPost)
})
_, err := client.Remittance.GetToken(ctx, "234343434", "43434343434")
if err == nil {
t.Errorf("Expected a non nil error but got %s", err)
}
})
}
func TestRemittanceServiceOp_Transfer(t *testing.T) {
t.Run("Remittance.Transfer returns 202_ACCEPTED", func(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc(remittancesTransferURL, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusAccepted)
testMethod(t, r, http.MethodPost)
})
client.Token = "34534523243"
transactionID, err := client.Remittance.Transfer(ctx, "25678999720", 500, "34232", "payee", "payer", "UGX")
if err != nil {
t.Fatalf("unexpected error %s", err)
}
if transactionID == "" {
t.Errorf("Expected transactionID to be a non empty string")
}
})
}
func TestRemittanceServiceOp_GetTransfer(t *testing.T) {
setup()
defer teardown()
expectedStatus := PaymentStatusResponse{
Amount: "500",
Currency: "UGX",
FinancialTransactionID: 2312,
ExternalID: "3232",
Payer: paymentDetails{
PartyIDType: "MSISDN",
PartyID: "4656473839",
},
Status: "SUCCESSFUL",
Reason: "",
}
transactionID := "6c6eb16c-8b34-4d5d-bd41-2a9303f65075"
urlStr := fmt.Sprintf("%s/%s", remittancesTransferURL, transactionID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(expectedStatus)
w.WriteHeader(http.StatusOK)
testMethod(t, r, http.MethodGet)
})
actualStatus, err := client.Remittance.GetTransfer(ctx, transactionID)
if err != nil {
t.Fatalf("unexpected error %s", err)
}
if !reflect.DeepEqual(actualStatus, &expectedStatus) {
t.Errorf("GetTransaction\n got=%#v\nwant=%#v", actualStatus, expectedStatus)
}
}
func TestRemittanceServiceOp_GetBalance(t *testing.T) {
setup()
defer teardown()
expectedBalance := BalanceResponse{
AvailableBalance: "500",
Currency: "UGX",
}
mux.HandleFunc(remittancesBalanceURL, func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(expectedBalance)
w.WriteHeader(http.StatusOK)
testMethod(t, r, http.MethodGet)
})
actualBalance, err := client.Remittance.GetBalance(ctx)
if err != nil {
t.Fatalf("unexpected error %s", err)
}
if !reflect.DeepEqual(actualBalance, &expectedBalance) {
t.Errorf("GetBalance\n got=%#v\nwant=%#v", actualBalance, expectedBalance)
}
}
func TestRemittanceServiceOp_IsPayeeActive(t *testing.T) {
setup()
defer teardown()
mobileNumber := "256789997290"
urlStr := fmt.Sprintf("%s%s/active", remittancesIsAccountActiveURL, mobileNumber)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
testMethod(t, r, http.MethodGet)
})
_, err := client.Remittance.IsPayeeActive(ctx, mobileNumber)
if err != nil {
t.Fatalf("unexpected error %s", err)
}
}