mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-20 13:51:45 +00:00
fc7d8b5d12
Brownfield strangler migration of the backend onto NestJS modules (auth, trips, days, places, assignments, packing, todo, budget, reservations, collab, files, photos, journey, share, settings, backup, oidc, oauth, admin, atlas, vacay, weather, airports, maps, categories, tags, notifications, system-notices) served through a per-prefix dispatcher, keeping the existing SQLite/better-sqlite3 DB and JWT httpOnly cookie auth, with behavioural parity for every route. Client: React 19 upgrade, "page = wiring container + data hook" pattern across all pages, per-domain Zustand stores bound to @trek/shared contracts, and decomposition of the large components (DayPlanSidebar, PackingListPanel, CollabNotes, FileManager, MemoriesPanel, PlacesSidebar, CollabChat, SystemNoticeModal, BudgetPanel, PlaceFormModal, ...) into focused render units backed by in-file hooks. Apply the shared global request pipeline (helmet/CSP, CORS, HSTS, forced HTTPS, the global MFA policy and request logging) to the NestJS instance as well, so a migrated route is protected identically to the legacy fallback rather than bypassing it.
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
import request from 'supertest';
|
|
import { expect } from 'vitest';
|
|
import type { Server } from 'http';
|
|
|
|
export interface ParityRequest {
|
|
method?: 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
path: string;
|
|
query?: Record<string, string>;
|
|
body?: unknown;
|
|
/** Request headers (e.g. a Cookie/Authorization) applied to BOTH stacks. */
|
|
headers?: Record<string, string>;
|
|
}
|
|
|
|
/**
|
|
* Reusable Nest-vs-Express parity harness.
|
|
*
|
|
* Fires the same HTTP request at the legacy Express app and the migrated Nest app
|
|
* and asserts the response is client-identical — same status code and same JSON
|
|
* body. With the underlying service mocked identically for both, any difference is
|
|
* purely framework-layer (routing, validation, error envelope), which is exactly
|
|
* what a migration must not change. Use one assertion per migrated route/case.
|
|
*/
|
|
export async function expectParity(
|
|
expressServer: Server | Express.Application,
|
|
nestServer: Server,
|
|
req: ParityRequest,
|
|
): Promise<void> {
|
|
const fire = (target: Server | Express.Application) => {
|
|
const method = req.method ?? 'get';
|
|
let r = request(target as never)[method](req.path);
|
|
if (req.headers) for (const [k, v] of Object.entries(req.headers)) r = r.set(k, v);
|
|
if (req.query) r = r.query(req.query);
|
|
if (req.body !== undefined) r = r.send(req.body as object);
|
|
return r;
|
|
};
|
|
|
|
const [ex, ne] = await Promise.all([fire(expressServer), fire(nestServer)]);
|
|
|
|
const label = `${(req.method ?? 'GET').toUpperCase()} ${req.path}`;
|
|
expect(ne.status, `${label}: status mismatch`).toBe(ex.status);
|
|
expect(ne.body, `${label}: body mismatch`).toEqual(ex.body);
|
|
}
|