Files

84 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

import chai from 'chai'
import BCHJS from '../../src/bch-js.js'
import sinon from 'sinon'
2020-07-27 21:32:51 -07:00
import mockDataLib from './fixtures/price-mocks.js'
const { assert } = chai
let mockData
2021-01-02 15:41:12 -08:00
describe('#price', () => {
let sandbox
let bchjs
beforeEach(() => {
sandbox = sinon.createSandbox()
bchjs = new BCHJS()
mockData = Object.assign({}, mockDataLib)
})
afterEach(() => sandbox.restore())
// describe('#current', () => {
// it('should get current price for single currency', async () => {
// sandbox
// .stub(bchjs.Price.axios, 'get')
// .resolves({ data: { price: 24905 } })
//
// const result = await bchjs.Price.current('usd')
// // 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 } })
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 () => {
sandbox
2021-01-02 15:41:12 -08:00
.stub(bchjs.Price.axios, 'get')
.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-03-04 15:14:46 -04:00
describe('#getBchUsd', () => {
it('should get the USD price of BCH', async () => {
sandbox.stub(bchjs.Price.axios, 'get').resolves({ data: { usd: 510.39 } })
const result = await bchjs.Price.getBchUsd()
// console.log(result)
assert.isNumber(result)
})
it('should handle error', async () => {
try {
sandbox.stub(bchjs.Price.axios, 'get').throws(new Error('test error'))
await bchjs.Price.getBchUsd()
// console.log(result)
assert.equal(false, true, 'unexpected error')
} catch (err) {
assert.include(err.message, 'test error')
}
})
})
2020-07-27 21:32:51 -07:00
})