-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move histo tests and helpers to seperate files
- Loading branch information
Showing
3 changed files
with
68 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
// NOT_USD_TRADABLE is a cryptocurrency which does not trade directly with USD. | ||
// This value is used in testing tryConversion. Currently, this is set to LTD. | ||
// If LTD trades directly with USD in the future, tests will fail. | ||
// In that case, change this value: | ||
exports.NOT_USD_TRADABLE = 'LTD' | ||
|
||
exports.testTryConversion = function (promise, t) { | ||
t.plan(1) | ||
promise.then(prices => { | ||
t.end('Promise should not resolve') | ||
}).catch(e => { | ||
t.ok(e.match(/market does not exist/i), `Converting ${exports.NOT_USD_TRADABLE} to USD fails`) | ||
t.end() | ||
}).catch(t.end) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict' | ||
const test = require('tape') | ||
|
||
if (!global.fetch) global.fetch = require('node-fetch') | ||
const cc = require('../') | ||
const helpers = require('./helpers') | ||
|
||
test('histoDay()', t => { | ||
t.plan(8) | ||
cc.histoDay('BTC', 'USD').then(data => { | ||
t.is(data.length, 31, 'returns 31 items by default') | ||
const item = data[0] | ||
t.is(typeof item.time, 'number', 'item.time is a number') | ||
t.is(typeof item.close, 'number', 'item.close is a number') | ||
t.is(typeof item.high, 'number', 'item.high is a number') | ||
t.is(typeof item.low, 'number', 'item.low is a number') | ||
t.is(typeof item.open, 'number', 'item.open is a number') | ||
t.is(typeof item.volumefrom, 'number', 'item.volumefrom is a number') | ||
t.is(typeof item.volumeto, 'number', 'item.volumeto is a number') | ||
t.end() | ||
}).catch(t.end) | ||
}) | ||
|
||
test("histoDay()'s limit option works", t => { | ||
t.plan(1) | ||
cc.histoDay('BTC', 'USD', { limit: 2 }).then(data => { | ||
t.is(data.length, 3, 'returns limit plus timestamped data') | ||
t.end() | ||
}).catch(t.end) | ||
}) | ||
|
||
test("histoDay()'s timestamp option works", t => { | ||
t.plan(1) | ||
let data = [] | ||
data.push(cc.histoDay('BTC', 'USD', { timestamp: new Date('2017-01-01') })) | ||
data.push(cc.histoDay('BTC', 'USD', { timestamp: new Date('2017-01-02') })) | ||
Promise.all(data).then(data => { | ||
t.notDeepEqual(data[0], data[1], 'data from different days should not be equivalent') | ||
t.end() | ||
}).catch(t.end) | ||
}) | ||
|
||
test("histoDay()'s tryConversion=false works", t => { | ||
helpers.testTryConversion(cc.histoDay(helpers.NOT_USD_TRADABLE, 'USD', { tryConversion: false }), t) | ||
}) |