mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service.git
synced 2026-09-21 16:52:03 -07:00
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
/*
|
|
Unit tests for the adapters index.js library
|
|
*/
|
|
|
|
// Global npm libraries
|
|
import { assert } from 'chai'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
// Local libraries
|
|
import Adapters from '../../../src/adapters/index.js'
|
|
|
|
describe('#adapters', () => {
|
|
let uut, sandbox
|
|
|
|
beforeEach(() => {
|
|
uut = new Adapters()
|
|
|
|
sandbox = sinon.createSandbox()
|
|
})
|
|
|
|
afterEach(() => {
|
|
sandbox.restore()
|
|
})
|
|
|
|
describe('#start', () => {
|
|
it('should start the async adapters', async () => {
|
|
// Mock dependencies
|
|
uut.config.getJwtAtStartup = true
|
|
uut.config.useIpfs = true
|
|
uut.config.env = 'not-a-test'
|
|
sandbox.stub(uut.fullStackJwt, 'getJWT').resolves()
|
|
sandbox.stub(uut.fullStackJwt, 'instanceBchjs').resolves()
|
|
sandbox.stub(uut.ipfs, 'start').resolves()
|
|
|
|
const result = await uut.start()
|
|
|
|
assert.equal(result, true)
|
|
})
|
|
it('should not start ipfs on test enviroment', async () => {
|
|
// Mock dependencies
|
|
uut.config.getJwtAtStartup = true
|
|
uut.config.useIpfs = true
|
|
uut.config.env = 'test'
|
|
|
|
sandbox.stub(uut.fullStackJwt, 'getJWT').resolves()
|
|
sandbox.stub(uut.fullStackJwt, 'instanceBchjs').resolves()
|
|
const ipfsSpy = sandbox.stub(uut.ipfs, 'start').resolves(null)
|
|
|
|
const result = await uut.start()
|
|
|
|
assert.isTrue(ipfsSpy.notCalled)
|
|
assert.equal(result, true)
|
|
})
|
|
|
|
it('should catch and throw an error', async () => {
|
|
try {
|
|
// Force an error
|
|
uut.config.getJwtAtStartup = false
|
|
uut.config.env = 'dev'
|
|
sandbox.stub(uut.ipfs, 'start').rejects(new Error('test error'))
|
|
|
|
await uut.start()
|
|
|
|
assert.fail('Unexpected result')
|
|
} catch (err) {
|
|
// console.log('err: ', err)
|
|
assert.include(err.message, 'test error')
|
|
}
|
|
})
|
|
})
|
|
})
|