-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
115 lines (105 loc) · 2.56 KB
/
client_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package xsolla
import (
"os"
"strconv"
"testing"
"time"
)
func newTestClient() *Client {
merchantId, _ := strconv.Atoi(os.Getenv("MerchantId"))
projectId, _ := strconv.Atoi(os.Getenv("ProjectId"))
return &Client{
MerchantId: merchantId,
MerchantSecret: os.Getenv("MerchantSecret"),
ProjectId: projectId,
ProjectSecret: os.Getenv("ProjectSecret"),
Sandbox: true,
Timeout: time.Second * 10,
}
}
func newTestAttribute() M {
return M{
"key": "13",
"list_of_values": M{},
"name": M{
"en": "rating",
},
"type": "int",
}
}
func TestClient_GetSubscriptionUserId(t *testing.T) {
testClient := newTestClient()
id := os.Getenv("testSubscriptionUserId")
userId, err := testClient.GetSubscriptionUserId(id)
if err != nil {
t.Fatal(err)
}
if userId == "" {
t.Fatal("Returned userId was nil")
}
}
func TestClient_GetSubscription(t *testing.T) {
projectId, _ := strconv.Atoi(os.Getenv("TestClientProjectId"))
subscriptionId, _ := strconv.Atoi(os.Getenv("SubscriptionId"))
testClient := newTestClient()
testClient.ProjectId = projectId
resPayLoad, err := testClient.GetSubscription(subscriptionId)
if err != nil {
t.Fatal(err)
}
if resPayLoad == nil {
t.Fatal("Subscription was nil")
}
}
func TestClient_GetUser(t *testing.T) {
testClient := newTestClient()
var user *User
var err error
user, err = testClient.GetUser(os.Getenv("TestUserId"))
if err != nil {
t.Fatal(err)
}
if user == nil {
t.Fatal("User is nill")
}
}
func TestClient_GetTransaction(t *testing.T) {
testClient := newTestClient()
id := os.Getenv("TestClientId")
transaction, err := testClient.GetTransaction(id)
if err != nil {
t.Fatal(err)
}
if transaction == nil {
t.Fatal("Transaction is nil")
}
}
func TestClient_UpdateSubscription(t *testing.T) {
subscriptionID, _ := strconv.Atoi(os.Getenv("SubscriptionId"))
userID := os.Getenv("TestUserId")
testClient := newTestClient()
res, err := testClient.UpdateSubscription(userID, subscriptionID, StatusCanceled)
if err != nil {
t.Fatal(err)
}
if res == nil {
t.Fatal("Subscription is nil, update subscription failed")
}
if res.Status != "canceled" {
t.Fatal("Update subscription did not go through, please try again")
}
}
func TestClient_CreateToken(t *testing.T) {
var utm, attr M
client := newTestClient()
token := &Token{
User: NewUserData("user_2", "[email protected]", "", utm, attr),
Settings: client.NewTokenSettings(),
}
str, err := client.CreateToken(token)
if err != nil {
t.Fatal(err)
} else if str == "" {
t.Fatal("Token response was empty")
}
}