-
Notifications
You must be signed in to change notification settings - Fork 5
/
mpesa_test.go
80 lines (77 loc) · 1.65 KB
/
mpesa_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
package ravepay
import (
"reflect"
"testing"
)
func TestMpesaPaymentInstruction(t *testing.T) {
type args struct {
cr *ChargeResponse
}
tests := []struct {
name string
args args
want *MpesaPaymentInfo
}{
{
name: "returns the mpesa payment info-1",
args: args{
cr: &ChargeResponse{
Data: chargeResponseData{
Amount: 900,
OrderRef: "some-ref",
BusinessNumber: "some-biz-num",
},
},
},
want: &MpesaPaymentInfo{
Amount: 900,
AccountNumber: "some-ref",
BusinessNumber: "some-biz-num",
},
},
{
name: "returns the mpesa payment info-2",
args: args{
cr: &ChargeResponse{},
},
want: &MpesaPaymentInfo{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MpesaPaymentInstruction(tt.args.cr); !reflect.DeepEqual(got, tt.want) {
t.Errorf("MpesaPaymentInstruction() = %v, want %v", got, tt.want)
}
})
}
}
func TestMpesa_ChargeURL(t *testing.T) {
type fields struct {
ChargeMpesaURL string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "returns the ChargeMpesaURL in the mpesa object if present",
fields: fields{"https://charge.mpesa.url"},
want: "https://charge.mpesa.url",
},
{
name: "set's the object ChargeMpesaURL to config's defaultChargeURL and returns it",
want: baseURL + defaultChargeURL,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &Mpesa{
ChargeMpesaURL: tt.fields.ChargeMpesaURL,
}
if got := m.ChargeURL(); got != tt.want {
t.Errorf("Mpesa.ChargeURL() = %v, want %v", got, tt.want)
}
})
}
}