@webex/calling 3.12.0-mobius-socket.14 → 3.12.0-mobius-socket.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1884,5 +1884,183 @@ describe('Registration Tests', function () {
1884
1884
  }, _callee39);
1885
1885
  })));
1886
1886
  });
1887
+ describe('handleRegistrationDownEvent tests', function () {
1888
+ var registrationDownEvent = {
1889
+ type: 'async_event',
1890
+ eventId: 'evt-1',
1891
+ trackingId: 'tid-1',
1892
+ data: {
1893
+ eventType: 'registration.down',
1894
+ deviceInfo: {
1895
+ userId: 'u1',
1896
+ device: {
1897
+ deviceId: 'd1',
1898
+ uri: 'https://mobius/device/d1',
1899
+ status: 'ACTIVE'
1900
+ }
1901
+ }
1902
+ }
1903
+ };
1904
+ beforeEach(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee40() {
1905
+ return _regenerator.default.wrap(function (_context40) {
1906
+ while (1) switch (_context40.prev = _context40.next) {
1907
+ case 0:
1908
+ postRegistrationSpy.mockResolvedValueOnce(successPayload);
1909
+ _context40.next = 1;
1910
+ return reg.triggerRegistration();
1911
+ case 1:
1912
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
1913
+ case 2:
1914
+ case "end":
1915
+ return _context40.stop();
1916
+ }
1917
+ }, _callee40);
1918
+ })));
1919
+ afterEach(function () {
1920
+ var calls = (0, _values.default)(reg.callManager.getActiveCalls());
1921
+ calls.forEach(function (call) {
1922
+ call.end();
1923
+ });
1924
+ reg.callManager.callCollection = {};
1925
+ });
1926
+ it('runs cleanup immediately when no active calls are present (socket disabled)', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee41() {
1927
+ var clearKeepaliveSpy, setStatusSpy, disconnectSocketSpy;
1928
+ return _regenerator.default.wrap(function (_context41) {
1929
+ while (1) switch (_context41.prev = _context41.next) {
1930
+ case 0:
1931
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
1932
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
1933
+ disconnectSocketSpy = jest.spyOn(_request.APIRequest.getInstance({
1934
+ webex: webex
1935
+ }), 'disconnectFromMobiusSocket');
1936
+ lineEmitter.mockClear();
1937
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
1938
+ _context41.next = 1;
1939
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
1940
+ case 1:
1941
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
1942
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
1943
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
1944
+ expect(reg.reconnectPending).toBe(false);
1945
+ expect(reg.scheduled429Retry).toBe(false);
1946
+ expect(reg.failoverImmediately).toBe(false);
1947
+ expect(reg.retryAfter).toBeUndefined();
1948
+ expect(reg.registerRetry).toBe(false);
1949
+ expect(disconnectSocketSpy).not.toHaveBeenCalled();
1950
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
1951
+ case 2:
1952
+ case "end":
1953
+ return _context41.stop();
1954
+ }
1955
+ }, _callee41);
1956
+ })));
1957
+ it('ends the active call and still runs cleanup when an active call is present', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee42() {
1958
+ var clearKeepaliveSpy, setStatusSpy, activeCall, endSpy;
1959
+ return _regenerator.default.wrap(function (_context42) {
1960
+ while (1) switch (_context42.prev = _context42.next) {
1961
+ case 0:
1962
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
1963
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
1964
+ activeCall = reg.callManager.createCall();
1965
+ endSpy = jest.spyOn(activeCall, 'end');
1966
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(1);
1967
+ lineEmitter.mockClear();
1968
+ _context42.next = 1;
1969
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
1970
+ case 1:
1971
+ expect(endSpy).toHaveBeenCalledTimes(1);
1972
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
1973
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
1974
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
1975
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
1976
+ case 2:
1977
+ case "end":
1978
+ return _context42.stop();
1979
+ }
1980
+ }, _callee42);
1981
+ })));
1982
+ it('runs cleanup without calling end when no active call is present on re-invocation', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee43() {
1983
+ var clearKeepaliveSpy, setStatusSpy;
1984
+ return _regenerator.default.wrap(function (_context43) {
1985
+ while (1) switch (_context43.prev = _context43.next) {
1986
+ case 0:
1987
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
1988
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
1989
+ _context43.next = 1;
1990
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
1991
+ case 1:
1992
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
1993
+ clearKeepaliveSpy.mockClear();
1994
+ setStatusSpy.mockClear();
1995
+ lineEmitter.mockClear();
1996
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
1997
+ _context43.next = 2;
1998
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
1999
+ case 2:
2000
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
2001
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
2002
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2003
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2004
+ case 3:
2005
+ case "end":
2006
+ return _context43.stop();
2007
+ }
2008
+ }, _callee43);
2009
+ })));
2010
+ it('disconnects the Mobius WebSocket when socket is enabled', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee44() {
2011
+ var apiRequest, disconnectSocketSpy;
2012
+ return _regenerator.default.wrap(function (_context44) {
2013
+ while (1) switch (_context44.prev = _context44.next) {
2014
+ case 0:
2015
+ apiRequest = _request.APIRequest.getInstance({
2016
+ webex: webex
2017
+ });
2018
+ jest.spyOn(apiRequest, 'isSocketEnabled').mockReturnValue(true);
2019
+ disconnectSocketSpy = jest.spyOn(apiRequest, 'disconnectFromMobiusSocket').mockResolvedValue();
2020
+ lineEmitter.mockClear();
2021
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
2022
+ _context44.next = 1;
2023
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2024
+ case 1:
2025
+ expect(disconnectSocketSpy).toHaveBeenCalledWith({
2026
+ code: 3050,
2027
+ reason: 'done (permanent)'
2028
+ });
2029
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2030
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2031
+ case 2:
2032
+ case "end":
2033
+ return _context44.stop();
2034
+ }
2035
+ }, _callee44);
2036
+ })));
2037
+ it('still emits UNREGISTERED when socket disconnect fails', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee45() {
2038
+ var apiRequest, disconnectSocketSpy;
2039
+ return _regenerator.default.wrap(function (_context45) {
2040
+ while (1) switch (_context45.prev = _context45.next) {
2041
+ case 0:
2042
+ apiRequest = _request.APIRequest.getInstance({
2043
+ webex: webex
2044
+ });
2045
+ jest.spyOn(apiRequest, 'isSocketEnabled').mockReturnValue(true);
2046
+ disconnectSocketSpy = jest.spyOn(apiRequest, 'disconnectFromMobiusSocket').mockRejectedValue(new Error('socket teardown failed'));
2047
+ lineEmitter.mockClear();
2048
+ _context45.next = 1;
2049
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2050
+ case 1:
2051
+ expect(disconnectSocketSpy).toHaveBeenCalled();
2052
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Mobius socket disconnect failed after registration-down'), {
2053
+ file: _constants.REGISTRATION_FILE,
2054
+ method: _constants.METHODS.HANDLE_REGISTRATION_DOWN_EVENT
2055
+ });
2056
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2057
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2058
+ case 2:
2059
+ case "end":
2060
+ return _context45.stop();
2061
+ }
2062
+ }, _callee45);
2063
+ })));
2064
+ });
1887
2065
  });
1888
2066
  //# sourceMappingURL=register.test.js.map