"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

function _chai() {
  const data = require("chai");

  _chai = function () {
    return data;
  };

  return data;
}

function _checkVersionCompatibility() {
  const data = require("./check-version-compatibility");

  _checkVersionCompatibility = function () {
    return data;
  };

  return data;
}

function constants() {
  const data = _interopRequireWildcard(require("../../constants"));

  constants = function () {
    return data;
  };

  return data;
}

function _exceptions() {
  const data = require("./exceptions");

  _exceptions = function () {
    return data;
  };

  return data;
}

const setServerVersion = serverVersion => {
  constants().BIT_VERSION = serverVersion;
};

describe('check-version-compatibility', () => {
  describe('checkVersionCompatibilityOnTheServer', () => {
    it('should not throw any error when the major versions of the server and the client are the same', () => {
      setServerVersion('14.0.0');

      const func = () => (0, _checkVersionCompatibility().checkVersionCompatibilityOnTheServer)('14.0.0');

      (0, _chai().expect)(func).to.not.throw();
    });
    it('should not throw any error when the major version of the client is higher than the server', () => {
      setServerVersion('13.0.0');

      const func = () => (0, _checkVersionCompatibility().checkVersionCompatibilityOnTheServer)('14.0.0');

      (0, _chai().expect)(func).to.not.throw();
    });
    it('should throw an OldClientVersion exception when the major version of the server is higher than the client', () => {
      setServerVersion('15.0.0');

      const func = () => (0, _checkVersionCompatibility().checkVersionCompatibilityOnTheServer)('14.0.0');

      (0, _chai().expect)(func).to.throw(_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', () => {
      setServerVersion('14.0.0');

      const func = () => (0, _checkVersionCompatibility().checkVersionCompatibilityOnTheServer)('13.0.0');

      (0, _chai().expect)(func).to.not.throw(_exceptions().OldClientVersion);
      (0, _chai().expect)(func).to.throw();
    });
  });
});