1
|
|
|
package smobilpay |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"net/http" |
6
|
|
|
"testing" |
7
|
|
|
|
8
|
|
|
"github.com/NdoleStudio/smobilpay-go/internal/helpers" |
9
|
|
|
"github.com/NdoleStudio/smobilpay-go/internal/stubs" |
10
|
|
|
"github.com/stretchr/testify/assert" |
11
|
|
|
) |
12
|
|
|
|
13
|
|
|
func TestBillService_Get(t *testing.T) { |
14
|
|
|
// Setup |
15
|
|
|
t.Parallel() |
16
|
|
|
|
17
|
|
|
// Arrange |
18
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.BillGet()) |
19
|
|
|
accessToken := "6B352110-4716-11ED-963F-0800200C9A66" |
20
|
|
|
client := New( |
21
|
|
|
WithBaseURL(server.URL), |
22
|
|
|
WithAccessToken(accessToken), |
23
|
|
|
WithAccessSecret("1B875FB0-4717-11ED-963F-0800200C9A66"), |
24
|
|
|
) |
25
|
|
|
nonce := "95cdf110-4614-4d95-b6c2-f14fe01c4995" |
26
|
|
|
params := &BillGetParams{ |
27
|
|
|
ServiceID: "10039", |
28
|
|
|
Merchant: "ENEO", |
29
|
|
|
ServiceNumber: "500000001", |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// Act |
33
|
|
|
bill, response, err := client.Bill.Get( |
34
|
|
|
context.Background(), |
35
|
|
|
params, |
36
|
|
|
WithRequestNonce(nonce), |
37
|
|
|
) |
38
|
|
|
|
39
|
|
|
// Assert |
40
|
|
|
assert.Nil(t, err) |
41
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
42
|
|
|
assert.Equal(t, 1, len(bill)) |
43
|
|
|
assert.Equal(t, params.ServiceID, bill[0].ServiceID) |
44
|
|
|
assert.Equal(t, params.Merchant, bill[0].Merchant) |
45
|
|
|
assert.Equal(t, params.ServiceNumber, bill[0].ServiceNumber) |
46
|
|
|
|
47
|
|
|
// Teardown |
48
|
|
|
server.Close() |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
func TestBillService_GetEmpty(t *testing.T) { |
52
|
|
|
// Setup |
53
|
|
|
t.Parallel() |
54
|
|
|
|
55
|
|
|
// Arrange |
56
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.BillEmpty()) |
57
|
|
|
accessToken := "6B352110-4716-11ED-963F-0800200C9A66" |
58
|
|
|
client := New( |
59
|
|
|
WithBaseURL(server.URL), |
60
|
|
|
WithAccessToken(accessToken), |
61
|
|
|
WithAccessSecret("1B875FB0-4717-11ED-963F-0800200C9A66"), |
62
|
|
|
) |
63
|
|
|
nonce := "95cdf110-4614-4d95-b6c2-f14fe01c4995" |
64
|
|
|
|
65
|
|
|
params := &BillGetParams{ |
66
|
|
|
ServiceID: "10039", |
67
|
|
|
Merchant: "ENEO", |
68
|
|
|
ServiceNumber: "500000001", |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// Act |
72
|
|
|
bills, _, err := client.Bill.Get( |
73
|
|
|
context.Background(), |
74
|
|
|
params, |
75
|
|
|
WithRequestNonce(nonce), |
76
|
|
|
) |
77
|
|
|
|
78
|
|
|
// Assert |
79
|
|
|
assert.Nil(t, err) |
80
|
|
|
assert.Equal(t, 0, len(bills)) |
81
|
|
|
|
82
|
|
|
// Teardown |
83
|
|
|
server.Close() |
84
|
|
|
} |
85
|
|
|
|