|
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 TestProductService_Get(t *testing.T) { |
|
14
|
|
|
// Setup |
|
15
|
|
|
t.Parallel() |
|
16
|
|
|
|
|
17
|
|
|
// Arrange |
|
18
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.CashinGetOk()) |
|
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
|
|
|
serviceID := "30052" |
|
27
|
|
|
|
|
28
|
|
|
// Act |
|
29
|
|
|
payItems, response, err := client.Product.Get( |
|
30
|
|
|
context.Background(), |
|
31
|
|
|
serviceID, |
|
32
|
|
|
WithRequestNonce(nonce), |
|
33
|
|
|
) |
|
34
|
|
|
|
|
35
|
|
|
// Assert |
|
36
|
|
|
assert.Nil(t, err) |
|
37
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
|
38
|
|
|
assert.Equal(t, 1, len(payItems)) |
|
39
|
|
|
assert.Equal(t, serviceID, payItems[0].ServiceID) |
|
40
|
|
|
|
|
41
|
|
|
// Teardown |
|
42
|
|
|
server.Close() |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
func TestProductService_GetError(t *testing.T) { |
|
46
|
|
|
// Setup |
|
47
|
|
|
t.Parallel() |
|
48
|
|
|
|
|
49
|
|
|
// Arrange |
|
50
|
|
|
server := helpers.MakeTestServer(http.StatusBadRequest, stubs.CashinGetError()) |
|
51
|
|
|
accessToken := "6B352110-4716-11ED-963F-0800200C9A66" |
|
52
|
|
|
client := New( |
|
53
|
|
|
WithBaseURL(server.URL), |
|
54
|
|
|
WithAccessToken(accessToken), |
|
55
|
|
|
WithAccessSecret("1B875FB0-4717-11ED-963F-0800200C9A66"), |
|
56
|
|
|
) |
|
57
|
|
|
nonce := "95cdf110-4614-4d95-b6c2-f14fe01c4995" |
|
58
|
|
|
serviceID := "30052" |
|
59
|
|
|
|
|
60
|
|
|
// Act |
|
61
|
|
|
payItems, response, err := client.Product.Get( |
|
62
|
|
|
context.Background(), |
|
63
|
|
|
serviceID, |
|
64
|
|
|
WithRequestNonce(nonce), |
|
65
|
|
|
) |
|
66
|
|
|
|
|
67
|
|
|
// Assert |
|
68
|
|
|
assert.NotNil(t, err) |
|
69
|
|
|
assert.Equal(t, http.StatusBadRequest, response.HTTPResponse.StatusCode) |
|
70
|
|
|
assert.Equal(t, 0, len(payItems)) |
|
71
|
|
|
|
|
72
|
|
|
// Teardown |
|
73
|
|
|
server.Close() |
|
74
|
|
|
} |
|
75
|
|
|
|