'use strict';

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

var index = require('./utils/index.js');
var chai_js = require('aegir/utils/chai.js');
var mocha = require('./utils/mocha.js');
var all = require('it-all');
var ipfsUnixfsImporter = require('ipfs-unixfs-importer');
var drain = require('it-drain');
var cid = require('multiformats/cid');
var equals = require('uint8arrays/equals');
var blockstoreAdapter = require('./utils/blockstore-adapter.js');

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 testRefsLocal(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.refs.local', function () {
    this.timeout(60 * 1000);
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should get local refs', async function () {
      const content = name => ({
        path: `test-folder/${ name }`,
        content: index.fixtures.directory.files[name]
      });
      const dirs = [
        content('pp.txt'),
        content('holmes.txt')
      ];
      const imported = await all__default["default"](ipfsUnixfsImporter.importer(dirs, blockstoreAdapter(ipfs)));
      await drain__default["default"](ipfs.pin.addAll(imported.map(i => ({ cid: i.cid }))));
      const refs = await all__default["default"](ipfs.refs.local());
      const cids = refs.map(r => r.ref);
      chai_js.expect(cids.find(cid$1 => {
        const multihash = cid.CID.parse(cid$1).multihash.bytes;
        return equals.equals(imported[0].cid.multihash.bytes, multihash);
      })).to.be.ok();
      chai_js.expect(cids.find(cid$1 => {
        const multihash = cid.CID.parse(cid$1).multihash.bytes;
        return equals.equals(imported[1].cid.multihash.bytes, multihash);
      })).to.be.ok();
    });
  });
}

exports.testRefsLocal = testRefsLocal;
