|
1
|
|
|
package afrikpay |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
"net/http" |
|
6
|
|
|
"testing" |
|
7
|
|
|
|
|
8
|
|
|
"github.com/NdoleStudio/afrikpay-go/internal/helpers" |
|
9
|
|
|
"github.com/NdoleStudio/afrikpay-go/internal/stubs" |
|
10
|
|
|
"github.com/stretchr/testify/assert" |
|
11
|
|
|
) |
|
12
|
|
|
|
|
13
|
|
|
func TestCashinService_MakeDeposit(t *testing.T) { |
|
14
|
|
|
// Arrange |
|
15
|
|
|
apiKey := "test-api-key" |
|
16
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.OrangeMoneyCashinResponse()) |
|
17
|
|
|
client := New(WithBaseURL(server.URL), WithAPIKey(apiKey)) |
|
18
|
|
|
input := &OrangeMoneyCashinPaymentRequest{ |
|
19
|
|
|
ReferenceNumber: "659683157", |
|
20
|
|
|
Amount: 1000, |
|
21
|
|
|
Email: "[email protected]", |
|
22
|
|
|
ExternalID: "224169cd-caa6-46d3-8262-eb95adb6b1d9", |
|
23
|
|
|
Description: "Orange Airtime Purchase", |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
// Act |
|
27
|
|
|
txn, response, err := client.OrangeMoneyCashin.MakeDeposit(context.Background(), input) |
|
28
|
|
|
|
|
29
|
|
|
// Assert |
|
30
|
|
|
assert.Nil(t, err) |
|
31
|
|
|
assert.False(t, txn.IsFailed()) |
|
32
|
|
|
assert.Equal(t, "1850489561706069", txn.Result.RequestID) |
|
33
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
func TestCashinService_MakeDepositWithError(t *testing.T) { |
|
37
|
|
|
// Arrange |
|
38
|
|
|
apiKey := "test-api-key" |
|
39
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.OrangeMoneyCashinErrorResponse()) |
|
40
|
|
|
client := New(WithBaseURL(server.URL), WithAPIKey(apiKey)) |
|
41
|
|
|
input := &OrangeMoneyCashinPaymentRequest{ |
|
42
|
|
|
ReferenceNumber: "659683157", |
|
43
|
|
|
Amount: 1000, |
|
44
|
|
|
Email: "[email protected]", |
|
45
|
|
|
ExternalID: "224169cd-caa6-46d3-8262-eb95adb6b1d9", |
|
46
|
|
|
Description: "Orange Airtime Purchase", |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Act |
|
50
|
|
|
txn, response, err := client.OrangeMoneyCashin.MakeDeposit(context.Background(), input) |
|
51
|
|
|
|
|
52
|
|
|
// Assert |
|
53
|
|
|
assert.Nil(t, err) |
|
54
|
|
|
assert.True(t, txn.IsFailed()) |
|
55
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
func TestCashinService_TransactionStatus(t *testing.T) { |
|
59
|
|
|
// Arrange |
|
60
|
|
|
apiKey := "test-api-key" |
|
61
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.OrangeMoneyCashinResponse()) |
|
62
|
|
|
client := New(WithBaseURL(server.URL), WithAPIKey(apiKey)) |
|
63
|
|
|
input := &TransactionStatusRequest{ |
|
64
|
|
|
ReferenceNumber: "659683157", |
|
65
|
|
|
Amount: 1000, |
|
66
|
|
|
ExternalID: "224169cd-caa6-46d3-8262-eb95adb6b1d9", |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// Act |
|
70
|
|
|
txn, response, err := client.OrangeMoneyCashin.TransactionStatus(context.Background(), input) |
|
71
|
|
|
|
|
72
|
|
|
// Assert |
|
73
|
|
|
assert.Nil(t, err) |
|
74
|
|
|
assert.False(t, txn.IsFailed()) |
|
75
|
|
|
assert.Equal(t, "1850489561706069", txn.Result.RequestID) |
|
76
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
|
77
|
|
|
} |
|
78
|
|
|
|