"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
var _types = require("../../common/types");
var _Logger = _interopRequireDefault(require("../../Logger"));
var _mobiusSocketMapper = require("./mobiusSocketMapper");
var _constants = require("./constants");
describe('mobiusSocketMapper', function () {
  var warnSpy;
  beforeEach(function () {
    jest.clearAllMocks();
    warnSpy = jest.spyOn(_Logger.default, 'warn');
  });
  describe('deriveMobiusSocketMessageType', function () {
    describe('Supplementary services', function () {
      it('should return CALL_HOLD for hold service URI', function () {
        var uri = '/api/v1/calling/web/devices/device-123/services/callhold/hold';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.POST);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_HOLD);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return CALL_RESUME for resume service URI', function () {
        var uri = '/api/v1/calling/web/devices/device-123/services/callhold/resume';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.POST);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_RESUME);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return CALL_TRANSFER for transfer commit service URI', function () {
        var uri = '/api/v1/calling/web/devices/device-123/services/calltransfer/commit';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.POST);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_TRANSFER);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return UNKNOWN and log warning for unrecognized supplementary service', function () {
        var uri = '/api/v1/calling/web/devices/device-123/services/unknown/action';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.POST);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.UNKNOWN);
        expect(warnSpy).toHaveBeenCalledWith("Unrecognized supplementary service uri - uri: ".concat(uri, ", httpMethod: ").concat(_types.HTTP_METHODS.POST), {
          file: 'mobiusSocketMapper',
          method: 'deriveMobiusSocketMessageType'
        });
      });
    });
    describe('Call operations', function () {
      it('should return CALL_SETUP for call setup URI', function () {
        var uri = '/api/v1/calling/web/devices/device-123/call';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.POST);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_SETUP);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return CALL_MEDIA for call media URI', function () {
        var uri = '/api/v1/calling/web/devices/device-123/calls/call-456/media';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.PATCH);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_MEDIA);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return CALL_STATUS for call status URI', function () {
        var uri = '/api/v1/calling/web/devices/device-123/calls/call-456/status';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.PATCH);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_STATUS);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return CALL_STATE for calls/{callId} with PATCH method', function () {
        var uri = '/api/v1/calling/web/devices/device-123/calls/call-456';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.PATCH);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_STATE);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return CALL_DELETE for calls/{callId} with DELETE method', function () {
        var uri = '/api/v1/calling/web/devices/device-123/calls/call-456';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.DELETE);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_DELETE);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return UNKNOWN and log warning for calls/{callId} with unrecognized HTTP method', function () {
        var uri = '/api/v1/calling/web/devices/device-123/calls/call-456';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.GET);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.UNKNOWN);
        expect(warnSpy).toHaveBeenCalledWith("Unrecognized httpMethod for calls/{callId} - uri: ".concat(uri, ", httpMethod: ").concat(_types.HTTP_METHODS.GET), {
          file: 'mobiusSocketMapper',
          method: 'deriveMobiusSocketMessageType'
        });
      });
    });
    describe('Device operations', function () {
      it('should return REGISTER for device registration URI', function () {
        var uri = '/api/v1/calling/web/device';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.POST);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.REGISTER);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return UNREGISTER for devices/{deviceId} with DELETE method', function () {
        var uri = '/api/v1/calling/web/devices/device-123';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.DELETE);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.UNREGISTER);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return DEVICE_GET for devices/{deviceId} with GET method', function () {
        var uri = '/api/v1/calling/web/devices/device-123';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.GET);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.DEVICE_GET);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return UNKNOWN and log warning for devices/{deviceId} with unrecognized HTTP method', function () {
        var uri = '/api/v1/calling/web/devices/device-123';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.PATCH);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.UNKNOWN);
        expect(warnSpy).toHaveBeenCalledWith("Unrecognized httpMethod for devices/{deviceId} - uri: ".concat(uri, ", httpMethod: ").concat(_types.HTTP_METHODS.PATCH), {
          file: 'mobiusSocketMapper',
          method: 'deriveMobiusSocketMessageType'
        });
      });
      it('should return DEVICE_STATUS for devices/{deviceId}/status URI', function () {
        var uri = '/api/v1/calling/web/devices/device-123/status';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.PATCH);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.DEVICE_STATUS);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return DEVICE_STATUS for /status URI without /devices/ segment in path', function () {
        var uri = '/api/v1/calling/web/status';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.POST);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.DEVICE_STATUS);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return DEVICE_LIST for devices list URI without trailing ID', function () {
        var uri = '/api/v1/calling/web/devices';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.GET);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.DEVICE_LIST);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should return DEVICE_LIST for devices list URI with query parameters', function () {
        var uri = '/api/v1/calling/web/devices?userid=user-789';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.GET);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.DEVICE_LIST);
        expect(warnSpy).not.toHaveBeenCalled();
      });
    });
    describe('Edge cases', function () {
      it('should return UNKNOWN and log warning when uri is undefined', function () {
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(undefined, _types.HTTP_METHODS.GET);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.UNKNOWN);
        expect(warnSpy).toHaveBeenCalledWith('Cannot derive Mobius socket message type: uri is empty', {
          file: 'mobiusSocketMapper',
          method: 'deriveMobiusSocketMessageType'
        });
      });
      it('should return UNKNOWN and log warning when uri is empty string', function () {
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)('', _types.HTTP_METHODS.GET);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.UNKNOWN);
        expect(warnSpy).toHaveBeenCalledWith('Cannot derive Mobius socket message type: uri is empty', {
          file: 'mobiusSocketMapper',
          method: 'deriveMobiusSocketMessageType'
        });
      });
      it('should return UNKNOWN and log warning for completely unrecognized URI pattern', function () {
        var uri = '/api/v1/completely/unrecognized/path';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.POST);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.UNKNOWN);
        expect(warnSpy).toHaveBeenCalledWith("Unrecognized uri pattern for Mobius socket - uri: ".concat(uri, ", httpMethod: ").concat(_types.HTTP_METHODS.POST), {
          file: 'mobiusSocketMapper',
          method: 'deriveMobiusSocketMessageType'
        });
      });
      it('should never return DEVICE_STATUS when /calls/ is present in path ending with /status', function () {
        // The DEVICE_STATUS check explicitly excludes URIs containing /calls/. Any
        // call-scoped /status URI must resolve to CALL_STATUS via the earlier branch,
        // and must never fall through to DEVICE_STATUS even if check ordering changes.
        var uri = '/api/v1/calling/web/devices/device-123/calls/call-456/status';
        var result = (0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(uri, _types.HTTP_METHODS.PATCH);
        expect(result).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_STATUS);
        expect(result).not.toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.DEVICE_STATUS);
        expect(warnSpy).not.toHaveBeenCalled();
      });
      it('should prioritize call sub-resources over bare call patterns', function () {
        var mediaUri = '/api/v1/calling/web/devices/device-123/calls/call-456/media';
        var statusUri = '/api/v1/calling/web/devices/device-123/calls/call-456/status';
        expect((0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(mediaUri, _types.HTTP_METHODS.PATCH)).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_MEDIA);
        expect((0, _mobiusSocketMapper.deriveMobiusSocketMessageType)(statusUri, _types.HTTP_METHODS.PATCH)).toBe(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_STATUS);
      });
    });
  });
  describe('isSupplementaryServiceMessageType', function () {
    it('should return true for CALL_HOLD message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_HOLD);
      expect(result).toBe(true);
    });
    it('should return true for CALL_RESUME message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_RESUME);
      expect(result).toBe(true);
    });
    it('should return true for CALL_TRANSFER message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_TRANSFER);
      expect(result).toBe(true);
    });
    it('should return false for REGISTER message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.REGISTER);
      expect(result).toBe(false);
    });
    it('should return false for CALL_SETUP message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_SETUP);
      expect(result).toBe(false);
    });
    it('should return false for CALL_STATE message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_STATE);
      expect(result).toBe(false);
    });
    it('should return false for CALL_DELETE message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_DELETE);
      expect(result).toBe(false);
    });
    it('should return false for DEVICE_STATUS message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.DEVICE_STATUS);
      expect(result).toBe(false);
    });
    it('should return false for UNKNOWN message type', function () {
      var result = (0, _mobiusSocketMapper.isSupplementaryServiceMessageType)(_constants.MOBIUS_SOCKET_MESSAGE_TYPE.UNKNOWN);
      expect(result).toBe(false);
    });
  });
});
//# sourceMappingURL=mobiusSocketMapper.test.js.map
