'use strict';

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

var nanoid = require('nanoid');
var chai_js = require('aegir/utils/chai.js');
var mocha = require('../utils/mocha.js');

function testList(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.key.list', () => {
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should list all the keys', async function () {
      this.timeout(60 * 1000);
      const keys = await Promise.all([
        1,
        2,
        3
      ].map(() => ipfs.key.gen(nanoid.nanoid(), {
        type: 'rsa',
        size: 2048
      })));
      const res = await ipfs.key.list();
      chai_js.expect(res).to.exist();
      chai_js.expect(res).to.be.an('array');
      chai_js.expect(res.length).to.be.above(keys.length - 1);
      keys.forEach(key => {
        const found = res.find(({id, name}) => name === key.name && id === key.id);
        chai_js.expect(found).to.exist();
      });
    });
  });
}

exports.testList = testList;
