-
Notifications
You must be signed in to change notification settings - Fork 0
/
accounts_test.go
77 lines (69 loc) · 2.74 KB
/
accounts_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
package togai_test
import (
"fmt"
"math/rand"
"os"
"testing"
"github.com/karuppiah7890/go-togai"
)
func TestAccounts(t *testing.T) {
apiBaseUrl := os.Getenv("API_BASE_URL")
apiToken := os.Getenv("API_TOKEN")
c, err := togai.NewTogaiClient(apiBaseUrl, apiToken)
if err != nil {
t.Fatalf("expected no error while creating togai client but an error occurred: %v", err)
}
t.Run("create account", func(t *testing.T) {
randomNumber := rand.Int()
customer := dummyCustomerWithAccount(randomNumber)
// TODO: Check if the output response fields and input request fields match, and that response also has
// some expected values like status as ACTIVE for account and account alias
_, err := c.CreateCustomer(customer)
if err != nil {
t.Fatalf("expected no error while creating customer but an error occurred: %v", err)
}
anotherRandomNumber := rand.Int()
account := dummyAccount(anotherRandomNumber)
// TODO: Check if the output response fields and input request fields match, and that response also has
// some expected values like status as ACTIVE for account and account alias
_, err = c.CreateAccount(customer.Id, account)
if err != nil {
t.Fatalf("expected no error while creating account but an error occurred: %v", err)
}
})
t.Run("delete account", func(t *testing.T) {
randomNumber := rand.Int()
customer := dummyCustomerWithAccount(randomNumber)
// TODO: Check if the output response fields and input request fields match, and that response also has
// some expected values like status as ACTIVE for account and account alias
_, err := c.CreateCustomer(customer)
if err != nil {
t.Fatalf("expected no error while creating customer but an error occurred: %v", err)
}
anotherRandomNumber := rand.Int()
account := dummyAccount(anotherRandomNumber)
// TODO: Check if the output response fields and input request fields match, and that response also has
// some expected values like status as ACTIVE for account and account alias
_, err = c.CreateAccount(customer.Id, account)
if err != nil {
t.Fatalf("expected no error while creating account but an error occurred: %v", err)
}
})
}
func dummyAccount(randomNumber int) togai.Account {
return togai.Account{
Id: fmt.Sprintf("test-account-%d", randomNumber),
Name: fmt.Sprintf("Test Account %d", randomNumber),
InvoiceCurrency: "USD",
Aliases: []string{fmt.Sprintf("test-account-%d", randomNumber)},
Settings: []togai.Setting{
{
Id: fmt.Sprintf("dummy-account-setting-%d", randomNumber),
Name: fmt.Sprintf("Dummy Account Setting %d", randomNumber),
Namespace: togai.UserNamespace,
Value: fmt.Sprintf("something %d", randomNumber),
DataType: togai.StringSettingDataType,
},
},
}
}