Skip to main content

Messaging — Testing

Test strategy

Messaging tests cover the full delivery pipeline: local creation, transport routing, server relay, offline queue, receipt tracking, and sync. Tests run at both unit level (ChatService, encryption) and integration level (WebSocket relay, sync endpoint).


Unit tests — ChatService

ScenarioExpected result
Send message when peer connected via TCPMessage encrypted and sent via TcpClientAdapter
Send message when peer connected via WebSocket onlyMessage encrypted and sent via WsSignalingAdapter
Send message when peer offlineMessage stored locally; server queues it
Inbound message receivedDecrypted and persisted to WatermelonDB messages table

Integration tests — WebSocket relay

ScenarioExpected result
Sender connected, recipient connectedMessage forwarded immediately to recipient
Sender connected, recipient offlineMessage stored in queue table
Recipient reconnectsServer drains queue, delivers pending message
Client sends ack for queue entryQueue row deleted
Client does not send ackQueue row remains; re-delivered on next reconnect

Integration tests — sync

ScenarioExpected result
Push new message to server200, stored in MariaDB
Push same message UUID twice200, idempotent upsert (no duplicate)
Push MessageReceipt for LAN-TCP-only messageRejected (FK guard)
Pull messages after another device pushesPulled messages appear in response
Soft-delete message (is_deleted = true)Appears in pull as deleted record

Integration tests — public chat

ScenarioExpected result
Send public-chat messageBroadcast to all connected users
GET /public-chatReturns history of public messages
Unauthenticated user sends public-chat401 or connection closed

Receipt tests

ScenarioExpected result
Message delivered via WebSocketmessagereceipt.status = "delivered"
Recipient opens messagemessagereceipt.status = "read"
Push receipt for LAN-TCP messageRejected by sync endpoint

Coverage targets

  • ChatService transport selection: LAN TCP, WebSocket fallback, offline queue — all three paths covered.
  • Queue drain: reconnect-and-drain lifecycle tested end-to-end.
  • Sync push: idempotency, conflict detection, soft-delete — all tested.

Test conventions

  • Use synthetic UUIDs: alice-uuid, bob-uuid for users.
  • Mock TcpClientAdapter and WsSignalingAdapter in unit tests — no real sockets.
  • Use in-memory SQLite WatermelonDB adapter in unit tests.
  • Reset queue, messages, message_receipts, attachment tables between integration runs.