1
|
|
|
package afrikpay |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"net/http" |
5
|
|
|
"testing" |
6
|
|
|
|
7
|
|
|
"github.com/go-faker/faker/v4" |
8
|
|
|
"github.com/stretchr/testify/assert" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
func TestWithHTTPClient(t *testing.T) { |
12
|
|
|
t.Run("httpClient is not set when the httpClient is nil", func(t *testing.T) { |
13
|
|
|
// Setup |
14
|
|
|
t.Parallel() |
15
|
|
|
|
16
|
|
|
// Arrange |
17
|
|
|
config := defaultClientConfig() |
18
|
|
|
|
19
|
|
|
// Act |
20
|
|
|
WithHTTPClient(nil).apply(config) |
21
|
|
|
|
22
|
|
|
// Assert |
23
|
|
|
assert.NotNil(t, config.httpClient) |
24
|
|
|
}) |
25
|
|
|
|
26
|
|
|
t.Run("httpClient is set when the httpClient is not nil", func(t *testing.T) { |
27
|
|
|
// Setup |
28
|
|
|
t.Parallel() |
29
|
|
|
|
30
|
|
|
// Arrange |
31
|
|
|
config := defaultClientConfig() |
32
|
|
|
newClient := &http.Client{Timeout: 300} |
33
|
|
|
|
34
|
|
|
// Act |
35
|
|
|
WithHTTPClient(newClient).apply(config) |
36
|
|
|
|
37
|
|
|
// Assert |
38
|
|
|
assert.NotNil(t, config.httpClient) |
39
|
|
|
assert.Equal(t, newClient.Timeout, config.httpClient.Timeout) |
40
|
|
|
}) |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
func TestWithBaseURL(t *testing.T) { |
44
|
|
|
t.Run("baseURL is set successfully", func(t *testing.T) { |
45
|
|
|
// Setup |
46
|
|
|
t.Parallel() |
47
|
|
|
|
48
|
|
|
// Arrange |
49
|
|
|
baseURL := "https://example.com" |
50
|
|
|
config := defaultClientConfig() |
51
|
|
|
|
52
|
|
|
// Act |
53
|
|
|
WithBaseURL(baseURL).apply(config) |
54
|
|
|
|
55
|
|
|
// Assert |
56
|
|
|
assert.Equal(t, config.baseURL, config.baseURL) |
57
|
|
|
}) |
58
|
|
|
|
59
|
|
|
t.Run("tailing / is trimmed from baseURL", func(t *testing.T) { |
60
|
|
|
// Setup |
61
|
|
|
t.Parallel() |
62
|
|
|
|
63
|
|
|
// Arrange |
64
|
|
|
baseURL := "https://example.com/" |
65
|
|
|
config := defaultClientConfig() |
66
|
|
|
|
67
|
|
|
// Act |
68
|
|
|
WithBaseURL(baseURL).apply(config) |
69
|
|
|
|
70
|
|
|
// Assert |
71
|
|
|
assert.Equal(t, "https://example.com", config.baseURL) |
72
|
|
|
}) |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
func TestWithAPIKey(t *testing.T) { |
76
|
|
|
t.Run("apiKey is set successfully", func(t *testing.T) { |
77
|
|
|
// Setup |
78
|
|
|
t.Parallel() |
79
|
|
|
|
80
|
|
|
// Arrange |
81
|
|
|
config := defaultClientConfig() |
82
|
|
|
apiKey := "test-key" |
83
|
|
|
|
84
|
|
|
// Act |
85
|
|
|
WithAPIKey(apiKey).apply(config) |
86
|
|
|
|
87
|
|
|
// Assert |
88
|
|
|
assert.Equal(t, apiKey, config.apiKey) |
89
|
|
|
}) |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
func TestWithWalletUsername(t *testing.T) { |
93
|
|
|
t.Run("wallet username is set successfully", func(t *testing.T) { |
94
|
|
|
// Setup |
95
|
|
|
t.Parallel() |
96
|
|
|
|
97
|
|
|
// Arrange |
98
|
|
|
config := defaultClientConfig() |
99
|
|
|
walletUsername := faker.Username() |
100
|
|
|
|
101
|
|
|
// Act |
102
|
|
|
WithWalletUsername(walletUsername).apply(config) |
103
|
|
|
|
104
|
|
|
// Assert |
105
|
|
|
assert.Equal(t, walletUsername, config.walletUsername) |
106
|
|
|
}) |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
func TestWithWalletPassword(t *testing.T) { |
110
|
|
|
t.Run("wallet password is set successfully", func(t *testing.T) { |
111
|
|
|
// Setup |
112
|
|
|
t.Parallel() |
113
|
|
|
|
114
|
|
|
// Arrange |
115
|
|
|
config := defaultClientConfig() |
116
|
|
|
walletPassword := faker.Password() |
117
|
|
|
|
118
|
|
|
// Act |
119
|
|
|
WithWalletPassword(walletPassword).apply(config) |
120
|
|
|
|
121
|
|
|
// Assert |
122
|
|
|
assert.Equal(t, walletPassword, config.walletPassword) |
123
|
|
|
}) |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
func TestWithWalletPin(t *testing.T) { |
127
|
|
|
t.Run("wallet pin is set successfully", func(t *testing.T) { |
128
|
|
|
// Setup |
129
|
|
|
t.Parallel() |
130
|
|
|
|
131
|
|
|
// Arrange |
132
|
|
|
config := defaultClientConfig() |
133
|
|
|
walletPin := faker.YearString() |
134
|
|
|
|
135
|
|
|
// Act |
136
|
|
|
WithWalletPin(walletPin).apply(config) |
137
|
|
|
|
138
|
|
|
// Assert |
139
|
|
|
assert.Equal(t, walletPin, config.walletPin) |
140
|
|
|
}) |
141
|
|
|
} |
142
|
|
|
|