-
Notifications
You must be signed in to change notification settings - Fork 3
/
forex_test.go
123 lines (109 loc) · 3 KB
/
forex_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
package goiex
import (
"log"
"net/http"
"testing"
"github.com/dnaeon/go-vcr/recorder"
)
func TestNewForex(t *testing.T) {
fx := NewForex("test_token", "", sandboxURL, nil)
expected = "https://sandbox.iexapis.com/"
actual = fx.URL().String()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "fx/"
actual = fx.APIURL().String()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
expected = "test_token"
actual = fx.Token()
if expected != actual {
t.Errorf("\nExpected: %s\nActual: %s\n", expected, actual)
}
}
func TestLatestCurrencyRates(t *testing.T) {
rec, err := recorder.New("cassettes/forex/latest_currency_rates")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
cli := NewForex(testToken, DefaultVersion, sandboxURL, httpClient)
lcr, err := cli.LatestCurrencyRates(&LatestCurrencyRatesParams{Symbols: "USDCAD,USDGBP,USDJPY"})
if err != nil {
t.Error(err)
}
expected = false
actual = len(lcr) == 0
if expected != actual {
t.Errorf("\nExpected: %v\nActual: %v\n", expected, actual)
}
}
func TestCurrencyConversion(t *testing.T) {
rec, err := recorder.New("cassettes/forex/currency_conversion")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
cli := NewForex(testToken, DefaultVersion, sandboxURL, httpClient)
cc, err := cli.CurrencyConversion(&CurrencyConversionParams{Symbols: "USDCAD,USDGBP,USDJPY", Amount: 73})
if err != nil {
t.Error(err)
}
expected = false
actual = len(cc) == 0
if expected != actual {
t.Errorf("\nExpected: %v\nActual: %v\n", expected, actual)
}
}
func TestHistoricalDaily(t *testing.T) {
rec, err := recorder.New("cassettes/forex/historical_daily")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
cli := NewForex(testToken, DefaultVersion, sandboxURL, httpClient)
hd, err := cli.HistoricalDaily(&HistoricalDailyParams{Symbols: "USDCAD,USDGBP,USDJPY", From: "2019-10-24", To: "2019-10-25", Last: 5})
if err != nil {
t.Error(err)
}
expected = false
actual = len(hd) == 0
if expected != actual {
t.Errorf("\nExpected: %v\nActual: %v\n", expected, actual)
}
}
func TestExchangeRates(t *testing.T) {
rec, err := recorder.New("cassettes/forex/exchange_rates")
if err != nil {
log.Fatal(err)
} else {
rec.SetMatcher(matchWithoutToken)
httpClient = &http.Client{Transport: rec}
}
rec.AddFilter(removeToken)
defer rec.Stop()
cli := NewForex(testToken, DefaultVersion, sandboxURL, httpClient)
er, err := cli.ExchangeRates("eur", "usd")
if err != nil {
t.Error(err)
}
expected = "RUE"
actual = er.FromCurrency
if expected != actual {
t.Errorf("\nExpected: %v\nActual: %v\n", expected, actual)
}
}