Files
ipfs-bch-wallet-service/test/unit/adapters/ipfs.adapter.unit.js
T

64 lines
1.3 KiB
JavaScript
Raw Normal View History

/*
Unit tests for the IPFS Adapter.
*/
const assert = require('chai').assert
const sinon = require('sinon')
const IPFSLib = require('../../../src/adapters/ipfs/ipfs')
const IPFSMock = require('../mocks/ipfs-mock')
2021-07-13 09:09:42 -07:00
describe('#IPFS-adapter', () => {
let uut
let sandbox
beforeEach(() => {
uut = new IPFSLib()
sandbox = sinon.createSandbox()
})
afterEach(() => sandbox.restore())
describe('#start', () => {
it('should return a promise that resolves into an instance of IPFS.', async () => {
// Mock dependencies.
uut.IPFS = IPFSMock
const result = await uut.start()
// console.log('result: ', result)
assert.equal(uut.isReady, true)
assert.property(result, 'config')
})
it('should catch and throw an error', async () => {
try {
// Force an error
sandbox.stub(uut.IPFS, 'create').rejects(new Error('test error'))
await uut.start()
assert.fail('Unexpected code path.')
} catch (err) {
2021-07-13 09:09:42 -07:00
// console.log(err)
assert.include(err.message, 'test error')
}
})
})
describe('#stop', () => {
it('should stop the IPFS node', async () => {
// Mock dependencies
uut.ipfs = {
stop: () => {}
}
const result = await uut.stop()
assert.equal(result, true)
})
})
})