# Real-Time Tests

This document summarises the automated tests that cover the notification queue and WebSocket helpers.

## NotificationQueueCrudTest.php
Tests that CRUD actions performed through `GenericController` enqueue rows in `notification_queue`.
A fake controller uses a dummy model so the test can inspect the queued data. It confirms the entity
name, event type and tenant, branch, user and record identifiers.

## ProcessNotificationQueueTest.php
A future suite will verify background processing of queued messages. It should ensure rows are
published to their destinations (such as Redis) and marked with the correct status.

## WebSocketServer.test.js
Mocks both `redis` and the WebSocket server to simulate clients. The test checks that messages
received from Redis are forwarded to subscribed clients and that subscription filters are honoured.

## LocalSyncManagerWebSocket.test.js
Loads `LocalSyncManager` with a fake WebSocket. Incoming update messages write to IndexedDB and
trigger a `tableUpdated` event on `window` whose detail contains `{ tableName, action, record }`.

## LocalSyncManagerWebSocketReconnect.test.js
Verifies that the manager repeatedly calls `immediateSync()` when the WebSocket connection drops
and stops once a new connection is established.

## WebSocketManager.test.js
Ensures multiple `LocalSyncManager` instances share a single WebSocket created by `WebSocketManager` and that update messages are delivered to all listeners.

## Running Tests
Run the setup script and both PHP and JavaScript suites:

```bash
./test_setup.sh
phpunit -c api/phpunit.xml
npm test
```
