"use strict";

var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
var _testUtil = require("../../common/testUtil");
var _Logger = _interopRequireDefault(require("../../Logger"));
var _wsFeatureFlag = require("./wsFeatureFlag");
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
describe('wsFeatureFlag', function () {
  var webex;
  beforeEach(function () {
    webex = (0, _testUtil.getTestUtilsWebex)();
    jest.clearAllMocks();
  });
  describe('WEBRTC_CALLING_OVER_WS_FEATURE_KEY', function () {
    it('should export the correct feature key constant', function () {
      expect(_wsFeatureFlag.WEBRTC_CALLING_OVER_WS_FEATURE_KEY).toBe('webrtc-calling-over-ws-CALL-219562');
    });
  });
  describe('isMobiusWssEnabled', function () {
    var traceSpy;
    beforeEach(function () {
      traceSpy = jest.spyOn(_Logger.default, 'trace');
    });
    it('should return true when feature flag is enabled with boolean true', function () {
      webex.internal.device.features.developer.get = jest.fn().mockReturnValue({
        value: true
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webex);
      expect(result).toBe(true);
      expect(webex.internal.device.features.developer.get).toHaveBeenCalledWith(_wsFeatureFlag.WEBRTC_CALLING_OVER_WS_FEATURE_KEY);
      expect(traceSpy).toHaveBeenCalledWith("Mobius WSS feature flag '".concat(_wsFeatureFlag.WEBRTC_CALLING_OVER_WS_FEATURE_KEY, "' resolved to: true (backend: true, localStorage: null)"), {
        file: 'wsFeatureFlag',
        method: 'isMobiusWssEnabled'
      });
    });
    it('should return false when feature flag is disabled with boolean false', function () {
      webex.internal.device.features.developer.get = jest.fn().mockReturnValue({
        value: false
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webex);
      expect(result).toBe(false);
      expect(traceSpy).toHaveBeenCalledWith("Mobius WSS feature flag '".concat(_wsFeatureFlag.WEBRTC_CALLING_OVER_WS_FEATURE_KEY, "' resolved to: false (backend: false, localStorage: null)"), {
        file: 'wsFeatureFlag',
        method: 'isMobiusWssEnabled'
      });
    });
    it('should return false when feature flag value is undefined', function () {
      webex.internal.device.features.developer.get = jest.fn().mockReturnValue({
        value: undefined
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webex);
      expect(result).toBe(false);
      expect(traceSpy).toHaveBeenCalledWith("Mobius WSS feature flag '".concat(_wsFeatureFlag.WEBRTC_CALLING_OVER_WS_FEATURE_KEY, "' resolved to: false (backend: false, localStorage: null)"), {
        file: 'wsFeatureFlag',
        method: 'isMobiusWssEnabled'
      });
    });
    it('should return false when feature flag returns null', function () {
      webex.internal.device.features.developer.get = jest.fn().mockReturnValue(null);
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webex);
      expect(result).toBe(false);
    });
    it('should return false when feature flag value is truthy but not boolean true (number)', function () {
      webex.internal.device.features.developer.get = jest.fn().mockReturnValue({
        value: 1
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webex);
      expect(result).toBe(false);
      expect(traceSpy).toHaveBeenCalledWith("Mobius WSS feature flag '".concat(_wsFeatureFlag.WEBRTC_CALLING_OVER_WS_FEATURE_KEY, "' resolved to: false (backend: false, localStorage: null)"), {
        file: 'wsFeatureFlag',
        method: 'isMobiusWssEnabled'
      });
    });
    it('should return false when feature flag value is truthy but not boolean true (string)', function () {
      webex.internal.device.features.developer.get = jest.fn().mockReturnValue({
        value: 'true'
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webex);
      expect(result).toBe(false);
    });
    it('should return false when feature flag value is truthy but not boolean true (object)', function () {
      webex.internal.device.features.developer.get = jest.fn().mockReturnValue({
        value: {}
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webex);
      expect(result).toBe(false);
    });
    it('should return false when webex.internal.device.features is missing', function () {
      var webexWithoutFeatures = _objectSpread(_objectSpread({}, webex), {}, {
        internal: _objectSpread(_objectSpread({}, webex.internal), {}, {
          device: _objectSpread(_objectSpread({}, webex.internal.device), {}, {
            features: undefined
          })
        })
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webexWithoutFeatures);
      expect(result).toBe(false);
    });
    it('should return false when webex.internal.device.features.developer is missing', function () {
      var webexWithoutDeveloper = _objectSpread(_objectSpread({}, webex), {}, {
        internal: _objectSpread(_objectSpread({}, webex.internal), {}, {
          device: _objectSpread(_objectSpread({}, webex.internal.device), {}, {
            features: {
              entitlement: webex.internal.device.features.entitlement,
              developer: undefined
            }
          })
        })
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webexWithoutDeveloper);
      expect(result).toBe(false);
    });
    it('should return false when webex.internal.device is missing', function () {
      var webexWithoutDevice = _objectSpread(_objectSpread({}, webex), {}, {
        internal: _objectSpread(_objectSpread({}, webex.internal), {}, {
          device: undefined
        })
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webexWithoutDevice);
      expect(result).toBe(false);
    });
    it('should return false when webex.internal is missing', function () {
      var webexWithoutInternal = _objectSpread(_objectSpread({}, webex), {}, {
        internal: undefined
      });
      var result = (0, _wsFeatureFlag.isMobiusWssEnabled)(webexWithoutInternal);
      expect(result).toBe(false);
    });
  });
});
//# sourceMappingURL=wsFeatureFlag.test.js.map
