'use strict';

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

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

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

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

function testSubs(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.name.pubsub.subs', () => {
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should get an empty array as a result of subscriptions before any resolve', async function () {
      this.timeout(60 * 1000);
      const res = await ipfs.name.pubsub.subs();
      chai_js.expect(res).to.exist();
      chai_js.expect(res).to.eql([]);
    });
    it('should get the list of subscriptions updated after a resolve', async function () {
      this.timeout(300 * 1000);
      const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA';
      const subs = await ipfs.name.pubsub.subs();
      chai_js.expect(subs).to.eql([]);
      await chai_js.expect(all__default["default"](ipfs.name.resolve(id))).to.eventually.be.rejected();
      const res = await ipfs.name.pubsub.subs();
      chai_js.expect(res).to.be.an('array').that.does.include(`/ipns/${ id }`);
    });
  });
}

exports.testSubs = testSubs;
