@@ -5,6 +5,12 @@ const test = require('tape')
5
5
global . fetch = require ( 'node-fetch' )
6
6
const cc = require ( '../' )
7
7
8
+ // NOT_USD_TRADABLE is a cryptocurrency which does not trade directly with USD.
9
+ // This value is used in testing tryConversion. Currently, this is set to LTD.
10
+ // If LTD trades directly with USD in the future, tests will fail.
11
+ // In that case, change this value:
12
+ const NOT_USD_TRADABLE = 'LTD'
13
+
8
14
test ( 'price()' , t => {
9
15
t . plan ( 2 )
10
16
cc . price ( 'BTC' , [ 'USD' , 'EUR' ] ) . then ( prices => {
@@ -23,13 +29,7 @@ test('price() allows passing a string as the second parameter', t => {
23
29
} )
24
30
25
31
test ( "price()'s tryConversion=false works" , t => {
26
- t . plan ( 1 )
27
- cc . price ( 'LTD' , 'USD' , false ) . then ( prices => {
28
- t . end ( 'Promise should not resolve' )
29
- } ) . catch ( e => {
30
- t . ok ( e . match ( / m a r k e t d o e s n o t e x i s t / i) , 'Converting LTD to USD fails' )
31
- t . end ( )
32
- } ) . catch ( t . end )
32
+ testTryConversion ( cc . price ( NOT_USD_TRADABLE , 'USD' , false ) , t )
33
33
} )
34
34
35
35
test ( 'priceMulti()' , t => {
@@ -51,6 +51,10 @@ test('priceMulti() allows passing strings instead of arrays', t => {
51
51
} ) . catch ( t . end )
52
52
} )
53
53
54
+ test ( "priceMulti()'s tryConversion=false works" , t => {
55
+ testTryConversion ( cc . priceMulti ( NOT_USD_TRADABLE , 'USD' , false ) , t )
56
+ } )
57
+
54
58
test ( 'priceFull()' , t => {
55
59
t . plan ( 5 * 2 * 2 )
56
60
cc . priceFull ( [ 'BTC' , 'ETH' ] , [ 'USD' , 'EUR' ] ) . then ( prices => {
@@ -81,6 +85,10 @@ test('priceFull() allows passing strings instead of arrays', t => {
81
85
} ) . catch ( t . end )
82
86
} )
83
87
88
+ test ( "priceFull()'s tryConversion=false works" , t => {
89
+ testTryConversion ( cc . priceFull ( NOT_USD_TRADABLE , 'USD' , false ) , t )
90
+ } )
91
+
84
92
test ( 'priceHistorical()' , t => {
85
93
t . plan ( 3 )
86
94
// NOTE: Historical values are hard-coded into this test
@@ -94,15 +102,8 @@ test('priceHistorical()', t => {
94
102
} )
95
103
96
104
test ( "priceHistorical()'s tryConversion=false works" , t => {
97
- t . plan ( 1 )
98
- // NOTE: Historical values are hard-coded into this test
99
105
const timestamp = new Date ( '2017-01-01' )
100
- cc . priceHistorical ( 'LTD' , 'USD' , timestamp , false ) . then ( prices => {
101
- t . end ( 'Promise should not resolve' )
102
- } ) . catch ( e => {
103
- t . ok ( e . match ( / m a r k e t d o e s n o t e x i s t / i) , 'Converting LTD to USD fails' )
104
- t . end ( )
105
- } ) . catch ( t . end )
106
+ testTryConversion ( cc . priceHistorical ( NOT_USD_TRADABLE , 'USD' , timestamp , false ) , t )
106
107
} )
107
108
108
109
test ( 'error handling' , t => {
@@ -113,3 +114,15 @@ test('error handling', t => {
113
114
t . end ( )
114
115
} ) . catch ( t . end )
115
116
} )
117
+
118
+ // Helper Functions:
119
+
120
+ function testTryConversion ( promise , t ) {
121
+ t . plan ( 1 )
122
+ promise . then ( prices => {
123
+ t . end ( 'Promise should not resolve' )
124
+ } ) . catch ( e => {
125
+ t . ok ( e . match ( / m a r k e t d o e s n o t e x i s t / i) , `Converting ${ NOT_USD_TRADABLE } to USD fails` )
126
+ t . end ( )
127
+ } ) . catch ( t . end )
128
+ }
0 commit comments