'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');
var fromString = require('uint8arrays/from-string');

function testData(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.object.data', function () {
    this.timeout(80 * 1000);
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should get data by CID', async () => {
      const testObj = {
        Data: fromString.fromString(nanoid.nanoid()),
        Links: []
      };
      const nodeCid = await ipfs.object.put(testObj);
      const data = await ipfs.object.data(nodeCid);
      chai_js.expect(testObj.Data).to.equalBytes(data);
    });
    it('returns error for request without argument', () => {
      return chai_js.expect(ipfs.object.data(null)).to.eventually.be.rejected.and.be.an.instanceOf(Error);
    });
    it('returns error for request with invalid argument', () => {
      return chai_js.expect(ipfs.object.data('invalid', { enc: 'base58' })).to.eventually.be.rejected.and.be.an.instanceOf(Error);
    });
  });
}

exports.testData = testData;
