forked from webex/webex-js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
packages/@webex/plugin-cc/src/services/core/WebSocket/WebSocketManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/@webex/plugin-cc/test/unit/spec/services/core/WebSocket/connection-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ConnectionService } from '../../../../../../src/services/core/WebSocket/connection-service'; | ||
import { WebSocketManager } from '../../../../../../src/services/core/WebSocket/WebSocketManager'; | ||
import { Signal } from '../../../../../../src/services/core/Signal'; | ||
|
||
jest.mock('../../../../../../src/services/core/WebSocket/WebSocketManager'); | ||
|
||
describe('ConnectionService', () => { | ||
let connectionService: ConnectionService; | ||
let mockWebSocketManager: jest.Mocked<WebSocketManager>; | ||
|
||
beforeEach(() => { | ||
mockWebSocketManager = new WebSocketManager({ webex: {} as any }) as jest.Mocked<WebSocketManager>; | ||
|
||
// Mock the onMessage and onSocketClose properties | ||
mockWebSocketManager.onMessage = { | ||
listen: jest.fn(), | ||
} as any; | ||
|
||
mockWebSocketManager.onSocketClose = { | ||
listen: jest.fn(), | ||
} as any; | ||
|
||
connectionService = new ConnectionService(mockWebSocketManager); | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should initialize ConnectionService', () => { | ||
expect(connectionService).toBeDefined(); | ||
}); | ||
|
||
it('should set connection properties', () => { | ||
const newProps = { lostConnectionRecoveryTimeout: 30000 }; | ||
connectionService.setConnectionProp(newProps); | ||
expect(connectionService['connectionProp']).toEqual(newProps); | ||
}); | ||
|
||
it('should handle ping message and update connection data', () => { | ||
const pingMessage = JSON.stringify({ keepalive: 'true' }); | ||
connectionService['onPing'](pingMessage); | ||
expect(connectionService['isKeepAlive']).toBe(true); | ||
expect(connectionService['isConnectionLost']).toBe(false); | ||
expect(connectionService['isRestoreFailed']).toBe(false); | ||
expect(connectionService['isSocketReconnected']).toBe(false); | ||
}); | ||
}); |