This repository has been archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
price_test.go
138 lines (103 loc) · 3.24 KB
/
price_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
package cryptocomparego
import (
"errors"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestFormattedQueryStringNilPriceRequest(t *testing.T) {
priceRequest := NewPriceRequest("", nil)
acct := priceRequest.FormattedQueryString("/data/price")
expected := "/data/price?e=CCCAGG&sign=false&tryConversion=true"
if acct != expected {
t.Errorf("PriceRequest.FormattedQueryString returned %+v, expected %+v", acct, expected)
}
}
func TestFormattedQueryStringPriceRequest(t *testing.T) {
priceRequest := NewPriceRequest("ETH", []string{"BTC", "USD", "EUR"})
acct := priceRequest.FormattedQueryString("/data/price")
expected := "/data/price?e=CCCAGG&fsym=ETH&sign=false&tryConversion=true&tsyms=BTC%2CUSD%2CEUR"
if acct != expected {
t.Errorf("PriceRequest.FormattedQueryString returned %+v, expected %+v", acct, expected)
}
}
func TestPriceListNilPriceRequest(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/price", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
if r.URL.Query().Get("fsym") != "" || r.URL.Query().Get("tsyms") != "" {
t.Errorf("Price.List did not request the correct fsym or tsyms")
}
response := `
{
"BTC": 0.04502,
"EUR": 313.82,
"USD": 368.87
}`
fmt.Fprint(w, response)
})
acct, _, err := client.Price.List(ctx, nil)
if err != nil {
t.Errorf("Price.List returned error: %v", err)
}
expected := []Price{{"BTC", 0.04502}, {"EUR", 313.82}, {"USD", 368.87}}
if !reflect.DeepEqual(acct, expected) {
t.Errorf("Price.List returned %+v, expected %+v", acct, expected)
}
}
func TestPriceListWrongPriceRequest(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/price", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
if r.URL.Query().Get("fsym") != "ETH" || r.URL.Query().Get("tsyms") != "" {
t.Errorf("Price.List did not request the correct fsym or tsyms")
}
response := `
{
"Response": "Error",
"Message": "tsyms param seems to be missing.",
"Type": 1,
"Aggregated": false,
"Data": []
}`
fmt.Fprint(w, response)
})
priceRequest := NewPriceRequest("ETH", nil)
acct, _, err := client.Price.List(ctx, priceRequest)
if acct != nil {
t.Errorf("Price.List returned a value: %v", err)
}
expected := errors.New("tsyms param seems to be missing.")
if !reflect.DeepEqual(err, expected) {
t.Errorf("Price.List returned %+v, expected %+v", acct, expected)
}
}
func TestPriceList(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/data/price", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
if r.URL.Query().Get("fsym") != "ETH" || r.URL.Query().Get("tsyms") != "BTC,USD,EUR" {
t.Errorf("Price.List did not request the correct fsym or tsyms")
}
response := `
{
"BTC": 0.04502,
"EUR": 313.82,
"USD": 368.87
}`
fmt.Fprint(w, response)
})
priceRequest := &PriceRequest{Fsym: "ETH", Tsyms: []string{"BTC", "USD", "EUR"}}
acct, _, err := client.Price.List(ctx, priceRequest)
if err != nil {
t.Errorf("Price.List returned error: %v", err)
}
expected := []Price{{"BTC", 0.04502}, {"EUR", 313.82}, {"USD", 368.87}}
if !reflect.DeepEqual(acct, expected) {
t.Errorf("Price.List returned %+v, expected %+v", acct, expected)
}
}