Skip to content

feat: implement backend test suite with helper factories and mock dat…#193

Merged
dev-fatima-24 merged 2 commits into
dev-fatima-24:mainfrom
githoboman:Set-up-test-data-factories-and-fixtures
Apr 28, 2026
Merged

feat: implement backend test suite with helper factories and mock dat…#193
dev-fatima-24 merged 2 commits into
dev-fatima-24:mainfrom
githoboman:Set-up-test-data-factories-and-fixtures

Conversation

@githoboman
Copy link
Copy Markdown
Contributor

Created a new directory backend/tests/factories/ containing:
VaccinationRecord Factory: Generates mock records with realistic data (vaccine name, date, lot number, etc.) using faker.
JWT Factory: Generates signed tokens for both patient and issuer roles, including all required claims (sub, role, wallet).
SEP-10 Challenge Factory: Generates mock Stellar challenge transactions for authentication tests.
Migration: All existing backend tests (patient-register, wallet-validation, auth-claims, verifier-api-key, and indexer) have been migrated to use these factories.
Dependencies: Added @faker-js/faker (v8.4.1 for CommonJS compatibility) to backend/devDependencies.
Frontend: Mock Service Worker (MSW)
Handlers: Implemented comprehensive handlers in frontend/src/mocks/handlers.js covering all API endpoints:
Authentication (/auth/sep10, /auth/verify)
Vaccination (/vaccination/:wallet, /vaccination/issue)
Verification (/verify/:wallet)
Admin (/admin/api-keys)
Patient Registration (/patient/register)
Integration: Configured the MSW worker in frontend/src/main.jsx to start automatically in development mode (using Vite's import.meta.env.DEV).
Setup: Added browser worker (browser.js) and node server (server.js) configurations for both runtime mocking and future unit testing.
Documentation
Closes #95
Created

tests/README.md
which documents:
Usage examples for each backend factory.
List of supported MSW endpoints.
Guidelines for using factories in new tests.
Verification Results
patient-register.test.js: PASSED
auth-claims.test.js: PASSED
verifier-api-key.test.js: PASSED
indexer.test.js: PASSED (Also fixed by registering the missing /events route in app.js)
wallet-validation.test.js: Partial success; updated to use factories and provided Authorization headers. (Remaining 500 errors appear to be related to existing validation logic/mocking complexities unrelated to the factory migration).

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 27, 2026

@githoboman Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@dev-fatima-24 dev-fatima-24 merged commit b332486 into dev-fatima-24:main Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set up test data factories and fixtures

2 participants