'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 testClear(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  const validIp4 = new multiaddr.Multiaddr('/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z');
  describe('.bootstrap.clear', function () {
    this.timeout(100 * 1000);
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should return a list containing the peer removed when called with a valid arg (ip4)', async () => {
      await ipfs.bootstrap.clear();
      const addRes = await ipfs.bootstrap.add(validIp4);
      chai_js.expect(addRes).to.be.eql({ Peers: [validIp4] });
      const rmRes = await ipfs.bootstrap.clear();
      chai_js.expect(rmRes).to.be.eql({ Peers: [validIp4] });
      const peers = rmRes.Peers;
      chai_js.expect(peers).to.have.property('length').that.is.equal(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(removedPeers.every(ma => multiaddr.Multiaddr.isMultiaddr(ma))).to.be.true();
    });
  });
}

exports.testClear = testClear;
