'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 testRm(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.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.nanoid(), {
        type: 'rsa',
        size: 2048
      });
      const removeRes = await ipfs.key.rm(key.name);
      chai_js.expect(removeRes).to.exist();
      chai_js.expect(removeRes).to.have.property('name', key.name);
      chai_js.expect(removeRes).to.have.property('id', key.id);
      const res = await ipfs.key.list();
      chai_js.expect(res.find(k => k.name === key.name)).to.not.exist();
    });
  });
}

exports.testRm = testRm;
