2021-07-11 19:33:26 -07:00
|
|
|
/*
|
|
|
|
|
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', () => {
|
2021-07-11 19:33:26 -07:00
|
|
|
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)
|
2021-07-11 19:33:26 -07:00
|
|
|
assert.include(err.message, 'test error')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-09-30 15:20:51 -07:00
|
|
|
|
|
|
|
|
describe('#stop', () => {
|
|
|
|
|
it('should stop the IPFS node', async () => {
|
|
|
|
|
// Mock dependencies
|
|
|
|
|
uut.ipfs = {
|
|
|
|
|
stop: () => {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await uut.stop()
|
|
|
|
|
|
|
|
|
|
assert.equal(result, true)
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-07-11 19:33:26 -07:00
|
|
|
})
|