import { nanoid } from 'nanoid';
import { expect } from 'aegir/utils/chai.js';
import {
  getDescribe,
  getIt
} from '../utils/mocha.js';
export function testList(factory, options) {
  const describe = getDescribe(options);
  const it = 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(), {
        type: 'rsa',
        size: 2048
      })));
      const res = await ipfs.key.list();
      expect(res).to.exist();
      expect(res).to.be.an('array');
      expect(res.length).to.be.above(keys.length - 1);
      keys.forEach(key => {
        const found = res.find(({id, name}) => name === key.name && id === key.id);
        expect(found).to.exist();
      });
    });
  });
}