fix(ipfs-coord): Got adapter back to 100% test coverage

This commit is contained in:
Chris Troutner
2021-09-30 15:12:47 -07:00
parent 7e228b729e
commit 5af068e0d6
2 changed files with 30 additions and 13 deletions
+2 -2
View File
@@ -29,8 +29,8 @@ class IpfsCoordAdapter {
this.IpfsCoord = IpfsCoord
this.ipfsCoord = {}
this.bchjs = new BCHJS()
// this.rpc = new JSONRPC()
this.config = config
this.publicIp = publicIp
// Properties of this class instance.
this.isReady = false
@@ -44,7 +44,7 @@ class IpfsCoordAdapter {
// If configured as a Circuit Relay, get the public IP addresses for this node.
if (this.config.isCircuitRelay) {
try {
const ip4 = await publicIp.v4()
const ip4 = await this.publicIp.v4()
// const ip6 = await publicIp.v6()
circuitRelayInfo.ip4 = ip4
+28 -11
View File
@@ -47,6 +47,20 @@ describe('#IPFS', () => {
assert.equal(result, true)
})
it('should get the public IP address if this node is a Circuit Relay', async () => {
// Mock dependencies.
uut.IpfsCoord = IPFSCoordMock
sandbox.stub(uut.publicIp, 'v4').returns('123')
// Force Circuit Relay
uut.config.isCircuitRelay = true
const result = await uut.start()
// console.log('result: ', result)
assert.equal(result, true)
})
})
describe('#attachRPCRouter', () => {
@@ -71,16 +85,19 @@ describe('#IPFS', () => {
uut.attachRPCRouter(router)
})
// it('should throw an error if ipfs-coord has not been instantiated', () => {
// try {
// const router = console.log
//
// uut.attachRPCRouter(router)
//
// assert.fail('Unexpected code path')
// } catch (err) {
// assert.include(err.message, 'Cannot read property')
// }
// })
it('should catch and throw an error', () => {
try {
// Force an error
delete uut.ipfsCoord.adapters
const router = console.log
uut.attachRPCRouter(router)
assert.fail('Unexpected code path')
} catch (err) {
assert.include(err.message, 'Cannot read property')
}
})
})
})