Repository navigation
feat(dx): mock API for local development (MSW) so the app runs without a backend - #145
Merged
afeezorobsco-cyber merged 2 commits intoOct 18, 2026
Conversation
…t a backend (DocForum#95) - npm run dev:mock boots Vite with an MSW service worker covering every endpoint the service layer calls (auth, dependents, health profile, care threads, consultation notes, doctor queue/messages/insights, facility finder/team/fulfillment, payments, account export/delete) - Obviously fake fixtures (example.test personas) in an in-memory DB with a dev panel: role switcher (patient/doctor/facility/admin), scenarios (normal / empty states / forced errors), latency slider, reset - Mocks boot before React's first render (dev-only top-level await) so deep links into protected routes keep the persona session - 26 handler tests drive the real src/services layer through MSW, incl. scenario/latency switches and 404/409 paths - Production bundles stay byte-identical; new CI step npm run check:dist fails if any mock marker leaks into dist/ - Docs: CONTRIBUTING mock-mode section, ROADMAP W7 section, ARCHITECTURE_ ESSENTIALS src/mocks note; shared src/query-client.ts for cache invalidation from the panel 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@mskdylan 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.
Closes #95
Note: opened from the fork
mskdylan/docforum-web(the contributor account has read-only access toDocForum/docforum-web). Branch:feat/mock-api-local-development, based onmain@7e2c21b.This is a developer-tooling change — no screen tied to a PRD §4 core flow is altered, so no PRD flow mapping applies (the flows are exercised through the existing service layer, unchanged).
What changed & why
Contributors previously needed a running
docforum-core(or its cold-starting Render preview) to see most screens.npm run dev:mocknow boots the same Vite dev server with an MSW service worker mocking every endpoint the app's service layer calls, so every screen runs locally in any role, instantly, with obviously fake data.src/mocks/— handlers for all ~40 endpoints (auth, dependents, health profile, care threads, consultation notes, doctor queue/messages/insights, facility finder/team/fulfillment, payments, account export/delete) over an in-memory DB seeded from obviously-fake fixtures (example.testemails,Placeholder/Examplepersonas).npm run dev:mock—VITE_ENABLE_MOCKS=true vite(same inline-env convention as the existingbuild:pagesscript).import.meta.env.DEV && VITE_ENABLE_MOCKSinmain.tsx; newnpm run check:dist(wired intoci.ymlafter build) fails if any mock marker string appears indist/.CONTRIBUTING.mdmock-mode section (incl. the rule: new endpoints get a handler + fixture in the same PR),ROADMAP.mdW7 section,ARCHITECTURE_ESSENTIALS.mdsrc/mocks/note.Implementation / architectural decisions
src/services/→api-fetch/apiFetch→ interceptedfetch). No screen, hook, or service was modified to accommodate mocks, and thepages/ components/ features/ hooks/ services/ store/ types/shape is preserved (src/mocks/is new tooling-only tooling scoped to the issue's sanctioned path).respond()wrapper applies the dev-panel scenario (forced errors, empty lists/null singletons) and latency uniformly, so scenario coverage can't drift per-endpoint.db.ts+resetDb()) so mutations (start a visit, fund an intent, add a dependent) persist across requests within a session and reset on reload/Reset data.await import()inmain.tsx, dev+flag only). The earlier fire-and-forget approach lost the deep-link race:RequireAuthbounced protected deep links to#/loginbefore the persona session existed. Booting first also preserves arbitrary deep links.src/query-client.ts— the app'sQueryClientwas moved out ofmain.tsx(same defaults, same instance) so the panel caninvalidateQueries()on role/scenario/data changes; without it, cached responses masked scenario switches.// @vitest-environment node) so MSW's interceptor wraps Node'sfetch, driving the real service functions — novi.mockof services.Validation (actual output)
Before/after bundle: byte-identical — the built JS is
index-Akq-wW34.jsat 518.33 kB / 162.19 kB gzip on bothmainand this branch (mock code adds zero production bytes).Exclusion check negative-tested: planting a file containing a mock marker in
dist/makescheck:distexit 1 with✗ mock marker "mock-access-token" found in ….Browser verification (headless Chromium against
npm run dev:mock, 9/9 scripted checks, no uncaught page errors): dev panel renders; patient persona auto-signed in; role switch → doctor dashboard shows seeded queue (live queue, running delay, inbox badge); patient dependents show fixtures; empty scenario →No dependents added yet.; error scenario →Mock scenario: forced server error (dev panel)rendered via the app'sFormError; deep link into#/patient/dependentskeeps the mock session; mobile (390×844) panel usable.Screenshots (desktop + mobile)
Committed under
screenshots/per repo convention (raw URLs below render inline):Limitations / notes for review
ci.ymlexecutes, plus the newcheck:diststep added in this PR.dev:mockfrom a clean clone and visits every route") is the intended final check.ROADMAP.mdnow contains the W7 section with [Platform] Generate MSW handlers and fixtures from the backend OpenAPI spec #96 marked blocked on opendocforum-core#112— if [Platform] Mock API for local development (MSW) so the app runs without a backend #95 merges after another W7 PR lands, expect the usual trivial ROADMAP conflicts.