'use strict';

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

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

function testGet(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.config.get', function () {
    this.timeout(30 * 1000);
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should fail with error', async () => {
      await chai_js.expect(ipfs.config.get()).to.eventually.rejectedWith('key argument is required');
    });
    it('should retrieve a value through a key', async () => {
      const peerId = await ipfs.config.get('Identity.PeerID');
      chai_js.expect(peerId).to.exist();
    });
    it('should retrieve a value through a nested key', async () => {
      const swarmAddrs = await ipfs.config.get('Addresses.Swarm');
      chai_js.expect(swarmAddrs).to.exist();
    });
    it('should fail on non valid key', () => {
      return chai_js.expect(ipfs.config.get(1234)).to.eventually.be.rejected();
    });
    it('should fail on non existent key', () => {
      return chai_js.expect(ipfs.config.get('Bananas')).to.eventually.be.rejected();
    });
  });
  describe('.config.getAll', function () {
    this.timeout(30 * 1000);
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should retrieve the whole config', async () => {
      const config = await ipfs.config.getAll();
      chai_js.expect(config).to.be.an('object');
    });
    it('should retrieve the whole config with options', async () => {
      const config = await ipfs.config.getAll({ signal: undefined });
      chai_js.expect(config).to.be.an('object');
    });
  });
}

exports.testGet = testGet;
