-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaccount_test.go
116 lines (102 loc) · 2.65 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
package goiex
import (
"log"
"net/http"
"testing"
"github.com/dnaeon/go-vcr/recorder"
)
func TestNewAccount(t *testing.T) {
acc := NewAccount("test_token", "stable", sandboxURL, nil)
expected = "account/"
actual = acc.APIURL().String()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = true
actual = acc.Client() == nil
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "test_token"
actual = acc.Token()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "https://sandbox.iexapis.com/"
actual = acc.URL().String()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "stable"
actual = acc.Version()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
}
func TestMetadata(t *testing.T) {
rec, err := recorder.New("cassettes/account/metadata")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
cli := NewAccount(testToken, DefaultVersion, sandboxURL, httpClient)
metadata, err := cli.Metadata()
if err != nil {
t.Error(err)
}
if metadata == nil {
t.Errorf("\nExpected metadata to be not nil\n")
}
expected = "alnnua"
actual = metadata.SubscriptionTermType
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
}
func TestUsage(t *testing.T) {
rec, err := recorder.New("cassettes/account/usage")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
cli := NewAccount(testToken, DefaultVersion, sandboxURL, httpClient)
usage, err := cli.Usage()
if err != nil {
t.Error(err)
}
if usage.Messages.MonthlyUsage < 1 {
t.Errorf("\nExpected MonthlyUsage > 0 but got: %d\n", usage.Messages.MonthlyUsage)
}
expected = "4"
if actual = usage.Messages.DailyUsage.(map[string]interface{})["20191021"]; actual != expected {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
}
// TODO: fix mock server usage
// func TestPayasyougo(t *testing.T) {
// _, err := mockClient.Payasyougo(map[string]string{
// "token": "my_token",
// "allow": "false",
// })
// if err != nil {
// t.Error(err)
// }
// }
//
// func TestMessageBudget(t *testing.T) {
// _, err := mockClient.MessageBudget(map[string]string{
// "token": "my_token",
// "totalMessages": "500000",
// })
// if err != nil {
// t.Error(err)
// }
// }