-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhistorical_rates_test.go
56 lines (43 loc) · 1.53 KB
/
historical_rates_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
package dinero
import (
"reflect"
"testing"
"time"
. "github.com/onsi/gomega"
)
// TestHistoricalRates_List will test updating our local store of forex rates from the OXR API expecting rates for defaultCurrency for a historical date.
func TestHistoricalRates_List(t *testing.T) {
// Register the test.
NewWithT(t)
// Init dinero client.
client := NewClient(appID, defaultCurrency, 1*time.Minute)
historicalDate := time.Now().AddDate(0, -2, -5)
// Get latest forex rates.
response, err := client.HistoricalRates.List(historicalDate)
if err != nil {
t.Fatalf("Unexpected error running client.HistoricalRates.List(): %s", err)
}
if response.Base != defaultCurrency {
t.Fatalf("Unexpected base oxr rate: Expecting `%s`.", defaultCurrency)
}
if response.Rates == nil {
t.Fatal("Unexpected nil length of rates")
}
}
// TestHistoricalRate_Get will test pulling a single rate for defaultCurrency for a historical date.
func TestHistoricalRate_Get(t *testing.T) {
// Register the test.
NewWithT(t)
// Init dinero client.
client := NewClient(appID, defaultCurrency, 1*time.Minute)
historicalDate := time.Now().AddDate(0, -2, -5)
// Get latest forex rates for NZD (using defaultCurrency as a base).
response, err := client.HistoricalRates.Get("NZD", historicalDate)
if err != nil {
t.Fatalf("Unexpected error running client.HistoricalRates.Get('NZD'): %s", err)
}
// Did we get a *float64 back?
if reflect.TypeOf(response).String() != "*float64" {
t.Fatalf("Unexpected rate datatype, expected float64 got %T", response)
}
}