import { nanoid } from 'nanoid';
import { expect } from 'aegir/utils/chai.js';
import {
  getDescribe,
  getIt
} from '../utils/mocha.js';
export function testRm(factory, options) {
  const describe = getDescribe(options);
  const it = getIt(options);
  describe('.key.rm', () => {
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should rm a key', async function () {
      this.timeout(30 * 1000);
      const key = await ipfs.key.gen(nanoid(), {
        type: 'rsa',
        size: 2048
      });
      const removeRes = await ipfs.key.rm(key.name);
      expect(removeRes).to.exist();
      expect(removeRes).to.have.property('name', key.name);
      expect(removeRes).to.have.property('id', key.id);
      const res = await ipfs.key.list();
      expect(res.find(k => k.name === key.name)).to.not.exist();
    });
  });
}