'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var chai_js = require('aegir/utils/chai.js');
var mocha = require('../utils/mocha.js');
var multiaddr = require('multiaddr');

function testReset(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.bootstrap.reset', function () {
    this.timeout(100 * 1000);
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should return a list of bootstrap peers when resetting the bootstrap nodes', async () => {
      const res = await ipfs.bootstrap.reset();
      const peers = res.Peers;
      chai_js.expect(peers).to.have.property('length').that.is.gt(1);
    });
    it('should return a list of all peers removed when all option is passed', async () => {
      const addRes = await ipfs.bootstrap.reset();
      const addedPeers = addRes.Peers;
      const rmRes = await ipfs.bootstrap.clear();
      const removedPeers = rmRes.Peers;
      chai_js.expect(removedPeers.sort()).to.deep.equal(addedPeers.sort());
      chai_js.expect(addedPeers.every(ma => multiaddr.Multiaddr.isMultiaddr(ma))).to.be.true();
    });
  });
}

exports.testReset = testReset;
