-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
conversions_test.go
96 lines (77 loc) · 3.29 KB
/
conversions_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
package bsvrates
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
// TestClient_GetConversion will test the method GetConversion()
func TestClient_GetConversion(t *testing.T) {
t.Parallel()
t.Run("valid get conversion - default", func(t *testing.T) {
client := newMockClient(&mockWOCValid{}, &mockPaprikaValid{})
assert.NotNil(t, client)
satoshis, provider, err := client.GetConversion(context.Background(), CurrencyDollars, 1)
assert.NoError(t, err)
assert.Equal(t, int64(633157), satoshis)
assert.Equal(t, true, provider.IsValid())
assert.Equal(t, "CoinPaprika", provider.Name())
})
t.Run("valid get conversion - whats on chain", func(t *testing.T) {
client := newMockClient(&mockWOCValid{}, &mockPaprikaValid{}, ProviderWhatsOnChain)
assert.NotNil(t, client)
satoshis, provider, err := client.GetConversion(context.Background(), CurrencyDollars, 1)
assert.NoError(t, err)
assert.Equal(t, int64(628892), satoshis)
assert.Equal(t, true, provider.IsValid())
assert.Equal(t, "WhatsOnChain", provider.Name())
})
t.Run("valid get conversion - coin paprika", func(t *testing.T) {
client := newMockClient(&mockWOCValid{}, &mockPaprikaValid{}, ProviderCoinPaprika)
assert.NotNil(t, client)
satoshis, provider, err := client.GetConversion(context.Background(), CurrencyDollars, 1)
assert.NoError(t, err)
assert.Equal(t, int64(633157), satoshis)
assert.Equal(t, true, provider.IsValid())
assert.Equal(t, "CoinPaprika", provider.Name())
})
t.Run("valid get conversion - custom provider list", func(t *testing.T) {
client := newMockClient(&mockWOCValid{}, &mockPaprikaValid{}, ProviderCoinPaprika, ProviderWhatsOnChain)
assert.NotNil(t, client)
satoshis, provider, err := client.GetConversion(context.Background(), CurrencyDollars, 1)
assert.NoError(t, err)
assert.NotEqual(t, 633157, satoshis)
assert.Equal(t, true, provider.IsValid())
assert.Equal(t, "CoinPaprika", provider.Name())
})
t.Run("non accepted currency", func(t *testing.T) {
client := newMockClient(&mockWOCValid{}, &mockPaprikaFailed{})
assert.NotNil(t, client)
_, _, rateErr := client.GetConversion(context.Background(), 123, 1)
assert.Error(t, rateErr)
})
t.Run("failed conversion - default", func(t *testing.T) {
client := newMockClient(&mockWOCValid{}, &mockPaprikaFailed{})
assert.NotNil(t, client)
satoshis, provider, err := client.GetConversion(context.Background(), CurrencyDollars, 1)
assert.NoError(t, err)
assert.Equal(t, int64(628892), satoshis)
assert.Equal(t, true, provider.IsValid())
assert.Equal(t, "WhatsOnChain", provider.Name())
})
t.Run("failed conversion - whats on chain", func(t *testing.T) {
client := newMockClient(&mockWOCFailed{}, &mockPaprikaValid{})
assert.NotNil(t, client)
satoshis, provider, err := client.GetConversion(context.Background(), CurrencyDollars, 1)
assert.NoError(t, err)
assert.Equal(t, int64(633157), satoshis)
assert.Equal(t, true, provider.IsValid())
assert.Equal(t, "CoinPaprika", provider.Name())
})
t.Run("failed conversion - all providers", func(t *testing.T) {
client := newMockClient(&mockWOCFailed{}, &mockPaprikaFailed{})
assert.NotNil(t, client)
satoshis, _, err := client.GetConversion(context.Background(), CurrencyDollars, 1)
assert.Error(t, err)
assert.Equal(t, int64(0), satoshis)
})
}