'use strict';

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

var utils = require('./utils.js');
var chai_js = require('aegir/utils/chai.js');
var mocha = require('../utils/mocha.js');
var last = require('it-last');
var all = require('it-all');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var last__default = /*#__PURE__*/_interopDefaultLegacy(last);
var all__default = /*#__PURE__*/_interopDefaultLegacy(all);

function testBw(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.stats.bw', () => {
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should get bandwidth stats ', async () => {
      const res = await last__default["default"](ipfs.stats.bw());
      if (!res) {
        throw new Error('No bw stats returned');
      }
      utils.expectIsBandwidth(null, res);
    });
    it('should throw error for invalid interval option', async () => {
      await chai_js.expect(all__default["default"](ipfs.stats.bw({
        poll: true,
        interval: 'INVALID INTERVAL'
      }))).to.eventually.be.rejected().with.property('message').that.matches(/invalid duration/);
    });
  });
}

exports.testBw = testBw;
