/* Unit tests for the index.js file for the IPFS and ipfs-coord libraries. */ import { assert } from 'chai' import sinon from 'sinon' import IPFSLib from '../../../src/adapters/ipfs/index.js' // import IPFSMock from '../mocks/ipfs-mock.js' // import create from '../mocks/ipfs-mock.js' import IPFSCoordMock from '../mocks/ipfs-coord-mock.js' // import EventEmiter from 'events' describe('#IPFS-adapter-index', () => { let uut let sandbox beforeEach(() => { // uut = new IPFSLib({ eventEmitter: new EventEmitter() }) 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.ipfsAdapter = { start: async () => {} } uut.IpfsCoordAdapter = IPFSCoordMock const result = await uut.start() assert.equal(result, true) }) it('should catch and throw an error', async () => { try { // Force an error sandbox.stub(uut.ipfsAdapter, 'start').rejects(new Error('test error')) await uut.start() assert.fail('Unexpected code path.') } catch (err) { // console.log(err) assert.include(err.message, 'test error') } }) it('should handle lock-file errors', async () => { try { // Force an error sandbox .stub(uut.ipfsAdapter, 'start') .rejects(new Error('Lock already being held')) // Prevent process from exiting sandbox.stub(uut.process, 'exit').returns() await uut.start() assert.fail('Unexpected code path.') } catch (err) { assert.include(err.message, 'Lock already being held') } }) }) })