diff --git a/src/controllers/rest-api/ipfs/controller.js b/src/controllers/rest-api/ipfs/controller.js index 1654a6a..19249c2 100644 --- a/src/controllers/rest-api/ipfs/controller.js +++ b/src/controllers/rest-api/ipfs/controller.js @@ -113,7 +113,6 @@ class IpfsRESTControllerLib { */ async getThisNode (ctx) { try { - // const status = await this.adapters.ipfs.getStatus() const thisNode = this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.thisNode ctx.body = { thisNode } diff --git a/test/unit/controllers/rest-api/ipfs/ipfs.rest.controller.unit.js b/test/unit/controllers/rest-api/ipfs/ipfs.rest.controller.unit.js index dcb1f43..34483f5 100644 --- a/test/unit/controllers/rest-api/ipfs/ipfs.rest.controller.unit.js +++ b/test/unit/controllers/rest-api/ipfs/ipfs.rest.controller.unit.js @@ -211,4 +211,41 @@ describe('#IPFS REST API', () => { } }) }) + + describe('#getThisNode', () => { + it('should return 422 status on biz logic error', async () => { + try { + // Force an error + // sandbox.stub(uut.adapters.ipfs.ipfsCoordAdapter.ipfsCoord, 'thisNode').rejects(new Error('test error')) + uut.adapters.ipfs.ipfsCoordAdapter = {} + + ctx.request.body = {} + + await uut.getThisNode(ctx) + + assert.fail('Unexpected result') + } catch (err) { + // console.log('err: ', err) + assert.equal(err.status, 422) + assert.include(err.message, 'Cannot read') + } + }) + + it('should return 200 status on success', async () => { + // Mock dependencies + // sandbox.stub(uut.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs, 'connectToPeer').resolves({ success: true }) + + uut.adapters.ipfs.ipfsCoordAdapter = { + ipfsCoord: { + thisNode: {} + } + } + + ctx.request.body = {} + + await uut.getThisNode(ctx) + + assert.property(ctx.body, 'thisNode') + }) + }) }) diff --git a/test/unit/mocks/adapters/index.js b/test/unit/mocks/adapters/index.js index 55a1c83..80cd290 100644 --- a/test/unit/mocks/adapters/index.js +++ b/test/unit/mocks/adapters/index.js @@ -24,7 +24,8 @@ class IpfsCoordAdapter { peer: { sendPrivateMessage: () => {} } - } + }, + thisNode: {} } } }