mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service.git
synced 2026-09-21 16:52:03 -07:00
fix(/ipfs/node): Added unit tests for API controller
This commit is contained in:
@@ -113,7 +113,6 @@ class IpfsRESTControllerLib {
|
|||||||
*/
|
*/
|
||||||
async getThisNode (ctx) {
|
async getThisNode (ctx) {
|
||||||
try {
|
try {
|
||||||
// const status = await this.adapters.ipfs.getStatus()
|
|
||||||
const thisNode = this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.thisNode
|
const thisNode = this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.thisNode
|
||||||
|
|
||||||
ctx.body = { 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')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ class IpfsCoordAdapter {
|
|||||||
peer: {
|
peer: {
|
||||||
sendPrivateMessage: () => {}
|
sendPrivateMessage: () => {}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
thisNode: {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user