2019-11-14 11:52:06 +01:00
|
|
|
/* eslint-env mocha */
|
|
|
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const chai = require('chai')
|
|
|
|
const expect = chai.expect
|
|
|
|
chai.use(require('dirty-chai'))
|
|
|
|
const sinon = require('sinon')
|
|
|
|
|
|
|
|
const PeerId = require('peer-id')
|
|
|
|
const peers = require('../../utils/peers')
|
|
|
|
|
|
|
|
module.exports = (test) => {
|
|
|
|
describe('topology', () => {
|
2020-04-17 17:23:31 +02:00
|
|
|
let topology, id
|
2019-11-14 11:52:06 +01:00
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
topology = await test.setup()
|
|
|
|
if (!topology) throw new Error('missing multicodec topology')
|
|
|
|
|
2020-04-17 17:23:31 +02:00
|
|
|
id = await PeerId.createFromJSON(peers[0])
|
2019-11-14 11:52:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
sinon.restore()
|
|
|
|
await test.teardown()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should have properties set', () => {
|
|
|
|
expect(topology.min).to.exist()
|
|
|
|
expect(topology.max).to.exist()
|
|
|
|
expect(topology._onConnect).to.exist()
|
|
|
|
expect(topology._onDisconnect).to.exist()
|
|
|
|
expect(topology.peers).to.exist()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should trigger "onDisconnect" on peer disconnected', () => {
|
|
|
|
sinon.spy(topology, '_onDisconnect')
|
2020-04-17 17:23:31 +02:00
|
|
|
topology.disconnect(id)
|
2019-11-14 11:52:06 +01:00
|
|
|
|
|
|
|
expect(topology._onDisconnect.callCount).to.equal(1)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|