2021-01-02 15:41:12 -08:00
|
|
|
const assert = require('chai').assert
|
|
|
|
|
const BCHJS = require('../../src/bch-js')
|
|
|
|
|
const sinon = require('sinon')
|
2020-07-27 21:32:51 -07:00
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
const mockDataLib = require('./fixtures/price-mocks')
|
2020-10-19 19:36:55 -07:00
|
|
|
let mockData
|
|
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
describe('#price', () => {
|
2020-10-19 19:36:55 -07:00
|
|
|
let sandbox
|
|
|
|
|
let bchjs
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
sandbox = sinon.createSandbox()
|
|
|
|
|
|
|
|
|
|
bchjs = new BCHJS()
|
|
|
|
|
|
|
|
|
|
mockData = Object.assign({}, mockDataLib)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
afterEach(() => sandbox.restore())
|
|
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
describe('#current', () => {
|
|
|
|
|
it('should get current price for single currency', async () => {
|
2020-10-19 19:36:55 -07:00
|
|
|
sandbox
|
2021-01-02 15:41:12 -08:00
|
|
|
.stub(bchjs.Price.axios, 'get')
|
2020-10-19 19:36:55 -07:00
|
|
|
.resolves({ data: { price: 24905 } })
|
|
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
const result = await bchjs.Price.current('usd')
|
2020-10-19 19:36:55 -07:00
|
|
|
// console.log(result)
|
|
|
|
|
|
|
|
|
|
assert.isNumber(result)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
describe('#getUsd', () => {
|
|
|
|
|
it('should get the USD price of BCH', async () => {
|
|
|
|
|
sandbox.stub(bchjs.Price.axios, 'get').resolves({ data: { usd: 249.87 } })
|
2020-10-19 19:36:55 -07:00
|
|
|
|
|
|
|
|
const result = await bchjs.Price.getUsd()
|
|
|
|
|
// console.log(result)
|
|
|
|
|
|
|
|
|
|
assert.isNumber(result)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
describe('#rates', () => {
|
|
|
|
|
it('should get the price of BCH in several currencies', async () => {
|
2020-10-19 19:36:55 -07:00
|
|
|
sandbox
|
2021-01-02 15:41:12 -08:00
|
|
|
.stub(bchjs.Price.axios, 'get')
|
2020-10-19 19:36:55 -07:00
|
|
|
.resolves({ data: mockData.mockRates })
|
|
|
|
|
|
|
|
|
|
const result = await bchjs.Price.rates()
|
|
|
|
|
// console.log(result)
|
|
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
assert.property(result, 'USD')
|
|
|
|
|
assert.property(result, 'CAD')
|
2020-07-27 21:32:51 -07:00
|
|
|
})
|
|
|
|
|
})
|
2020-11-17 14:41:04 -08:00
|
|
|
|
2021-01-02 15:41:12 -08:00
|
|
|
describe('#getBchaUsd', () => {
|
|
|
|
|
it('should get the USD price of BCHA', async () => {
|
|
|
|
|
sandbox.stub(bchjs.Price.axios, 'get').resolves({ data: { usd: 18.87 } })
|
2020-11-17 14:41:04 -08:00
|
|
|
|
|
|
|
|
const result = await bchjs.Price.getBchaUsd()
|
|
|
|
|
// console.log(result)
|
|
|
|
|
|
|
|
|
|
assert.isNumber(result)
|
|
|
|
|
})
|
|
|
|
|
})
|
2020-07-27 21:32:51 -07:00
|
|
|
})
|