"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 _index = require("./index");
var _types = require("./types");
var _constants = require("../CallingClient/constants");
var _CallingDeviceError = require("../Errors/catalog/CallingDeviceError");
var _types2 = require("../Errors/types");
var _types3 = require("../common/types");
var _Logger = _interopRequireDefault(require("../Logger"));
var _CallError = require("../Errors/catalog/CallError");
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; } /* eslint-disable dot-notation */
var webex = (0, _testUtil.getTestUtilsWebex)();
describe('CALLING: Metric tests', function () {
  var metricManager = (0, _index.getMetricManager)(webex, _types3.ServiceIndicator.CALLING);
  var mockDeviceInfo = (0, _testUtil.getMockDeviceInfo)();
  var submitClientMetricSpy = jest.spyOn(webex.internal.metrics, 'submitClientMetrics');
  var MOCK_VERSION_NUMBER = '1.0.0';
  var originalEnv = process.env;
  var mockCallId = '123456';
  var mockCorrelationId = '0931237';
  var mockCallAction = 'S_SEND_CALL_SETUP';
  var mockMediaAction = 'S_SEND_ROAP_OFFER';
  beforeEach(function () {
    submitClientMetricSpy.mockClear();
    process.env = _objectSpread(_objectSpread({}, originalEnv), {}, {
      CALLING_SDK_VERSION: MOCK_VERSION_NUMBER
    });
  });
  it('initialize metric manager', function () {
    expect(metricManager).not.toBeNull();
    expect(metricManager['deviceInfo']).toBeUndefined();
  });
  it('update deviceInfo in metric manager', function () {
    expect(metricManager['deviceInfo']).toBeUndefined();
    metricManager.setDeviceInfo(mockDeviceInfo);
    expect(metricManager['deviceInfo']).toEqual(mockDeviceInfo);
  });
  describe('CallingClient metric tests', function () {
    it('submit registration success metric', function () {
      metricManager.setDeviceInfo(mockDeviceInfo);
      var expectedData = {
        tags: {
          action: _types.REG_ACTION.REGISTER,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          reg_source: _constants.REGISTRATION_UTIL,
          server_type: 'PRIMARY',
          trackingId: 'webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15'
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitRegistrationMetric(_types.METRIC_EVENT.REGISTRATION, _types.REG_ACTION.REGISTER, _types.METRIC_TYPE.BEHAVIORAL, _constants.REGISTRATION_UTIL, 'PRIMARY', 'webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15', undefined, undefined);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.REGISTRATION, expectedData);
    });
    it('submit registration failure metric', function () {
      metricManager.setDeviceInfo(mockDeviceInfo);
      var clientError = (0, _CallingDeviceError.createClientError)('', {}, _types2.ERROR_TYPE.DEFAULT, _types3.RegistrationStatus.INACTIVE);
      var err = {};
      err.context = {};
      err.message = 'Unknown Error';
      err.type = _types2.ERROR_TYPE.SERVICE_UNAVAILABLE;
      clientError.setError(err);
      var expectedData = {
        tags: {
          action: _types.REG_ACTION.REGISTER,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          reg_source: _constants.REGISTRATION_UTIL,
          server_type: 'BACKUP',
          trackingId: 'webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15',
          error: clientError.getError().message,
          error_type: clientError.getError().type
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitRegistrationMetric(_types.METRIC_EVENT.REGISTRATION_ERROR, _types.REG_ACTION.REGISTER, _types.METRIC_TYPE.BEHAVIORAL, _constants.REGISTRATION_UTIL, 'BACKUP', 'webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15', undefined, clientError);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.REGISTRATION_ERROR, expectedData);
    });
    it('submit keepalive failure metric', function () {
      metricManager.setDeviceInfo(mockDeviceInfo);
      var clientError = (0, _CallingDeviceError.createClientError)('', {}, _types2.ERROR_TYPE.DEFAULT, _types3.RegistrationStatus.INACTIVE);
      var err = {};
      err.context = {};
      err.message = 'Unknown Error';
      err.type = _types2.ERROR_TYPE.NOT_FOUND;
      clientError.setError(err);
      var expectedData = {
        tags: {
          action: _types.REG_ACTION.KEEPALIVE_FAILURE,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          reg_source: _constants.REGISTRATION_UTIL,
          server_type: 'BACKUP',
          trackingId: 'webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15',
          keepalive_count: 1,
          error: clientError.getError().message,
          error_type: clientError.getError().type
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitRegistrationMetric(_types.METRIC_EVENT.KEEPALIVE_ERROR, _types.REG_ACTION.KEEPALIVE_FAILURE, _types.METRIC_TYPE.BEHAVIORAL, _constants.REGISTRATION_UTIL, 'BACKUP', 'webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15', 1, clientError);
      expect(submitClientMetricSpy).toHaveBeenCalledWith(_types.METRIC_EVENT.KEEPALIVE_ERROR, expectedData);
    });
    it('submit unknown registration metric', function () {
      var logSpy = jest.spyOn(_Logger.default, 'warn');
      metricManager.submitRegistrationMetric('invalidMetricName', _types.REG_ACTION.REGISTER, _types.METRIC_TYPE.OPERATIONAL, _constants.REGISTRATION_UTIL, 'PRIMARY', undefined, undefined, undefined);
      expect(submitClientMetricSpy).not.toBeCalled();
      expect(logSpy).toBeCalledOnceWith('Invalid metric name received. Rejecting request to submit metric.', {
        file: 'metric',
        method: 'submitRegistrationMetric'
      });
    });
  });
  describe('Call Metric tests', function () {
    beforeAll(function () {
      metricManager.setDeviceInfo(mockDeviceInfo);
    });
    it('submit call success metric', function () {
      var expectedData = {
        tags: {
          action: mockCallAction,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          call_id: mockCallId,
          correlation_id: mockCorrelationId
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitCallMetric(_types.METRIC_EVENT.CALL, mockCallAction, _types.METRIC_TYPE.BEHAVIORAL, mockCallId, mockCorrelationId);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.CALL, expectedData);
    });
    it('submit call failure metric', function () {
      var callError = (0, _CallError.createCallError)('', {}, _types2.ERROR_TYPE.DEFAULT, mockCorrelationId, _types2.ERROR_LAYER.CALL_CONTROL);
      var err = {};
      err.context = {};
      err.message = 'An invalid status update has been received for the call. Wait a moment and try again.';
      err.type = _types2.ERROR_TYPE.FORBIDDEN_ERROR;
      callError.setCallError(err);
      var expectedData = {
        tags: {
          action: mockCallAction,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          call_id: mockCallId,
          correlation_id: mockCorrelationId,
          error: callError.getCallError().message,
          error_type: callError.getCallError().type
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitCallMetric(_types.METRIC_EVENT.CALL_ERROR, mockCallAction, _types.METRIC_TYPE.BEHAVIORAL, mockCallId, mockCorrelationId, callError);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.CALL_ERROR, expectedData);
    });
    it('submit unknown call metric', function () {
      var logSpy = jest.spyOn(_Logger.default, 'warn');
      metricManager.submitCallMetric('invalidMetricName', mockCallAction, _types.METRIC_TYPE.OPERATIONAL, mockCallId, mockCorrelationId);
      expect(submitClientMetricSpy).not.toBeCalled();
      expect(logSpy).toBeCalledOnceWith('Invalid metric name received. Rejecting request to submit metric.', {
        file: 'metric',
        method: 'submitCallMetric'
      });
    });
  });
  describe('Media Metric tests', function () {
    var mockSdp = 'sdpInformation';
    beforeAll(function () {
      metricManager.setDeviceInfo(mockDeviceInfo);
    });
    it('submit media success metric', function () {
      var expectedData = {
        tags: {
          action: mockMediaAction,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          call_id: mockCallId,
          correlation_id: mockCorrelationId,
          local_media_details: mockSdp,
          remote_media_details: mockSdp
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMediaMetric(_types.METRIC_EVENT.MEDIA, mockMediaAction, _types.METRIC_TYPE.BEHAVIORAL, mockCallId, mockCorrelationId, mockSdp, mockSdp);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MEDIA, expectedData);
    });
    it('submit media failure metric', function () {
      var callError = (0, _CallError.createCallError)('', {}, _types2.ERROR_TYPE.DEFAULT, mockCorrelationId, _types2.ERROR_LAYER.MEDIA);
      var err = {};
      err.context = {};
      err.message = 'An error occurred while parsing the provided information. Wait a moment and try again.';
      err.type = _types2.ERROR_TYPE.SERVICE_UNAVAILABLE;
      callError.setCallError(err);
      var expectedData = {
        tags: {
          action: mockMediaAction,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          call_id: mockCallId,
          correlation_id: mockCorrelationId,
          local_media_details: mockSdp,
          remote_media_details: mockSdp,
          error: callError.getCallError().message,
          error_type: callError.getCallError().type
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMediaMetric(_types.METRIC_EVENT.MEDIA_ERROR, mockMediaAction, _types.METRIC_TYPE.BEHAVIORAL, mockCallId, mockCorrelationId, mockSdp, mockSdp, undefined, callError);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MEDIA_ERROR, expectedData);
    });
    it('submit unknown media metric', function () {
      var logSpy = jest.spyOn(_Logger.default, 'warn');
      metricManager.submitMediaMetric('invalidMetricName', mockMediaAction, _types.METRIC_TYPE.OPERATIONAL, mockCallId, mockCorrelationId, mockSdp, mockSdp);
      expect(submitClientMetricSpy).not.toBeCalled();
      expect(logSpy).toBeCalledOnceWith('Invalid metric name received. Rejecting request to submit metric.', {
        file: 'metric',
        method: 'submitMediaMetric'
      });
    });
  });
  describe('BNR metric tests', function () {
    beforeAll(function () {
      metricManager.setDeviceInfo(mockDeviceInfo);
    });
    it('submit bnr enabled metric', function () {
      var expectedData = {
        tags: {
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          call_id: mockCallId,
          correlation_id: mockCorrelationId
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitBNRMetric(_types.METRIC_EVENT.BNR_ENABLED, _types.METRIC_TYPE.BEHAVIORAL, mockCallId, mockCorrelationId);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.BNR_ENABLED, expectedData);
    });
    it('submit bnr disabled metric', function () {
      var expectedData = {
        tags: {
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          call_id: mockCallId,
          correlation_id: mockCorrelationId
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitBNRMetric(_types.METRIC_EVENT.BNR_DISABLED, _types.METRIC_TYPE.BEHAVIORAL, mockCallId, mockCorrelationId);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.BNR_DISABLED, expectedData);
    });
    it('submit unknown bnr metric', function () {
      var logSpy = jest.spyOn(_Logger.default, 'warn');
      metricManager.submitBNRMetric('invalidMetricName', _types.METRIC_TYPE.BEHAVIORAL, mockCallId, mockCorrelationId);
      expect(submitClientMetricSpy).not.toBeCalled();
      expect(logSpy).toBeCalledOnceWith('Invalid metric name received. Rejecting request to submit metric.', {
        file: 'metric',
        method: 'submitBNRMetric'
      });
    });
  });
  describe('Voicemail metric tests', function () {
    var originalProcess = global.process;
    beforeAll(function () {
      return metricManager.setDeviceInfo(mockDeviceInfo);
    });
    afterEach(function () {
      global.process = originalProcess;
    });
    it('submit voicemail success metric', function () {
      var expectedData1 = {
        tags: {
          action: _types.VOICEMAIL_ACTION.GET_VOICEMAILS,
          device_id: mockDeviceInfo.device.deviceId
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          calling_sdk_version: MOCK_VERSION_NUMBER
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitVoicemailMetric(_types.METRIC_EVENT.VOICEMAIL, _types.VOICEMAIL_ACTION.GET_VOICEMAILS, _types.METRIC_TYPE.BEHAVIORAL);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.VOICEMAIL, expectedData1);
      submitClientMetricSpy.mockClear();
      var expectedData2 = _objectSpread(_objectSpread({}, expectedData1), {}, {
        tags: _objectSpread(_objectSpread({}, expectedData1.tags), {}, {
          message_id: 'messageId',
          action: _types.VOICEMAIL_ACTION.DELETE
        })
      });
      metricManager.submitVoicemailMetric(_types.METRIC_EVENT.VOICEMAIL, _types.VOICEMAIL_ACTION.DELETE, _types.METRIC_TYPE.BEHAVIORAL, 'messageId');
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.VOICEMAIL, expectedData2);
    });
    it('submit voicemail failure metric', function () {
      var errorMessage = 'User is not authenticated';
      var expectedData1 = {
        tags: {
          action: _types.VOICEMAIL_ACTION.GET_VOICEMAILS,
          device_id: mockDeviceInfo.device.deviceId,
          message_id: undefined,
          error: errorMessage,
          status_code: 401
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          calling_sdk_version: MOCK_VERSION_NUMBER
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitVoicemailMetric(_types.METRIC_EVENT.VOICEMAIL_ERROR, _types.VOICEMAIL_ACTION.GET_VOICEMAILS, _types.METRIC_TYPE.BEHAVIORAL, undefined, errorMessage, 401);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.VOICEMAIL_ERROR, expectedData1);
      submitClientMetricSpy.mockClear();
      var expectedData2 = _objectSpread(_objectSpread({}, expectedData1), {}, {
        tags: _objectSpread(_objectSpread({}, expectedData1.tags), {}, {
          message_id: 'messageId',
          action: _types.VOICEMAIL_ACTION.DELETE
        })
      });
      metricManager.submitVoicemailMetric(_types.METRIC_EVENT.VOICEMAIL_ERROR, _types.VOICEMAIL_ACTION.DELETE, _types.METRIC_TYPE.BEHAVIORAL, 'messageId', errorMessage, 401);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.VOICEMAIL_ERROR, expectedData2);
    });
    it('submit voicemail metric with undefined process object', function () {
      // Mock process as undefined (browser environment)
      global.process = undefined;
      var expectedData = {
        tags: {
          action: _types.VOICEMAIL_ACTION.GET_VOICEMAILS,
          device_id: mockDeviceInfo.device.deviceId
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          calling_sdk_version: _constants.VERSION
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitVoicemailMetric(_types.METRIC_EVENT.VOICEMAIL, _types.VOICEMAIL_ACTION.GET_VOICEMAILS, _types.METRIC_TYPE.BEHAVIORAL);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.VOICEMAIL, expectedData);
    });
    it('submit voicemail error metric with undefined process object', function () {
      // Mock process as undefined (browser environment)
      global.process = undefined;
      var errorMessage = 'Network error';
      var expectedData = {
        tags: {
          action: _types.VOICEMAIL_ACTION.MARK_READ,
          device_id: mockDeviceInfo.device.deviceId,
          message_id: 'msg-123',
          error: errorMessage,
          status_code: 500
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          calling_sdk_version: _constants.VERSION
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitVoicemailMetric(_types.METRIC_EVENT.VOICEMAIL_ERROR, _types.VOICEMAIL_ACTION.MARK_READ, _types.METRIC_TYPE.BEHAVIORAL, 'msg-123', errorMessage, 500);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.VOICEMAIL_ERROR, expectedData);
    });
    it('submit unknown voicemail metric', function () {
      var logSpy = jest.spyOn(_Logger.default, 'warn');
      metricManager.submitVoicemailMetric('invalidMetricName', _types.VOICEMAIL_ACTION.GET_VOICEMAILS, _types.METRIC_TYPE.BEHAVIORAL);
      expect(submitClientMetricSpy).not.toBeCalled();
      expect(logSpy).toBeCalledOnceWith('Invalid metric name received. Rejecting request to submit metric.', {
        file: 'metric',
        method: 'submitVoicemailMetric'
      });
    });
  });
  describe('Calling_Sdk_Version fallback test', function () {
    it('submit metric with fallback version', function () {
      process.env = {};
      metricManager.setDeviceInfo(mockDeviceInfo);
      var expectedData = {
        tags: {
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: _constants.VERSION,
          call_id: mockCallId,
          correlation_id: mockCorrelationId
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitBNRMetric(_types.METRIC_EVENT.BNR_ENABLED, _types.METRIC_TYPE.BEHAVIORAL, mockCallId, mockCorrelationId);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.BNR_ENABLED, expectedData);
    });
  });
  describe('Connection metric tests', function () {
    beforeAll(function () {
      return metricManager.setDeviceInfo(mockDeviceInfo);
    });
    it('submit connection metric for network flap', function () {
      var downTimestamp = '2026-05-04T10:00:00.000Z';
      var upTimestamp = '2026-05-04T10:05:00.000Z';
      var expectedData = {
        tags: {
          metricAction: 'network_flap',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          downTimestamp: downTimestamp,
          upTimestamp: upTimestamp
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitConnectionMetrics(_types.METRIC_EVENT.CONNECTION_ERROR, _types.CONNECTION_ACTION.NETWORK_FLAP, _types.METRIC_TYPE.BEHAVIORAL, downTimestamp, upTimestamp);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.CONNECTION_ERROR, expectedData);
    });
    it('submit connection metric for mercury down', function () {
      var downTimestamp = '2026-05-04T10:10:00.000Z';
      var upTimestamp = '2026-05-04T10:15:00.000Z';
      var expectedData = {
        tags: {
          metricAction: 'mercury_down',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          downTimestamp: downTimestamp,
          upTimestamp: upTimestamp
        },
        type: _types.METRIC_TYPE.OPERATIONAL
      };
      metricManager.submitConnectionMetrics(_types.METRIC_EVENT.CONNECTION_ERROR, _types.CONNECTION_ACTION.MERCURY_DOWN, _types.METRIC_TYPE.OPERATIONAL, downTimestamp, upTimestamp);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.CONNECTION_ERROR, expectedData);
    });
  });
  describe('Region Info metric tests', function () {
    beforeAll(function () {
      return metricManager.setDeviceInfo(mockDeviceInfo);
    });
    it('submit region info metric with all parameters', function () {
      var trackingId = 'track-region-123';
      var mobiusHost = 'mobius-us-east.webex.com';
      var clientRegion = 'US-EAST';
      var countryCode = 'US';
      var expectedData = {
        tags: {
          action: 'region-info',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          mobius_host: mobiusHost,
          client_region: clientRegion,
          country_code: countryCode,
          tracking_id: trackingId
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitRegionInfoMetric(_types.METRIC_EVENT.MOBIUS_DISCOVERY, 'region-info', _types.METRIC_TYPE.BEHAVIORAL, mobiusHost, clientRegion, countryCode, trackingId);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_DISCOVERY, expectedData);
    });
    it('submit region info metric without tracking ID', function () {
      var mobiusHost = 'mobius-eu-west.webex.com';
      var clientRegion = 'EU-WEST';
      var countryCode = 'GB';
      var expectedData = {
        tags: {
          action: 'region-info',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          mobius_host: mobiusHost,
          client_region: clientRegion,
          country_code: countryCode,
          tracking_id: undefined
        },
        type: _types.METRIC_TYPE.OPERATIONAL
      };
      metricManager.submitRegionInfoMetric(_types.METRIC_EVENT.MOBIUS_DISCOVERY, 'region-info', _types.METRIC_TYPE.OPERATIONAL, mobiusHost, clientRegion, countryCode, undefined);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_DISCOVERY, expectedData);
    });
  });
  describe('Mobius Servers metric tests', function () {
    beforeAll(function () {
      return metricManager.setDeviceInfo(mockDeviceInfo);
    });
    it('submit mobius servers metric with primary and backup servers', function () {
      var trackingId = 'track-servers-456';
      var mobiusServers = {
        primary: {
          region: 'US-EAST',
          uris: ['wss://mobius-us-east-1.webex.com/api/v1', 'wss://mobius-us-east-2.webex.com/api/v1']
        },
        backup: {
          region: 'US-WEST',
          uris: ['wss://mobius-us-west-1.webex.com/api/v1']
        }
      };
      var expectedData = {
        tags: {
          action: 'mobius-servers',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          primary_mobius_servers_region: 'US-EAST',
          primary_mobius_servers_uris: 'wss://mobius-us-east-1.webex.com/api/v1,wss://mobius-us-east-2.webex.com/api/v1',
          backup_mobius_servers_region: 'US-WEST',
          backup_mobius_servers_uris: 'wss://mobius-us-west-1.webex.com/api/v1',
          tracking_id: trackingId
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMobiusServersMetric(_types.METRIC_EVENT.MOBIUS_DISCOVERY, 'mobius-servers', _types.METRIC_TYPE.BEHAVIORAL, mobiusServers, trackingId);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_DISCOVERY, expectedData);
    });
    it('submit mobius servers metric without tracking ID', function () {
      var mobiusServers = {
        primary: {
          region: 'EU-CENTRAL',
          uris: ['wss://mobius-eu-central.webex.com/api/v1']
        },
        backup: {
          region: 'EU-WEST',
          uris: ['wss://mobius-eu-west.webex.com/api/v1', 'wss://mobius-eu-west-2.webex.com/api/v1']
        }
      };
      var expectedData = {
        tags: {
          action: 'mobius-servers',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          primary_mobius_servers_region: 'EU-CENTRAL',
          primary_mobius_servers_uris: 'wss://mobius-eu-central.webex.com/api/v1',
          backup_mobius_servers_region: 'EU-WEST',
          backup_mobius_servers_uris: 'wss://mobius-eu-west.webex.com/api/v1,wss://mobius-eu-west-2.webex.com/api/v1',
          tracking_id: undefined
        },
        type: _types.METRIC_TYPE.OPERATIONAL
      };
      metricManager.submitMobiusServersMetric(_types.METRIC_EVENT.MOBIUS_DISCOVERY, 'mobius-servers', _types.METRIC_TYPE.OPERATIONAL, mobiusServers, undefined);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_DISCOVERY, expectedData);
    });
  });
  describe('Mobius Socket metric tests', function () {
    beforeAll(function () {
      return metricManager.setDeviceInfo(mockDeviceInfo);
    });
    it('submit mobius socket connect success metric', function () {
      var wssUrl = 'wss://mobius.webex.com/api/v1';
      var trackingId = 'track-socket-123';
      var expectedData = {
        tags: {
          action: 'connect',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          wss_url: wssUrl,
          tracking_id: trackingId,
          event_type: undefined
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMobiusSocketMetric(_types.METRIC_EVENT.MOBIUS_SOCKET, _types.MOBIUS_SOCKET_ACTION.CONNECT, _types.METRIC_TYPE.BEHAVIORAL, wssUrl, trackingId);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_SOCKET, expectedData);
    });
    it('submit mobius socket disconnect success metric', function () {
      var expectedData = {
        tags: {
          action: 'disconnect',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          wss_url: undefined,
          tracking_id: undefined,
          event_type: undefined
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMobiusSocketMetric(_types.METRIC_EVENT.MOBIUS_SOCKET, _types.MOBIUS_SOCKET_ACTION.DISCONNECT, _types.METRIC_TYPE.BEHAVIORAL);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_SOCKET, expectedData);
    });
    it('submit mobius socket listener registered metric', function () {
      var expectedData = {
        tags: {
          action: 'listener_registered',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          wss_url: undefined,
          tracking_id: undefined,
          event_type: undefined
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMobiusSocketMetric(_types.METRIC_EVENT.MOBIUS_SOCKET, _types.MOBIUS_SOCKET_ACTION.LISTENER_REGISTERED, _types.METRIC_TYPE.BEHAVIORAL);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_SOCKET, expectedData);
    });
    it('submit mobius socket listener unregistered metric', function () {
      var expectedData = {
        tags: {
          action: 'listener_unregistered',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          wss_url: undefined,
          tracking_id: undefined,
          event_type: undefined
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMobiusSocketMetric(_types.METRIC_EVENT.MOBIUS_SOCKET, _types.MOBIUS_SOCKET_ACTION.LISTENER_UNREGISTERED, _types.METRIC_TYPE.BEHAVIORAL);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_SOCKET, expectedData);
    });
    it('submit mobius socket error metric with connection failure', function () {
      var wssUrl = 'wss://mobius.webex.com/api/v1';
      var trackingId = 'track-error-456';
      var error = 'WebSocket connection failed: timeout';
      var expectedData = {
        tags: {
          action: 'connect',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          wss_url: wssUrl,
          tracking_id: trackingId,
          event_type: undefined,
          error: error
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMobiusSocketMetric(_types.METRIC_EVENT.MOBIUS_SOCKET_ERROR, _types.MOBIUS_SOCKET_ACTION.CONNECT, _types.METRIC_TYPE.BEHAVIORAL, wssUrl, trackingId, error);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_SOCKET_ERROR, expectedData);
    });
    it('submit mobius socket error metric with registration down event', function () {
      var trackingId = 'track-regdown-789';
      var eventType = 'registration.down';
      var expectedData = {
        tags: {
          action: 'registration_down',
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          wss_url: undefined,
          tracking_id: trackingId,
          event_type: eventType,
          error: undefined
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitMobiusSocketMetric(_types.METRIC_EVENT.MOBIUS_SOCKET_ERROR, _types.MOBIUS_SOCKET_ACTION.REGISTRATION_DOWN, _types.METRIC_TYPE.BEHAVIORAL, undefined, trackingId, undefined, eventType);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.MOBIUS_SOCKET_ERROR, expectedData);
    });
    it('submit unknown mobius socket metric', function () {
      var logSpy = jest.spyOn(_Logger.default, 'warn');
      metricManager.submitMobiusSocketMetric('invalidMetricName', _types.MOBIUS_SOCKET_ACTION.CONNECT, _types.METRIC_TYPE.BEHAVIORAL);
      expect(submitClientMetricSpy).not.toBeCalled();
      expect(logSpy).toBeCalledOnceWith('Invalid metric name received. Rejecting request to submit metric.', {
        file: 'metric',
        method: 'submitMobiusSocketMetric'
      });
    });
  });
  describe('Upload Logs metric tests', function () {
    beforeAll(function () {
      return metricManager.setDeviceInfo(mockDeviceInfo);
    });
    it('submit upload logs success metric includes broadworksCorrelationInfo', function () {
      var trackingId = 'track-123';
      var feedbackId = 'feed-456';
      var correlationId = 'corr-789';
      var callId = 'call-123';
      var broadworksCorrelationInfo = 'bw-corr-abc';
      var expectedData = {
        tags: {
          action: _types.UPLOAD_LOGS_ACTION,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          correlation_id: correlationId,
          broadworksCorrelationInfo: broadworksCorrelationInfo,
          tracking_id: trackingId,
          feedback_id: feedbackId,
          call_id: callId
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitUploadLogsMetric(_types.METRIC_EVENT.UPLOAD_LOGS_SUCCESS, _types.UPLOAD_LOGS_ACTION, _types.METRIC_TYPE.BEHAVIORAL, trackingId, feedbackId, correlationId, undefined, callId, broadworksCorrelationInfo);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.UPLOAD_LOGS_SUCCESS, expectedData);
    });
    it('submit upload logs failure metric includes error and broadworksCorrelationInfo', function () {
      var feedbackId = 'feed-456';
      var correlationId = 'corr-789';
      var callId = 'call-123';
      var broadworksCorrelationInfo = 'bw-corr-abc';
      var errorStack = 'some error stack';
      var expectedData = {
        tags: {
          action: _types.UPLOAD_LOGS_ACTION,
          device_id: mockDeviceInfo.device.deviceId,
          service_indicator: _types3.ServiceIndicator.CALLING
        },
        fields: {
          device_url: mockDeviceInfo.device.clientDeviceUri,
          mobius_url: mockDeviceInfo.device.uri,
          calling_sdk_version: MOCK_VERSION_NUMBER,
          correlation_id: correlationId,
          broadworksCorrelationInfo: broadworksCorrelationInfo,
          tracking_id: undefined,
          feedback_id: feedbackId,
          call_id: callId,
          error: errorStack
        },
        type: _types.METRIC_TYPE.BEHAVIORAL
      };
      metricManager.submitUploadLogsMetric(_types.METRIC_EVENT.UPLOAD_LOGS_FAILED, _types.UPLOAD_LOGS_ACTION, _types.METRIC_TYPE.BEHAVIORAL, undefined, feedbackId, correlationId, errorStack, callId, broadworksCorrelationInfo);
      expect(submitClientMetricSpy).toBeCalledOnceWith(_types.METRIC_EVENT.UPLOAD_LOGS_FAILED, expectedData);
    });
  });
});
//# sourceMappingURL=index.test.js.map
