-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_test.go
170 lines (144 loc) · 4.56 KB
/
account_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package veritrans
import (
"fmt"
"log"
"os"
"testing"
"github.com/joho/godotenv"
assert "github.com/stretchr/testify/require"
)
var accountService *AccountService
func init() {
if err := godotenv.Load(); err != nil {
for _, envItem := range EnvVariables {
if os.Getenv(envItem) == "" {
log.Fatal("No env file for testing")
}
}
}
accountService = NewAccountService(ConnectionConfig{
MerchantCCID: os.Getenv("MERCHANT_CCID"),
MerchantPassword: os.Getenv("MERCHANT_PASSWORD"),
AccountAPIURL: os.Getenv("ACCOUNT_API_URL"),
TxnVersion: os.Getenv("TXN_VERSION"),
DummyRequest: os.Getenv("DUMMY_REQUEST"),
})
}
func TestAccount(t *testing.T) {
testAccountID := "TEST_ACCOUNT_1"
accountParam := &AccountParam{
AccountID: testAccountID,
}
// Get Account
account, err := accountService.GetAccount(accountParam)
if err == nil {
// Assert if the account exists
assert.Equal(t, testAccountID, account.AccountID)
} else {
assert.Equal(t, "未登録の会員です。", err.Error())
account, err := accountService.CreateAccount(accountParam)
// Create if the account doesn't exist
assert.Nil(t, err)
assert.Equal(t, testAccountID, account.AccountID)
}
fmt.Println("Create Account Passed")
// Remove account
account, err = accountService.DeleteAccount(accountParam)
assert.Nil(t, err)
assert.Equal(t, testAccountID, account.AccountID)
fmt.Println("Remove Account Passed")
// Restore account
account, err = accountService.RestoreAccount(accountParam)
assert.Nil(t, err)
assert.Equal(t, testAccountID, account.AccountID)
fmt.Println("Restore Account Passed")
}
func TestCard(t *testing.T) {
testAccountID := "TEST_ACCOUNT_2"
accountParam := &AccountParam{
AccountID: testAccountID,
}
// Get Account
account, err := accountService.GetAccount(accountParam)
if err == nil {
// Assert if the account exists
assert.Equal(t, testAccountID, account.AccountID)
} else {
assert.Equal(t, "未登録の会員です。", err.Error())
account, err := accountService.CreateAccount(accountParam)
// Create if the account doesn't exist
assert.Nil(t, err)
assert.Equal(t, testAccountID, account.AccountID)
}
// Add Card
firstTestCardNumber := "4111111111111111"
firstExpectedCardNumber := "411111********11"
expiredAt := GetAfterOneMonth()
accountParam.CardParam = &CardParam{
CardNumber: firstTestCardNumber,
CardExpire: expiredAt,
DefaultCard: "1",
}
account, err = accountService.CreateCard(accountParam)
assert.Nil(t, err)
assert.Equal(t, 1, len(account.CardInfo))
fmt.Println("Add The First Card Passed")
// Get Cards
accountParam.CardParam = nil
account, err = accountService.GetCard(accountParam)
assert.Nil(t, err)
assert.Equal(t, 1, len(account.CardInfo))
assert.Equal(t, firstExpectedCardNumber, account.CardInfo[0].CardNumber)
assert.Equal(t, "1", account.CardInfo[0].DefaultCard)
assert.Equal(t, expiredAt, account.CardInfo[0].CardExpire)
fmt.Println("Get Card Passed")
firstCardID := account.CardInfo[0].CardID
// Add another card
secondTestCardNumber := "5555555555554444"
secondExpectedCardNumber := "555555********44"
accountParam.CardParam = &CardParam{
CardNumber: secondTestCardNumber,
CardExpire: expiredAt,
DefaultCard: "0",
}
account, err = accountService.CreateCard(accountParam)
assert.Nil(t, err)
secondCardID := account.CardInfo[0].CardID
fmt.Println("Add The Second Card Passed")
// Get Cards
accountParam.CardParam = nil
account, err = accountService.GetCard(accountParam)
assert.Nil(t, err)
assert.Equal(t, 2, len(account.CardInfo))
assert.Equal(t, secondExpectedCardNumber, account.CardInfo[1].CardNumber)
assert.Equal(t, "0", account.CardInfo[1].DefaultCard)
// Update Card
newExpiredAt := GetAfterOneYear()
accountParam.CardParam = &CardParam{
CardID: secondCardID,
DefaultCard: "1",
CardExpire: newExpiredAt,
}
account, err = accountService.UpdateCard(accountParam)
assert.Nil(t, err)
assert.Equal(t, secondExpectedCardNumber, account.CardInfo[0].CardNumber)
assert.Equal(t, newExpiredAt, account.CardInfo[0].CardExpire)
assert.Equal(t, "1", account.CardInfo[0].DefaultCard)
// Remove Two Cards
accountParam.CardParam = &CardParam{
CardID: firstCardID,
}
_, err = accountService.DeleteCard(accountParam)
assert.Nil(t, err)
accountParam.CardParam = &CardParam{
CardID: secondCardID,
}
_, err = accountService.DeleteCard(accountParam)
assert.Nil(t, err)
// Get Cards
accountParam.CardParam = nil
account, err = accountService.GetCard(accountParam)
assert.Nil(t, err)
assert.Equal(t, 0, len(account.CardInfo))
fmt.Println("Remove Card Passed")
}