OpenWA enforces a robust testing strategy ensuring both sides of our Hybrid Architecture (Python and TypeScript) remain stable and reliable.
Our test suite is organized logically within the test/ root directory to prevent cluttering the operational codebases.
test/
├── unit/
│ ├── api-gateway/ # FastAPI endpoint tests
│ ├── wa-worker/ # Node.js Worker logic tests
│ ├── sdk-python/ # Python Client SDK tests
│ └── sdk-javascript/ # JS Client SDK tests
└── integration/ # End-to-end multi-component tests
We use pytest for testing the API Gateway, the Python SDK, and the End-to-End integration workflows.
# Export PYTHONPATH so the tests can import the modules natively
PYTHONPATH=$(pwd) api-gateway/venv/bin/pytest test/unit/api-gateway/ test/unit/sdk-python/ test/integration/- Database (
db_session): Located intest/conftest.py, we inject a fully isolated in-memory SQLite database (StaticPool) into every test. The database is wiped clean automatically after each function execution. - FastAPI Client (
client): We use FastAPI'sTestClientallowing us to perform synchronous HTTP requests against the endpoints without booting a live Uvicorn server. - Mocker (
pytest-mock): We heavily utilize themockerfixture to patch external dependencies likeredis_client.publish. Since the architecture is decoupled via Redis, we can test the API by simply asserting that the correct Redis payloads are dispatched!
Note: Be sure to use mocker.AsyncMock when patching async functions!
We use Jest paired with ts-jest for testing the JS SDK and the wa-worker logic.
Because the test/ directory lives outside the wa-worker and sdk/javascript package roots, Jest is configured via roots and transform mappings in jest.config.js to transpile the tests correctly.
# Test the Worker
cd wa-worker
npx jest
# Test the JS SDK
cd sdk/javascript
npx jest- The JS SDK tests mock the global
fetchAPI. - The
wa-workertests mock thewhatsapp-web.jsevent emitters andioredissubscriptions.
The test/integration/ directory contains tests that boot the actual FastAPI application, inject an in-memory database, mock the Node.js Redis responses, and use the Python SDK to interact with the API Gateway.
This ensures that:
- The API Gateway routes correctly.
- The Database persists state.
- The internal RPC and Pub/Sub mechanics function as expected.
- The SDK correctly parses the responses.
All four of these layers are verified in a single test_e2e_flow.py execution.