fix(/ipfs/node): Added unit tests for API controller

This commit is contained in:
Chris Troutner
2024-03-07 18:55:09 -08:00
parent 439dbc54ae
commit dbbd321029
3 changed files with 39 additions and 2 deletions
@@ -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 }
@@ -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')
})
})
})
+2 -1
View File
@@ -24,7 +24,8 @@ class IpfsCoordAdapter {
peer: {
sendPrivateMessage: () => {}
}
}
},
thisNode: {}
}
}
}