'use strict';

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

var _chai;

function _load_chai() {
  return _chai = require('chai');
}

var _;

function _load_() {
  return _ = require('./');
}

var _dependenciesFixture;

function _load_dependenciesFixture() {
  return _dependenciesFixture = _interopRequireDefault(require('../../../../fixtures/dependencies-fixture.json'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

describe('Dependencies', function () {
  describe('validate()', function () {
    var dependencies = void 0;
    var validateFunc = void 0;
    beforeEach(function () {
      dependencies = new (_ || _load_()).Dependencies((_ramda || _load_ramda()).default.clone((_dependenciesFixture || _load_dependenciesFixture()).default));
      validateFunc = function validateFunc() {
        return dependencies.validate();
      };
    });
    it('should not throw when it has a valid dependencies array', function () {
      (0, (_chai || _load_chai()).expect)(validateFunc).to.not.throw();
    });
    it('should throw when dependencies are not array', function () {
      dependencies.dependencies = {};
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('to be array, got object');
    });
    it('should throw when an individual dependency is not an object', function () {
      dependencies.dependencies[0] = 12;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('to be object, got number');
    });
    it('should throw when a dependency is missing id', function () {
      delete dependencies.dependencies[0].id;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('is missing ID');
    });
    it('should throw when a dependency is missing relativePaths', function () {
      delete dependencies.dependencies[0].relativePaths;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('is missing relativePaths');
    });
    it('should throw when a dependency has an extra attribute other than id and relativePaths', function () {
      dependencies.dependencies[0].extra = 'should not be there!';
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('has an undetected property "extra"');
    });
    it('should throw when relativePaths is not an array', function () {
      dependencies.dependencies[0].relativePaths = {};
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('to be array, got object');
    });
    it('should throw when relativePaths.sourceRelativePath is missing', function () {
      delete dependencies.dependencies[0].relativePaths[0].sourceRelativePath;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('relativePaths.sourceRelativePath is missing');
    });
    it('should throw when relativePaths.destinationRelativePath is missing', function () {
      delete dependencies.dependencies[0].relativePaths[0].destinationRelativePath;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('relativePaths.destinationRelativePath is missing');
    });
    it('should throw when a relativePaths has an extra attribute', function () {
      dependencies.dependencies[0].relativePaths[0].extra = 'should not be there!';
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('undetected property of relativePaths "extra"');
    });
    it('should throw when relativePaths.isCustomResolveUsed is true but importSource is missing', function () {
      delete dependencies.dependencies[0].relativePaths[0].importSource;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('missing relativePath.importSource');
    });
    it('should not throw when both relativePaths.isCustomResolveUsed and relativePaths.importSource are missing', function () {
      delete dependencies.dependencies[0].relativePaths[0].isCustomResolveUsed;
      delete dependencies.dependencies[0].relativePaths[0].importSource;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.not.throw();
    });
    it('should throw when relativePaths.importSpecifiers is not an array', function () {
      dependencies.dependencies[0].relativePaths[0].importSpecifiers = {};
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('to be array, got object');
    });
    it('should throw when importSpecifier is not an object', function () {
      dependencies.dependencies[0].relativePaths[0].importSpecifiers[0] = [];
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('to be object, got array');
    });
    it('should throw when relativePaths.importSpecifiers has extra attributes', function () {
      dependencies.dependencies[0].relativePaths[0].importSpecifiers[0].extra = 'should not be there!';
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('undetected property of importSpecifier "extra"');
    });
    it('should throw when importSpecifier.mainFile is missing', function () {
      delete dependencies.dependencies[0].relativePaths[0].importSpecifiers[0].mainFile;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('mainFile property is missing');
    });
    it('should throw when importSpecifier.mainFile.isDefault is missing', function () {
      delete dependencies.dependencies[0].relativePaths[0].importSpecifiers[0].mainFile.isDefault;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('expected properties of importSpecifier.mainFile "isDefault,name", got "name"');
    });
    it('should throw when importSpecifier.mainFile.name is missing', function () {
      delete dependencies.dependencies[0].relativePaths[0].importSpecifiers[0].mainFile.isDefault;
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('expected properties of importSpecifier.mainFile "isDefault,name", got "name"');
    });
    it('should throw when importSpecifier.mainFile has an extra attribute', function () {
      dependencies.dependencies[0].relativePaths[0].importSpecifiers[0].mainFile.extra = 'invalid';
      (0, (_chai || _load_chai()).expect)(validateFunc).to.throw('expected properties of importSpecifier.mainFile "isDefault,name", got "extra,isDefault,name"');
    });
  });
});