'use strict';

var _chai;

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

var _checkVersionCompatibility;

function _load_checkVersionCompatibility() {
  return _checkVersionCompatibility = require('./check-version-compatibility');
}

var _constants;

function _load_constants() {
  return _constants = _interopRequireWildcard(require('../../constants'));
}

var _exceptions;

function _load_exceptions() {
  return _exceptions = require('./exceptions');
}

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var setServerVersion = function setServerVersion(serverVersion) {
  (_constants || _load_constants()).BIT_VERSION = serverVersion;
};

describe('check-version-compatibility', function () {
  describe('checkVersionCompatibilityOnTheServer', function () {
    it('should not throw any error when the major versions of the server and the client are the same', function () {
      setServerVersion('14.0.0');
      var func = function func() {
        return (0, (_checkVersionCompatibility || _load_checkVersionCompatibility()).checkVersionCompatibilityOnTheServer)('14.0.0');
      };
      (0, (_chai || _load_chai()).expect)(func).to.not.throw();
    });
    it('should not throw any error when the major version of the client is higher than the server', function () {
      setServerVersion('13.0.0');
      var func = function func() {
        return (0, (_checkVersionCompatibility || _load_checkVersionCompatibility()).checkVersionCompatibilityOnTheServer)('14.0.0');
      };
      (0, (_chai || _load_chai()).expect)(func).to.not.throw();
    });
    it('should throw an OldClientVersion exception when the major version of the server is higher than the client', function () {
      setServerVersion('15.0.0');
      var func = function func() {
        return (0, (_checkVersionCompatibility || _load_checkVersionCompatibility()).checkVersionCompatibilityOnTheServer)('14.0.0');
      };
      (0, (_chai || _load_chai()).expect)(func).to.throw((_exceptions || _load_exceptions()).OldClientVersion);
    });
    it('when there is a mismatch major version and the client version is less than 14 it should throw an error but not OldClientVersion', function () {
      setServerVersion('14.0.0');
      var func = function func() {
        return (0, (_checkVersionCompatibility || _load_checkVersionCompatibility()).checkVersionCompatibilityOnTheServer)('13.0.0');
      };
      (0, (_chai || _load_chai()).expect)(func).to.not.throw((_exceptions || _load_exceptions()).OldClientVersion);
      (0, (_chai || _load_chai()).expect)(func).to.throw();
    });
  });
});