'use strict';

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

var utils = require('./utils.js');
var chai_js = require('aegir/utils/chai.js');
var mocha = require('../utils/mocha.js');
var all = require('it-all');
var drain = require('it-drain');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var all__default = /*#__PURE__*/_interopDefaultLegacy(all);
var drain__default = /*#__PURE__*/_interopDefaultLegacy(drain);

function testRmAll(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.pin.rmAll', function () {
    this.timeout(50 * 1000);
    let ipfs;
    beforeEach(async () => {
      ipfs = (await factory.spawn()).api;
      const dir = utils.fixtures.directory.files.map(file => ({
        path: file.path,
        content: file.data
      }));
      await all__default["default"](ipfs.addAll(dir, {
        pin: false,
        cidVersion: 0
      }));
      await ipfs.add(utils.fixtures.files[0].data, { pin: false });
      await ipfs.add(utils.fixtures.files[1].data, { pin: false });
    });
    after(() => factory.clean());
    beforeEach(() => {
      return utils.clearPins(ipfs);
    });
    it('should pipe the output of ls to rm', async () => {
      await ipfs.pin.add(utils.fixtures.directory.cid);
      await drain__default["default"](ipfs.pin.rmAll(ipfs.pin.ls({ type: 'recursive' })));
      await chai_js.expect(all__default["default"](ipfs.pin.ls())).to.eventually.have.lengthOf(0);
    });
  });
}

exports.testRmAll = testRmAll;
