'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 testAddAll(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.pin.addAll', function () {
    this.timeout(50 * 1000);
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
      await drain__default["default"](ipfs.addAll(utils.fixtures.files.map(file => ({ content: file.data })), { pin: false }));
      await drain__default["default"](ipfs.addAll(utils.fixtures.directory.files.map(file => ({
        path: file.path,
        content: file.data
      })), { pin: false }));
    });
    after(() => factory.clean());
    beforeEach(() => {
      return utils.clearPins(ipfs);
    });
    async function testAddPinInput(source) {
      const pinset = await all__default["default"](ipfs.pin.addAll(source));
      chai_js.expect(pinset).to.have.deep.members([
        utils.fixtures.files[0].cid,
        utils.fixtures.files[1].cid
      ]);
    }
    it('should add an array of CIDs', () => {
      return testAddPinInput([
        utils.fixtures.files[0].cid,
        utils.fixtures.files[1].cid
      ]);
    });
    it('should add a generator of CIDs', () => {
      return testAddPinInput(function* () {
        yield utils.fixtures.files[0].cid;
        yield utils.fixtures.files[1].cid;
      }());
    });
    it('should add an async generator of CIDs', () => {
      return testAddPinInput(async function* () {
        yield utils.fixtures.files[0].cid;
        yield utils.fixtures.files[1].cid;
      }());
    });
    it('should add an array of pins with options', () => {
      return testAddPinInput([
        {
          cid: utils.fixtures.files[0].cid,
          recursive: false
        },
        {
          cid: utils.fixtures.files[1].cid,
          recursive: true
        }
      ]);
    });
    it('should add a generator of pins with options', () => {
      return testAddPinInput(function* () {
        yield {
          cid: utils.fixtures.files[0].cid,
          recursive: false
        };
        yield {
          cid: utils.fixtures.files[1].cid,
          recursive: true
        };
      }());
    });
    it('should add an async generator of pins with options', () => {
      return testAddPinInput(async function* () {
        yield {
          cid: utils.fixtures.files[0].cid,
          recursive: false
        };
        yield {
          cid: utils.fixtures.files[1].cid,
          recursive: true
        };
      }());
    });
  });
}

exports.testAddAll = testAddAll;
