From eb46a4c130404c3c4cfe88434e1cd456b138b07d Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 20 Jun 2022 07:19:36 -0700 Subject: [PATCH] fix(tests): Got to 100% test coverage for entire repo --- src/adapters/index.js | 2 + test/unit/adapters/adapters-index-unit.js | 53 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/unit/adapters/adapters-index-unit.js diff --git a/src/adapters/index.js b/src/adapters/index.js index 95acde1..92d2506 100644 --- a/src/adapters/index.js +++ b/src/adapters/index.js @@ -47,6 +47,8 @@ class Adapters { // Start the IPFS node. await this.ipfs.start() + + return true } catch (err) { console.error('Error in adapters/index.js/start()') throw err diff --git a/test/unit/adapters/adapters-index-unit.js b/test/unit/adapters/adapters-index-unit.js new file mode 100644 index 0000000..420a3d1 --- /dev/null +++ b/test/unit/adapters/adapters-index-unit.js @@ -0,0 +1,53 @@ +/* + Unit tests for the adapters index.js library +*/ + +// Global npm libraries +const assert = require('chai').assert +const sinon = require('sinon') + +// Local libraries +const Adapters = require('../../../src/adapters') + +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 + 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 catch and throw an error', async () => { + try { + // Force an error + uut.config.getJwtAtStartup = false + 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') + } + }) + }) +})