-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic_test.go
80 lines (66 loc) · 1.95 KB
/
public_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
package mono_test
import (
"bytes"
"context"
"io/ioutil"
"net/http"
"testing"
mono "github.com/kudrykv/go-monobank-api"
)
var currencyResponseBody = `[
{
"currencyCodeA": 840,
"currencyCodeB": 980,
"date": 1552392228,
"rateSell": 27,
"rateBuy": 27.2,
"rateCross": 27.1
}
]`
var failResponseBody = `{
"errorDescription": "go away"
}`
var expectedCurrencyResponseBody = []mono.CurrencyInfo{{
CurrencyCodeAISO4217: 840,
CurrencyCodeBISO4217: 980,
Date: mono.Time(1552392228),
RateSell: 27,
RateBuy: 27.2,
RateCross: 27.1,
}}
func TestNewPublic_Domain(t *testing.T) {
client := &clienttest{}
client.Resp = &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte(currencyResponseBody))),
}
public := mono.NewPublic(mono.WithClient(client))
actual, err := public.Currency(context.Background())
expectNoError(t, err)
expectDeepEquals(t, actual, expectedCurrencyResponseBody)
expectEquals(t, client.Req.URL.Scheme, "https")
expectEquals(t, client.Req.URL.Host, "api.monobank.ua")
}
func TestPublic_Currency_Succ(t *testing.T) {
client := &clienttest{}
client.Resp = &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte(currencyResponseBody))),
}
ctx := context.Background()
public := mono.NewPublic(mono.WithDomain("https://domain"), mono.WithClient(client))
actual, err := public.Currency(ctx)
expectNoError(t, err)
expectDeepEquals(t, actual, expectedCurrencyResponseBody)
}
func TestPublic_Currency_FailMono(t *testing.T) {
client := &clienttest{}
client.Resp = &http.Response{
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(bytes.NewReader([]byte(failResponseBody))),
}
ctx := context.Background()
public := mono.NewPublic(mono.WithDomain("https://domain"), mono.WithClient(client))
_, err := public.Currency(ctx)
expectError(t, err, "mono error: go away")
}