forked from Sfippa/api-client-v1-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.js
91 lines (79 loc) · 2.28 KB
/
spec.js
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
var statistics = require('./index')
var nock = require('nock')
var expect = require('chai').expect
describe('statistics', function () {
describe('.get()', function () {
nock('https://blockchain.info')
.get('/stats').query(true).times(3)
.reply(200, { market_price_usd: 999.99 })
it('should get a list of stats', function (done) {
statistics.get()
.then(function (data) {
expect(data.market_price_usd).to.equal(999.99)
done()
})
.catch(done)
})
it('should get a single stat if specified', function (done) {
statistics.get({ stat: 'market_price_usd' })
.then(function (data) {
expect(data).to.equal(999.99)
done()
})
.catch(done)
})
it('should reject a nonexistant stat', function (done) {
statistics.get({ stat: 'satoshis_coords' })
.then(done)
.catch(function (err) {
expect(err).to.equal('Received unknown stat option')
done()
})
})
})
describe('.getChartData()', function () {
var chartData = [
{ x: 100, y: 4 },
{ x: 101, y: 8 }
]
nock('https://blockchain.info')
.get('/charts/market-cap').query(true)
.reply(200, { values: chartData })
it('should get a list of chart points', function (done) {
statistics.getChartData('market-cap')
.then(function (data) {
expect(data).to.deep.equal(chartData)
done()
})
.catch(done)
})
})
describe('.getPoolData()', function () {
var poolData = {
'BitFury': 58,
'AntPool': 87
}
it('should get pool data', function (done) {
nock('https://blockchain.info')
.get('/pools?format=json')
.reply(200, poolData)
statistics.getPoolData()
.then(function (data) {
expect(data).to.deep.equal(poolData)
done()
})
.catch(done)
})
it('should get pool data with optional timespan', function (done) {
nock('https://blockchain.info')
.get('/pools?format=json×pan=8days')
.reply(200, poolData)
statistics.getPoolData({ timespan: 8 })
.then(function (data) {
expect(data).to.deep.equal(poolData)
done()
})
.catch(done)
})
})
})