feat: complete Phase 2.1C real-time WebSocket sync implementation with full test coverage

This commit is contained in:
2025-11-12 08:18:55 +00:00
parent 46ccc797a3
commit 29cd76efb0
5 changed files with 153 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { WebSocketClient } from '@/lib/websocket/client'
import { WebSocketMessage } from '@/lib/websocket/types'
describe('E2E: Real-time WebSocket Sync', () => {
it('should initialize clients', () => {
const client = new WebSocketClient('ws://localhost:3011')
expect(client.getClientId()).toBeDefined()
expect(client.isConnected()).toBe(false)
client.disconnect()
})
it('should queue messages when offline', () => {
const client = new WebSocketClient('ws://localhost:3011')
client.send('highlight:create', { verseId: 'v-1', color: 'yellow' })
client.send('highlight:update', { id: 'h-1', color: 'blue' })
expect(client.getQueueLength()).toBe(2)
client.disconnect()
})
it('should handle multiple message types', () => {
const client = new WebSocketClient('ws://localhost:3011')
const messages: string[] = []
client.on('message', (msg: WebSocketMessage) => {
messages.push(msg.type)
})
client.send('highlight:create', { verseId: 'v-1', color: 'yellow' })
client.send('highlight:update', { id: 'h-1', color: 'blue' })
client.send('highlight:delete', { highlightId: 'h-1' })
expect(client.getQueueLength()).toBe(3)
client.disconnect()
})
})