feat: implement backend test suite with helper factories and mock dat…#193
Merged
dev-fatima-24 merged 2 commits intoApr 28, 2026
Conversation
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).