The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
test(db): run the admin and auth suites on the real database module
Maurice680ce7324aef
diff --git a/server/scripts/test-mocks-baseline.json b/server/scripts/test-mocks-baseline.jsonindex b8d6dc9e9..c442fcffb 100644--- a/server/scripts/test-mocks-baseline.json+++ b/server/scripts/test-mocks-baseline.json@@ -52,8 +52,6 @@"tests/e2e/trips.e2e.test.ts": 1,"tests/e2e/vacay.e2e.test.ts": 1,"tests/e2e/weather.e2e.test.ts": 1,- "tests/integration/admin.test.ts": 1,- "tests/integration/auth.test.ts": 1,"tests/integration/dayReorder.test.ts": 1,"tests/integration/journey-place-order.test.ts": 1,"tests/integration/journey.test.ts": 1,diff --git a/server/tests/integration/admin.test.ts b/server/tests/integration/admin.test.tsindex 9d587a3bf..8ab79fa6f 100644--- a/server/tests/integration/admin.test.ts+++ b/server/tests/integration/admin.test.ts@@ -3,7 +3,6 @@* Covers ADMIN-001 to ADMIN-022.*/import { buildApp } from '../../src/bootstrap';-import { db as testDb } from '../../src/db/database';import { AuditLog } from '../../src/db/entities/AuditLog.entity';import { BucketList } from '../../src/db/entities/BucketList.entity';import { BudgetItems } from '../../src/db/entities/BudgetItems.entity';@@ -40,42 +39,29 @@ import { VisitedCountries } from '../../src/db/entities/VisitedCountries.entity'import { VisitedRegions } from '../../src/db/entities/VisitedRegions.entity';import { dbNow } from '../../src/db/types/db-timestamp.type';import { authCookie } from '../helpers/auth';-import {- createUser,- createAdmin,- createInviteToken,- createTrip,- createBudgetItem,- createJourney,- createJourneyEntry,- addJourneyContributor,- addTripPhoto,- createCategory,- createTag,- createTodoItem,- createMcpToken,- createBucketListItem,- createVisitedCountry,- createCollabNote,- addTripMember,-} from '../helpers/factories';+import { makeBucketListItem, markCountryVisited } from '../helpers/factories/atlas';+import { makeBudgetItem } from '../helpers/factories/budget';+import { makeCollabNote } from '../helpers/factories/collab';import type { FactoryOrm } from '../helpers/factories/context';+import { addJourneyContributor, makeJourney, makeJourneyEntry } from '../helpers/factories/journeys';+import { addTripPhoto } from '../helpers/factories/photos';+import { makeCategory, makeTag } from '../helpers/factories/places';import { countRows, findRow, insertRow, insertRowIgnoringConflict, updateRows } from '../helpers/factories/rows';+import { makeTodoItem } from '../helpers/factories/todos';+import { makeInviteToken, makeMcpToken } from '../helpers/factories/tokens';import { makeShareToken } from '../helpers/factories/trips';+import { addTripMember, makeTrip } from '../helpers/factories/trips';import { readUser } from '../helpers/factories/users';+import { makeAdmin, makeUser } from '../helpers/factories/users';import { makeVacayPlan } from '../helpers/factories/vacay';-import { resetTestDb, resetRateLimits } from '../helpers/test-db';+import { resetDatabase } from '../helpers/reset-database';+import { resetRateLimits } from '../helpers/test-db';import { MikroORM } from '@mikro-orm/core';import type { INestApplication } from '@nestjs/common';import type { Application } from 'express';import request from 'supertest';-import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';--vi.mock('../../src/db/database', async () => {- const { createSnapshotTestDb, buildDbMock } = await import('../helpers/db-mock');- return buildDbMock(createSnapshotTestDb());-});+import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';let nestApp: INestApplication;let app: Application;@@ -88,13 +74,12 @@ beforeAll(async () => {});beforeEach(async () => {- resetTestDb(testDb);+ await resetDatabase(orm);await resetRateLimits(nestApp);});afterAll(async () => {await nestApp.close();- testDb.close();});// ─────────────────────────────────────────────────────────────────────────────@@ -103,7 +88,7 @@ afterAll(async () => {describe('Admin access control', () => {it('ADMIN-022 — non-admin cannot access admin routes', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).get('/api/admin/users').set('Cookie', authCookie(user.id));expect(res.status).toBe(403);@@ -121,9 +106,9 @@ describe('Admin access control', () => {describe('Admin user management', () => {it('ADMIN-001 — GET /admin/users lists all users', async () => {- const { user: admin } = createAdmin(testDb);- createUser(testDb);- createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ await makeUser(orm);+ await makeUser(orm);const res = await request(app).get('/api/admin/users').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -131,7 +116,7 @@ describe('Admin user management', () => {});it('ADMIN-002 — POST /admin/users creates a user', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).post('/api/admin/users')@@ -142,8 +127,8 @@ describe('Admin user management', () => {});it('ADMIN-003 — POST /admin/users with duplicate email returns 409', async () => {- const { user: admin } = createAdmin(testDb);- const { user: existing } = createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ const { user: existing } = await makeUser(orm);const res = await request(app).post('/api/admin/users')@@ -153,8 +138,8 @@ describe('Admin user management', () => {});it('ADMIN-004 — PUT /admin/users/:id updates user', async () => {- const { user: admin } = createAdmin(testDb);- const { user } = createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ const { user } = await makeUser(orm);const res = await request(app).put(`/api/admin/users/${user.id}`)@@ -165,8 +150,8 @@ describe('Admin user management', () => {});it('ADMIN-005 — DELETE /admin/users/:id removes user', async () => {- const { user: admin } = createAdmin(testDb);- const { user } = createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ const { user } = await makeUser(orm);const res = await request(app).delete(`/api/admin/users/${user.id}`).set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -178,29 +163,29 @@ describe('Admin user management', () => {});it('ADMIN-005b — DELETE /admin/users/:id succeeds when user has FK references', async () => {- const { user: admin } = createAdmin(testDb);- const { user: target } = createUser(testDb);- const { user: otherUser } = createUser(testDb);- const { user: thirdUser } = createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ const { user: target } = await makeUser(orm);+ const { user: otherUser } = await makeUser(orm);+ const { user: thirdUser } = await makeUser(orm);// trip_members.invited_by: target invited thirdUser to otherUser's trip// (trip survives deletion; only invited_by should become NULL)- const otherTrip = createTrip(testDb, otherUser.id);+ const otherTrip = await makeTrip(orm, otherUser.id);await insertRow(orm, TripMembers, { trip: otherTrip.id, user: thirdUser.id, invitedByRef: target.id });// share_tokens.created_by: target created a share token for otherUser's tripawait makeShareToken(orm, otherTrip.id, target.id, { token: 'tok-admin-test' });// budget_items.paid_by_user_id: target paid for an expense on otherUser's trip- const budgetItem = createBudgetItem(testDb, otherTrip.id);+ const budgetItem = await makeBudgetItem(orm, otherTrip.id);await updateRows(orm, BudgetItems, { id: budgetItem.id }, { paidByUser: target.id });// journey_contributors: target is a contributor on otherUser's journey- const otherJourney = createJourney(testDb, otherUser.id);- addJourneyContributor(testDb, otherJourney.id, target.id);+ const otherJourney = await makeJourney(orm, otherUser.id);+ await addJourneyContributor(orm, otherJourney.id, target.id);// journey_entries: target authored an entry on otherUser's journey- createJourneyEntry(testDb, otherJourney.id, target.id);+ await makeJourneyEntry(orm, otherJourney.id, target.id);// journey_share_tokens: target created a share token for otherUser's journeyawait insertRow(orm, JourneyShareTokens, {@@ -234,8 +219,8 @@ describe('Admin user management', () => {await insertRow(orm, UserNoticeDismissals, { user: target.id, notice_id: 'test-notice', dismissed_at: Date.now() });// owned journey: target owns a journey with an entry (cascade-deletes on journey deletion)- const ownedJourney = createJourney(testDb, target.id);- createJourneyEntry(testDb, ownedJourney.id, target.id);+ const ownedJourney = await makeJourney(orm, target.id);+ await makeJourneyEntry(orm, ownedJourney.id, target.id);// trip_files.uploaded_by (SET NULL): target uploaded a file to otherUser's tripconst fileId = await insertRow(orm, TripFiles, {@@ -253,22 +238,22 @@ describe('Admin user management', () => {});// trip_photos.user_id (CASCADE): target added a photo to otherUser's trip- addTripPhoto(testDb, otherTrip.id, target.id, 'asset-tp-admin', 'immich');+ await addTripPhoto(orm, otherTrip.id, target.id, 'asset-tp-admin', 'immich');// trips.user_id (CASCADE): target owns a trip- const ownedTrip = createTrip(testDb, target.id);+ const ownedTrip = await makeTrip(orm, target.id);// trip_members.user_id (CASCADE): target is a member of otherUser's trip- addTripMember(testDb, otherTrip.id, target.id);+ await addTripMember(orm, otherTrip.id, target.id);// categories.user_id (SET NULL): target created a category- const userCategory = createCategory(testDb, { user_id: target.id });+ const userCategory = await makeCategory(orm, { user: target.id });// tags.user_id (CASCADE): target created a tag- const userTag = createTag(testDb, target.id);+ const userTag = await makeTag(orm, target.id);// todo_items.assigned_user_id (SET NULL): target is assigned to a todo on otherUser's trip- const todoItem = createTodoItem(testDb, otherTrip.id);+ const todoItem = await makeTodoItem(orm, otherTrip.id);await updateRows(orm, TodoItems, { id: todoItem.id }, { assignedUser: target.id });// packing_bags.user_id (SET NULL): target owns a packing bag on otherUser's trip@@ -280,7 +265,7 @@ describe('Admin user management', () => {});// mcp_tokens.user_id (CASCADE): target has an MCP API token- createMcpToken(testDb, target.id);+ await makeMcpToken(orm, target.id);// oauth_tokens/consents.user_id (CASCADE): target has tokens from otherUser's OAuth client// The row id and the public client_id are the same string here, so the@@ -310,10 +295,10 @@ describe('Admin user management', () => {await insertRow(orm, VacayPlanMembers, { plan: otherVacayPlanId, user: target.id });// bucket_list.user_id (CASCADE): target has a bucket list item- createBucketListItem(testDb, target.id);+ await makeBucketListItem(orm, target.id);// visited_countries.user_id (CASCADE): target has visited a country- createVisitedCountry(testDb, target.id, 'JP');+ await markCountryVisited(orm, target.id, 'JP');// visited_regions.user_id (CASCADE): target has visited a regionawait insertRow(orm, VisitedRegions, {@@ -327,10 +312,10 @@ describe('Admin user management', () => {const packTemplateId = await insertRow(orm, PackingTemplates, { name: 'My Template', createdByRef: target.id });// invite_tokens.created_by (CASCADE): target created an invite token- createInviteToken(testDb, { created_by: target.id });+ await makeInviteToken(orm, target.id);// collab_notes.user_id (CASCADE): target authored a collab note on otherUser's trip- createCollabNote(testDb, otherTrip.id, target.id);+ await makeCollabNote(orm, otherTrip.id, target.id);// settings.user_id (CASCADE): target has a user settingawait insertRow(orm, Settings, { user: target.id, key: 'theme', value: 'dark' });@@ -424,7 +409,7 @@ describe('Admin user management', () => {});it('ADMIN-006 — admin cannot delete their own account', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).delete(`/api/admin/users/${admin.id}`).set('Cookie', authCookie(admin.id));expect(res.status).toBe(400);@@ -437,8 +422,8 @@ describe('Admin user management', () => {describe('Admin user management — whitespace normalization', () => {it('ADMIN-UPDATE-TRIM-1 — PUT /admin/users/:id trims username before storing', async () => {- const { user: admin } = createAdmin(testDb);- const { user } = createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ const { user } = await makeUser(orm);const res = await request(app).put(`/api/admin/users/${user.id}`)@@ -451,8 +436,8 @@ describe('Admin user management — whitespace normalization', () => {});it('ADMIN-UPDATE-TRIM-2 — PUT /admin/users/:id trims email before storing', async () => {- const { user: admin } = createAdmin(testDb);- const { user } = createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ const { user } = await makeUser(orm);const res = await request(app).put(`/api/admin/users/${user.id}`)@@ -465,9 +450,9 @@ describe('Admin user management — whitespace normalization', () => {});it('ADMIN-UPDATE-TRIM-3 — PUT /admin/users/:id with whitespace-padded username that trims to existing returns 409', async () => {- const { user: admin } = createAdmin(testDb);- const { user: existing } = createUser(testDb, { username: 'carol' });- const { user: target } = createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ const { user: existing } = await makeUser(orm, { username: 'carol' });+ const { user: target } = await makeUser(orm);const res = await request(app).put(`/api/admin/users/${target.id}`)@@ -484,7 +469,7 @@ describe('Admin user management — whitespace normalization', () => {describe('System stats', () => {it('ADMIN-007 — GET /admin/stats returns system statistics', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/stats').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -499,7 +484,7 @@ describe('System stats', () => {describe('Permissions management', () => {it('ADMIN-008 — GET /admin/permissions returns permission config', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/permissions').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -508,7 +493,7 @@ describe('Permissions management', () => {});it('ADMIN-008 — PUT /admin/permissions updates permissions and change persists', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);// Change trip_create from its default ('everybody') to 'admin'const res = await request(app)@@ -527,7 +512,7 @@ describe('Permissions management', () => {});it('ADMIN-008 — PUT /admin/permissions without object returns 400', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).put('/api/admin/permissions')@@ -543,7 +528,7 @@ describe('Permissions management', () => {describe('Audit log', () => {it('ADMIN-009 — GET /admin/audit-log returns log entries', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/audit-log').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -557,7 +542,7 @@ describe('Audit log', () => {describe('Addon management', () => {it('ADMIN-011 — PUT /admin/addons/:id disables an addon', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).put('/api/admin/addons/atlas')@@ -567,7 +552,7 @@ describe('Addon management', () => {});it('ADMIN-012 — PUT /admin/addons/:id re-enables an addon', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);await request(app).put('/api/admin/addons/atlas').set('Cookie', authCookie(admin.id)).send({ enabled: false });@@ -585,7 +570,7 @@ describe('Addon management', () => {describe('Invite token management', () => {it('ADMIN-013 — POST /admin/invites creates an invite token', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).post('/api/admin/invites').set('Cookie', authCookie(admin.id)).send({ max_uses: 5 });expect(res.status).toBe(201);@@ -593,7 +578,7 @@ describe('Invite token management', () => {});it('ADMIN-013b — POST /admin/invites with a trip that does not exist answers 404 and writes nothing', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).post('/api/admin/invites')@@ -606,8 +591,8 @@ describe('Invite token management', () => {});it('ADMIN-014 — DELETE /admin/invites/:id removes invite', async () => {- const { user: admin } = createAdmin(testDb);- const invite = createInviteToken(testDb, { created_by: admin.id });+ const { user: admin } = await makeAdmin(orm);+ const invite = await makeInviteToken(orm, admin.id);const res = await request(app).delete(`/api/admin/invites/${invite.id}`).set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -621,7 +606,7 @@ describe('Invite token management', () => {describe('Packing templates', () => {it('ADMIN-015 — POST /admin/packing-templates creates a template', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).post('/api/admin/packing-templates')@@ -632,7 +617,7 @@ describe('Packing templates', () => {});it('ADMIN-016 — DELETE /admin/packing-templates/:id removes template', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const create = await request(app).post('/api/admin/packing-templates').set('Cookie', authCookie(admin.id))@@ -653,7 +638,7 @@ describe('Packing templates', () => {describe('Bag tracking', () => {it('ADMIN-017 — PUT /admin/bag-tracking toggles bag tracking', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).put('/api/admin/bag-tracking')@@ -669,7 +654,7 @@ describe('Bag tracking', () => {describe('JWT rotation', () => {it('ADMIN-018 — POST /admin/rotate-jwt-secret rotates the JWT secret', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).post('/api/admin/rotate-jwt-secret').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -691,7 +676,7 @@ describe('Packing template CRUD (full)', () => {}it('ADMIN-019 — GET /admin/packing-templates/:id returns template', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const template = await makeTemplate(admin);const res = await request(app)@@ -703,14 +688,14 @@ describe('Packing template CRUD (full)', () => {});it('ADMIN-019b — GET /admin/packing-templates/:id returns 404 for missing', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/packing-templates/99999').set('Cookie', authCookie(admin.id));expect(res.status).toBe(404);});it('ADMIN-020 — PUT /admin/packing-templates/:id updates name', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const template = await makeTemplate(admin);const res = await request(app)@@ -722,7 +707,7 @@ describe('Packing template CRUD (full)', () => {});it('ADMIN-021 — POST /admin/packing-templates/:id/categories adds a category', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const template = await makeTemplate(admin);const res = await request(app)@@ -734,7 +719,7 @@ describe('Packing template CRUD (full)', () => {});it('ADMIN-021b — PUT /admin/packing-templates/:templateId/categories/:catId updates category', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const template = await makeTemplate(admin);const catRes = await request(app).post(`/api/admin/packing-templates/${template.id}/categories`)@@ -751,7 +736,7 @@ describe('Packing template CRUD (full)', () => {});it('ADMIN-021c — DELETE /admin/packing-templates/:templateId/categories/:catId removes category', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const template = await makeTemplate(admin);const catRes = await request(app).post(`/api/admin/packing-templates/${template.id}/categories`)@@ -767,7 +752,7 @@ describe('Packing template CRUD (full)', () => {});it('ADMIN-021d — POST .../categories/:catId/items adds an item to category', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const template = await makeTemplate(admin);const catRes = await request(app).post(`/api/admin/packing-templates/${template.id}/categories`)@@ -784,7 +769,7 @@ describe('Packing template CRUD (full)', () => {});it('ADMIN-021e — PUT /admin/packing-templates/:templateId/items/:itemId updates item', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const template = await makeTemplate(admin);const catRes = await request(app).post(`/api/admin/packing-templates/${template.id}/categories`)@@ -806,7 +791,7 @@ describe('Packing template CRUD (full)', () => {});it('ADMIN-021f — DELETE /admin/packing-templates/:templateId/items/:itemId removes item', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const template = await makeTemplate(admin);const catRes = await request(app).post(`/api/admin/packing-templates/${template.id}/categories`)@@ -833,7 +818,7 @@ describe('Packing template CRUD (full)', () => {describe('MCP token management', () => {it('ADMIN-023 — GET /admin/mcp-tokens returns list', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/mcp-tokens').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -841,14 +826,14 @@ describe('MCP token management', () => {});it('ADMIN-024 — DELETE /admin/mcp-tokens/:id returns 404 for missing token', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).delete('/api/admin/mcp-tokens/99999').set('Cookie', authCookie(admin.id));expect(res.status).toBe(404);});it('ADMIN-025 — DELETE /admin/mcp-tokens/abc (non-numeric id) returns the legacy 404, not a 500 (Plan 3b Task 2 review, F1)', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).delete('/api/admin/mcp-tokens/abc').set('Cookie', authCookie(admin.id));expect(res.status).toBe(404);@@ -862,7 +847,7 @@ describe('MCP token management', () => {describe('OAuth sessions', () => {it('ADMIN-025 — GET /admin/oauth-sessions returns list', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/oauth-sessions').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -870,14 +855,14 @@ describe('OAuth sessions', () => {});it('ADMIN-026 — DELETE /admin/oauth-sessions/:id returns 404 for missing session', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).delete('/api/admin/oauth-sessions/99999').set('Cookie', authCookie(admin.id));expect(res.status).toBe(404);});it('ADMIN-026B — DELETE /admin/oauth-sessions/abc (non-numeric id) returns the legacy 404, not a 500 (Plan 3b Task 4 controller addendum, per Task 2 review F1)', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).delete('/api/admin/oauth-sessions/abc').set('Cookie', authCookie(admin.id));expect(res.status).toBe(404);@@ -891,14 +876,14 @@ describe('OAuth sessions', () => {describe('OIDC settings', () => {it('ADMIN-027 — GET /admin/oidc returns OIDC configuration', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/oidc').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);});it('ADMIN-028 — PUT /admin/oidc updates OIDC settings', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).put('/api/admin/oidc')@@ -915,7 +900,7 @@ describe('OIDC settings', () => {describe('Demo baseline', () => {it('ADMIN-029 — POST /admin/save-demo-baseline returns 404 when DEMO_MODE is not set', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).post('/api/admin/save-demo-baseline').set('Cookie', authCookie(admin.id));expect(res.status).toBe(404);@@ -928,7 +913,7 @@ describe('Demo baseline', () => {describe('GitHub releases and version check', () => {it('ADMIN-030 — GET /admin/github-releases returns array (even if GitHub unreachable)', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/github-releases?per_page=5&page=1')@@ -938,7 +923,7 @@ describe('GitHub releases and version check', () => {});it('ADMIN-031 — GET /admin/version-check returns version info', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/version-check').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -952,7 +937,7 @@ describe('GitHub releases and version check', () => {describe('Admin list routes', () => {it('ADMIN-032 — GET /admin/invites lists invites', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/invites').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -960,14 +945,14 @@ describe('Admin list routes', () => {});it('ADMIN-033 — GET /admin/bag-tracking returns bag tracking setting', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/bag-tracking').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);});it('ADMIN-034 — GET /admin/packing-templates lists templates', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/packing-templates').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);@@ -975,7 +960,7 @@ describe('Admin list routes', () => {});it('ADMIN-035 — GET /admin/addons lists addons', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const res = await request(app).get('/api/admin/addons').set('Cookie', authCookie(admin.id));expect(res.status).toBe(200);diff --git a/server/tests/integration/auth.test.ts b/server/tests/integration/auth.test.tsindex 0dab7f9fd..7c02caef4 100644--- a/server/tests/integration/auth.test.ts+++ b/server/tests/integration/auth.test.ts@@ -5,7 +5,6 @@* Rate limiting scenarios (AUTH-004, AUTH-018) are at the end of this file.*/import { buildApp } from '../../src/bootstrap';-import { db as testDb } from '../../src/db/database';import { AuditLog } from '../../src/db/entities/AuditLog.entity';import { BucketList } from '../../src/db/entities/BucketList.entity';import { BudgetItems } from '../../src/db/entities/BudgetItems.entity';@@ -42,30 +41,21 @@ import { VisitedCountries } from '../../src/db/entities/VisitedCountries.entity'import { VisitedRegions } from '../../src/db/entities/VisitedRegions.entity';import { dbNow } from '../../src/db/types';import { authCookie, authHeader } from '../helpers/auth';-import {- createUser,- createAdmin,- createUserWithMfa,- createInviteToken,- createTrip,- createBudgetItem,- createJourney,- createJourneyEntry,- addJourneyContributor,- addTripPhoto,- createCategory,- createTag,- createTodoItem,- createMcpToken,- createBucketListItem,- createVisitedCountry,- createCollabNote,- addTripMember,-} from '../helpers/factories';+import { makeBucketListItem, markCountryVisited } from '../helpers/factories/atlas';+import { makeBudgetItem } from '../helpers/factories/budget';+import { makeCollabNote } from '../helpers/factories/collab';+import { addJourneyContributor, makeJourney, makeJourneyEntry } from '../helpers/factories/journeys';+import { addTripPhoto } from '../helpers/factories/photos';+import { makeCategory, makeTag } from '../helpers/factories/places';import { findRow, insertRow, insertRowIgnoringConflict, updateRows } from '../helpers/factories/rows';import { setAppSetting, setUserSetting } from '../helpers/factories/settings';+import { makeTodoItem } from '../helpers/factories/todos';+import { makeInviteToken, makeMcpToken } from '../helpers/factories/tokens';import { makeShareToken } from '../helpers/factories/trips';-import { resetTestDb, resetRateLimits } from '../helpers/test-db';+import { addTripMember, makeTrip } from '../helpers/factories/trips';+import { makeAdmin, makeUser, makeUserWithMfa } from '../helpers/factories/users';+import { resetDatabase } from '../helpers/reset-database';+import { resetRateLimits } from '../helpers/test-db';import type { EntityClass, FilterQuery } from '@mikro-orm/core';import { MikroORM } from '@mikro-orm/core';import type { INestApplication } from '@nestjs/common';@@ -73,15 +63,11 @@ import type { INestApplication } from '@nestjs/common';import type { Application } from 'express';import { authenticator } from 'otplib';import request from 'supertest';-import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';+import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';// ─────────────────────────────────────────────────────────────────────────────// Step 1: Bare in-memory DB — schema applied in beforeAll after mocks register// ─────────────────────────────────────────────────────────────────────────────-vi.mock('../../src/db/database', async () => {- const { createSnapshotTestDb, buildDbMock } = await import('../helpers/db-mock');- return buildDbMock(createSnapshotTestDb());-});let nestApp: INestApplication;let app: Application;@@ -99,14 +85,13 @@ function rowOf<T extends object>(entity: EntityClass<T>, where: FilterQuery<T>)}beforeEach(async () => {- resetTestDb(testDb);+ await resetDatabase(orm);// Reset rate limiter state between tests so they don't interfereawait resetRateLimits(nestApp);});afterAll(async () => {await nestApp.close();- testDb.close();});// ─────────────────────────────────────────────────────────────────────────────@@ -115,7 +100,7 @@ afterAll(async () => {describe('Login', () => {it('AUTH-001 — successful login returns 200, user object, and trek_session cookie', async () => {- const { user, password } = createUser(testDb);+ const { user, password } = await makeUser(orm);const res = await request(app).post('/api/auth/login').send({ email: user.email, password });expect(res.status).toBe(200);expect(res.body.user).toBeDefined();@@ -128,7 +113,7 @@ describe('Login', () => {});it('AUTH-002 — wrong password returns 401 with generic message', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).post('/api/auth/login').send({ email: user.email, password: 'WrongPass1!' });expect(res.status).toBe(401);expect(res.body.error).toContain('Invalid email or password');@@ -197,7 +182,7 @@ describe('Registration', () => {});it('AUTH-008 — registration with duplicate email returns 409', async () => {- createUser(testDb, { email: '[email protected]' });+ await makeUser(orm, { email: '[email protected]' });const res = await request(app).post('/api/auth/register').send({username: 'newuser',email: '[email protected]',@@ -207,7 +192,7 @@ describe('Registration', () => {});it('AUTH-009 — registration disabled by admin returns 403', async () => {- createUser(testDb);+ await makeUser(orm);await setAppSetting(orm, 'allow_registration', 'false');const res = await request(app).post('/api/auth/register').send({username: 'blocked',@@ -219,9 +204,9 @@ describe('Registration', () => {});it('AUTH-010 — registration with valid invite token succeeds even when registration disabled', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);await setAppSetting(orm, 'allow_registration', 'false');- const invite = createInviteToken(testDb, { max_uses: 1, created_by: admin.id });+ const invite = await makeInviteToken(orm, admin.id, { max_uses: 1 });const res = await request(app).post('/api/auth/register').send({username: 'invited',@@ -236,9 +221,9 @@ describe('Registration', () => {});it('AUTH-011 — GET /api/auth/invite/:token with expired token returns 410', async () => {- const { user: admin } = createAdmin(testDb);+ const { user: admin } = await makeAdmin(orm);const yesterday = new Date(Date.now() - 86_400_000).toISOString();- const invite = createInviteToken(testDb, { expires_at: yesterday, created_by: admin.id });+ const invite = await makeInviteToken(orm, admin.id, { expires_at: yesterday });const res = await request(app).get(`/api/auth/invite/${invite.token}`);expect(res.status).toBe(410);@@ -246,8 +231,8 @@ describe('Registration', () => {});it('AUTH-012 — GET /api/auth/invite/:token with exhausted token returns 410', async () => {- const { user: admin } = createAdmin(testDb);- const invite = createInviteToken(testDb, { max_uses: 1, created_by: admin.id });+ const { user: admin } = await makeAdmin(orm);+ const invite = await makeInviteToken(orm, admin.id, { max_uses: 1 });// Mark as exhaustedawait updateRows(orm, InviteTokens, { id: invite.id }, { used_count: 1 });@@ -257,8 +242,8 @@ describe('Registration', () => {});it('AUTH-013 — GET /api/auth/invite/:token for a never-expiring invite keeps expires_at present and null on the wire (rule 16, task-5-review F1/T1)', async () => {- const { user: admin } = createAdmin(testDb);- const invite = createInviteToken(testDb, { max_uses: 3, created_by: admin.id });+ const { user: admin } = await makeAdmin(orm);+ const invite = await makeInviteToken(orm, admin.id, { max_uses: 3 });await updateRows(orm, InviteTokens, { id: invite.id }, { used_count: 1 });const res = await request(app).get(`/api/auth/invite/${invite.token}`);@@ -297,7 +282,7 @@ describe('Registration — whitespace normalization', () => {});it('AUTH-REG-TRIM-3 — whitespace-padded username that trims to existing username returns 409', async () => {- createUser(testDb, { username: 'alice', email: '[email protected]' });+ await makeUser(orm, { username: 'alice', email: '[email protected]' });const res = await request(app).post('/api/auth/register').send({username: ' alice ',email: '[email protected]',@@ -307,7 +292,7 @@ describe('Registration — whitespace normalization', () => {});it('AUTH-REG-TRIM-4 — whitespace-padded email that trims to existing email returns 409', async () => {- createUser(testDb, { username: 'bob', email: '[email protected]' });+ await makeUser(orm, { username: 'bob', email: '[email protected]' });const res = await request(app).post('/api/auth/register').send({username: 'bob2',email: ' [email protected] ',@@ -357,7 +342,7 @@ describe('Registration / login — non-ASCII case folding (H1)', () => {});it('AUTH-NONASCII-3 — an ASCII-only account is unaffected (control)', async () => {- const { user, password } = createUser(testDb, { email: '[email protected]' });+ const { user, password } = await makeUser(orm, { email: '[email protected]' });const login = await request(app).post('/api/auth/login').send({ email: user.email, password });expect(login.status).toBe(200);});@@ -375,7 +360,7 @@ describe('Session', () => {});it('AUTH-014 — GET /api/auth/me with valid cookie returns safe user object', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).get('/api/auth/me').set('Cookie', authCookie(user.id));expect(res.status).toBe(200);expect(res.body.user.id).toBe(user.id);@@ -385,7 +370,7 @@ describe('Session', () => {});it('AUTH-021 — user with must_change_password=1 sees the flag in their profile', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await updateRows(orm, Users, { id: user.id }, { must_change_password: 1 });const res = await request(app).get('/api/auth/me').set('Cookie', authCookie(user.id));@@ -410,7 +395,7 @@ describe('App config', () => {});it('AUTH-028 — allow_registration is false after admin disables it', async () => {- createUser(testDb);+ await makeUser(orm);await setAppSetting(orm, 'allow_registration', 'false');const res = await request(app).get('/api/auth/app-config');expect(res.status).toBe(200);@@ -448,7 +433,7 @@ describe('Demo login', () => {describe('MFA', () => {it('AUTH-015 — POST /api/auth/mfa/setup returns secret and QR data URL', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).post('/api/auth/mfa/setup').set('Cookie', authCookie(user.id));expect(res.status).toBe(200);expect(res.body.secret).toBeDefined();@@ -457,7 +442,7 @@ describe('MFA', () => {});it('AUTH-015 — POST /api/auth/mfa/enable with valid TOTP code enables MFA', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const setupRes = await request(app).post('/api/auth/mfa/setup').set('Cookie', authCookie(user.id));expect(setupRes.status).toBe(200);@@ -472,7 +457,7 @@ describe('MFA', () => {});it('AUTH-016 — login with MFA-enabled account returns mfa_required + mfa_token', async () => {- const { user, password } = createUserWithMfa(testDb);+ const { user, password } = await makeUserWithMfa(orm);const loginRes = await request(app).post('/api/auth/login').send({ email: user.email, password });expect(loginRes.status).toBe(200);expect(loginRes.body.mfa_required).toBe(true);@@ -480,7 +465,7 @@ describe('MFA', () => {});it('AUTH-016 — POST /api/auth/mfa/verify-login with valid code completes login', async () => {- const { user, password, totpSecret } = createUserWithMfa(testDb);+ const { user, password, totpSecret } = await makeUserWithMfa(orm);const loginRes = await request(app).post('/api/auth/login').send({ email: user.email, password });const { mfa_token } = loginRes.body;@@ -497,7 +482,7 @@ describe('MFA', () => {});it('AUTH-017 — verify-login with invalid TOTP code returns 401', async () => {- const { user, password } = createUserWithMfa(testDb);+ const { user, password } = await makeUserWithMfa(orm);const loginRes = await request(app).post('/api/auth/login').send({ email: user.email, password });const verifyRes = await request(app)@@ -508,7 +493,7 @@ describe('MFA', () => {});it('AUTH-019 — disable MFA with valid password and TOTP code', async () => {- const { user, password, totpSecret } = createUserWithMfa(testDb);+ const { user, password, totpSecret } = await makeUserWithMfa(orm);const disableRes = await request(app).post('/api/auth/mfa/disable')@@ -520,7 +505,7 @@ describe('MFA', () => {it('AUTH-019 — disable MFA with password and unused backup code', async () => {const { hashBackupCodeBcrypt } = await import('../../src/nest/auth/auth.helpers');- const { user, password } = createUserWithMfa(testDb);+ const { user, password } = await makeUserWithMfa(orm);await updateRows(orm,Users,@@ -543,7 +528,7 @@ describe('MFA', () => {it('AUTH-019 — reject invalid recovery code and incorrect password', async () => {const { hashBackupCodeBcrypt } = await import('../../src/nest/auth/auth.helpers');- const { user, password } = createUserWithMfa(testDb);+ const { user, password } = await makeUserWithMfa(orm);await updateRows(orm,Users,@@ -571,7 +556,7 @@ describe('MFA', () => {describe('Forced MFA policy', () => {it('AUTH-020 — non-MFA user is blocked (403 MFA_REQUIRED) when require_mfa is true', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await setAppSetting(orm, 'require_mfa', 'true');// mfaPolicy checks Authorization: Bearer header@@ -581,7 +566,7 @@ describe('Forced MFA policy', () => {});it('AUTH-020 — /api/auth/me and MFA setup endpoints are exempt from require_mfa', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await setAppSetting(orm, 'require_mfa', 'true');const meRes = await request(app).get('/api/auth/me').set(authHeader(user.id));@@ -592,7 +577,7 @@ describe('Forced MFA policy', () => {});it('AUTH-020 — MFA-enabled user passes through require_mfa policy', async () => {- const { user } = createUserWithMfa(testDb);+ const { user } = await makeUserWithMfa(orm);await setAppSetting(orm, 'require_mfa', 'true');const res = await request(app).get('/api/trips').set(authHeader(user.id));@@ -604,8 +589,8 @@ describe('Forced MFA policy', () => {// must block the deeper trip-scoped controllers (budget/packing/todo) too —// not only /api/trips. A regression that only guarded top-level paths would// leave every addon endpoint reachable without MFA.- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await setAppSetting(orm, 'require_mfa', 'true');for (const path of [@@ -620,8 +605,8 @@ describe('Forced MFA policy', () => {});it('AUTH-020 — MFA-enabled user reaches nested Nest addon controllers under require_mfa', async () => {- const { user } = createUserWithMfa(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUserWithMfa(orm);+ const trip = await makeTrip(orm, user.id);await setAppSetting(orm, 'require_mfa', 'true');const res = await request(app).get(`/api/trips/${trip.id}/budget`).set(authHeader(user.id));@@ -635,7 +620,7 @@ describe('Forced MFA policy', () => {describe('Short-lived tokens', () => {it('AUTH-029 — POST /api/auth/ws-token returns a single-use token', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).post('/api/auth/ws-token').set('Cookie', authCookie(user.id));expect(res.status).toBe(200);expect(typeof res.body.token).toBe('string');@@ -643,7 +628,7 @@ describe('Short-lived tokens', () => {});it('AUTH-030 — POST /api/auth/resource-token returns a single-use token', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).post('/api/auth/resource-token').set('Cookie', authCookie(user.id))@@ -660,7 +645,7 @@ describe('Short-lived tokens', () => {describe('Extended auth scenarios', () => {it('AUTH-031 — login succeeds with uppercased email (case-insensitive lookup)', async () => {- const { user, password } = createUser(testDb, { email: '[email protected]' });+ const { user, password } = await makeUser(orm, { email: '[email protected]' });const res = await request(app).post('/api/auth/login').send({ email: '[email protected]', password });expect(res.status).toBe(200);@@ -668,7 +653,7 @@ describe('Extended auth scenarios', () => {});it('AUTH-032 — registration with duplicate username returns 409', async () => {- createUser(testDb, { username: 'alice' });+ await makeUser(orm, { username: 'alice' });const res = await request(app).post('/api/auth/register')@@ -678,7 +663,7 @@ describe('Extended auth scenarios', () => {it('AUTH-033 — MFA backup code login succeeds and invalidates the used code', async () => {const { hashBackupCode, generateBackupCodes } = await import('../../src/nest/auth/auth.helpers');- const { user, password } = createUserWithMfa(testDb);+ const { user, password } = await makeUserWithMfa(orm);// Generate and store backup codes on the MFA-enabled userconst backupCodes = generateBackupCodes();@@ -712,29 +697,29 @@ describe('Extended auth scenarios', () => {describe('Account deletion', () => {it('AUTH-040 — DELETE /auth/me succeeds when user has FK references', async () => {- const { user: admin } = createAdmin(testDb);- const { user: target } = createUser(testDb);- const { user: otherUser } = createUser(testDb);- const { user: thirdUser } = createUser(testDb);+ const { user: admin } = await makeAdmin(orm);+ const { user: target } = await makeUser(orm);+ const { user: otherUser } = await makeUser(orm);+ const { user: thirdUser } = await makeUser(orm);// trip_members.invited_by: target invited thirdUser to otherUser's trip// (trip survives deletion; only invited_by should become NULL)- const otherTrip = createTrip(testDb, otherUser.id);+ const otherTrip = await makeTrip(orm, otherUser.id);await insertRow(orm, TripMembers, { trip: otherTrip.id, user: thirdUser.id, invitedByRef: target.id });// share_tokens.created_by: target created a share token for otherUser's tripawait makeShareToken(orm, otherTrip.id, target.id, { token: 'tok-auth-test' });// budget_items.paid_by_user_id: target paid for an expense on otherUser's trip- const budgetItem = createBudgetItem(testDb, otherTrip.id);+ const budgetItem = await makeBudgetItem(orm, otherTrip.id);await updateRows(orm, BudgetItems, { id: budgetItem.id }, { paidByUser: target.id });// journey_contributors: target is a contributor on otherUser's journey- const otherJourney = createJourney(testDb, otherUser.id);- addJourneyContributor(testDb, otherJourney.id, target.id);+ const otherJourney = await makeJourney(orm, otherUser.id);+ await addJourneyContributor(orm, otherJourney.id, target.id);// journey_entries: target authored an entry on otherUser's journey- createJourneyEntry(testDb, otherJourney.id, target.id);+ await makeJourneyEntry(orm, otherJourney.id, target.id);// journey_share_tokens: target created a share token for otherUser's journeyawait insertRow(orm, JourneyShareTokens, {@@ -768,8 +753,8 @@ describe('Account deletion', () => {await insertRow(orm, UserNoticeDismissals, { user: target.id, notice_id: 'test-notice', dismissed_at: Date.now() });// owned journey: target owns a journey with an entry (cascade-deletes on journey deletion)- const ownedJourney = createJourney(testDb, target.id);- createJourneyEntry(testDb, ownedJourney.id, target.id);+ const ownedJourney = await makeJourney(orm, target.id);+ await makeJourneyEntry(orm, ownedJourney.id, target.id);// trip_files.uploaded_by (SET NULL): target uploaded a file to otherUser's tripconst fileId = await insertRow(orm, TripFiles, {@@ -787,22 +772,22 @@ describe('Account deletion', () => {});// trip_photos.user_id (CASCADE): target added a photo to otherUser's trip- addTripPhoto(testDb, otherTrip.id, target.id, 'asset-tp-auth', 'immich');+ await addTripPhoto(orm, otherTrip.id, target.id, 'asset-tp-auth', 'immich');// trips.user_id (CASCADE): target owns a trip- const ownedTrip = createTrip(testDb, target.id);+ const ownedTrip = await makeTrip(orm, target.id);// trip_members.user_id (CASCADE): target is a member of otherUser's trip- addTripMember(testDb, otherTrip.id, target.id);+ await addTripMember(orm, otherTrip.id, target.id);// categories.user_id (SET NULL): target created a category- const userCategory = createCategory(testDb, { user_id: target.id });+ const userCategory = await makeCategory(orm, { user: target.id });// tags.user_id (CASCADE): target created a tag- const userTag = createTag(testDb, target.id);+ const userTag = await makeTag(orm, target.id);// todo_items.assigned_user_id (SET NULL): target is assigned to a todo on otherUser's trip- const todoItem = createTodoItem(testDb, otherTrip.id);+ const todoItem = await makeTodoItem(orm, otherTrip.id);await updateRows(orm, TodoItems, { id: todoItem.id }, { assignedUser: target.id });// packing_bags.user_id (SET NULL): target owns a packing bag on otherUser's trip@@ -814,7 +799,7 @@ describe('Account deletion', () => {});// mcp_tokens.user_id (CASCADE): target has an MCP API token- createMcpToken(testDb, target.id);+ await makeMcpToken(orm, target.id);// oauth_tokens/consents.user_id (CASCADE): target has tokens from otherUser's OAuth clientawait insertRow(orm, OauthClients, {@@ -842,10 +827,10 @@ describe('Account deletion', () => {await insertRow(orm, VacayPlanMembers, { plan: otherVacayPlanId, user: target.id });// bucket_list.user_id (CASCADE): target has a bucket list item- createBucketListItem(testDb, target.id);+ await makeBucketListItem(orm, target.id);// visited_countries.user_id (CASCADE): target has visited a country- createVisitedCountry(testDb, target.id, 'JP');+ await markCountryVisited(orm, target.id, 'JP');// visited_regions.user_id (CASCADE): target has visited a regionawait insertRow(orm, VisitedRegions, {@@ -859,10 +844,10 @@ describe('Account deletion', () => {const packTemplateId = await insertRow(orm, PackingTemplates, { name: 'My Template', createdByRef: target.id });// invite_tokens.created_by (CASCADE): target created an invite token- createInviteToken(testDb, { created_by: target.id });+ await makeInviteToken(orm, target.id);// collab_notes.user_id (CASCADE): target authored a collab note on otherUser's trip- createCollabNote(testDb, otherTrip.id, target.id);+ await makeCollabNote(orm, otherTrip.id, target.id);// settings.user_id (CASCADE): target has a user settingawait setUserSetting(orm, target.id, 'theme', 'dark');@@ -1004,14 +989,14 @@ describe('Rate limiting', () => {describe('MCP token management', () => {it('AUTH-034 — GET /auth/mcp-tokens returns empty list initially', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).get('/api/auth/mcp-tokens').set('Cookie', authCookie(user.id));expect(res.status).toBe(200);expect(res.body.tokens).toEqual([]);});it('AUTH-035 — POST /auth/mcp-tokens creates a token', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).post('/api/auth/mcp-tokens').set('Cookie', authCookie(user.id))@@ -1022,13 +1007,13 @@ describe('MCP token management', () => {});it('AUTH-036 — POST /auth/mcp-tokens without name returns 400', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).post('/api/auth/mcp-tokens').set('Cookie', authCookie(user.id)).send({});expect(res.status).toBe(400);});it('AUTH-037 — DELETE /auth/mcp-tokens/:id deletes the token', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const createRes = await request(app).post('/api/auth/mcp-tokens').set('Cookie', authCookie(user.id))@@ -1045,7 +1030,7 @@ describe('MCP token management', () => {});it('AUTH-038 — DELETE /auth/mcp-tokens/:id returns 404 for non-existent', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).delete('/api/auth/mcp-tokens/99999').set('Cookie', authCookie(user.id));expect(res.status).toBe(404);});@@ -1056,14 +1041,14 @@ describe('MCP token management', () => {});it('AUTH-040 — DELETE /auth/mcp-tokens/abc (non-numeric id) returns the legacy 404, not a 500 (Plan 3b Task 2 review, F1)', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).delete('/api/auth/mcp-tokens/abc').set('Cookie', authCookie(user.id));expect(res.status).toBe(404);expect(res.body).toEqual({ error: 'Token not found' });});it('AUTH-041 — DELETE /auth/api-tokens/abc (non-numeric id) returns the legacy 404, not a 500 (Plan 3b Task 2 review, F1)', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const res = await request(app).delete('/api/auth/api-tokens/abc').set('Cookie', authCookie(user.id));expect(res.status).toBe(404);expect(res.body).toEqual({ error: 'Token not found' });diff --git a/server/tests/postgres/snapshot-suites-baseline.json b/server/tests/postgres/snapshot-suites-baseline.jsonindex fe3d65d7a..db79fa24b 100644--- a/server/tests/postgres/snapshot-suites-baseline.json+++ b/server/tests/postgres/snapshot-suites-baseline.json@@ -1,6 +1,4 @@[- "tests/integration/admin.test.ts",- "tests/integration/auth.test.ts","tests/integration/journey-place-order.test.ts","tests/integration/journey.test.ts","tests/integration/leg-mode-incoming.test.ts",