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 packing, places and plugin MCP suites on the real database module
Maurice6137aaf716c7
diff --git a/server/scripts/test-mocks-baseline.json b/server/scripts/test-mocks-baseline.jsonindex 147b6b20a..56bb729d9 100644--- a/server/scripts/test-mocks-baseline.json+++ b/server/scripts/test-mocks-baseline.json@@ -65,10 +65,6 @@"tests/unit/db/database-lazy-open.test.ts": 1,"tests/unit/mcp/tools-notifications.test.ts": 1,"tests/unit/mcp/tools-packing-advanced.test.ts": 1,- "tests/unit/mcp/tools-packing.test.ts": 1,- "tests/unit/mcp/tools-places.test.ts": 1,- "tests/unit/mcp/tools-plugin-pois.test.ts": 1,- "tests/unit/mcp/tools-plugin-search.test.ts": 1,"tests/unit/mcp/tools-prompts.test.ts": 1,"tests/unit/mcp/tools-reservations.test.ts": 1,"tests/unit/mcp/tools-roadtrip.test.ts": 1,diff --git a/server/tests/postgres/snapshot-suites-baseline.json b/server/tests/postgres/snapshot-suites-baseline.jsonindex a0f9e4dd7..852106339 100644--- a/server/tests/postgres/snapshot-suites-baseline.json+++ b/server/tests/postgres/snapshot-suites-baseline.json@@ -1,10 +1,6 @@["tests/unit/mcp/tools-notifications.test.ts","tests/unit/mcp/tools-packing-advanced.test.ts",- "tests/unit/mcp/tools-packing.test.ts",- "tests/unit/mcp/tools-places.test.ts",- "tests/unit/mcp/tools-plugin-pois.test.ts",- "tests/unit/mcp/tools-plugin-search.test.ts","tests/unit/mcp/tools-reservations.test.ts","tests/unit/mcp/tools-roadtrip.test.ts","tests/unit/mcp/tools-settings.test.ts",diff --git a/server/tests/unit/mcp/tools-packing.test.ts b/server/tests/unit/mcp/tools-packing.test.tsindex 23073e5de..c1788a04c 100644--- a/server/tests/unit/mcp/tools-packing.test.ts+++ b/server/tests/unit/mcp/tools-packing.test.ts@@ -12,44 +12,44 @@* legacy registerResources fan-out anymore).*/import { ADDON_IDS } from '../../../src/addons';-import { db as testDb } from '../../../src/db/database';import { PackingBags } from '../../../src/db/entities/PackingBags.entity';import { PackingItems } from '../../../src/db/entities/PackingItems.entity';-import { createUser, createTrip, createPackingItem, addTripMember } from '../../helpers/factories';import { inContext } from '../../helpers/factories/context';-import { addPackingBagMembers, addPackingItemRecipients, makePackingBag } from '../../helpers/factories/packing';+import {+ addPackingBagMembers,+ addPackingItemRecipients,+ makePackingBag,+ makePackingItem,+} from '../../helpers/factories/packing';import { countRows, findRow, insertRow, updateRows } from '../../helpers/factories/rows';import { setAddonEnabled } from '../../helpers/factories/settings';+import { addTripMember, makeTrip } from '../../helpers/factories/trips';+import { makeUser } from '../../helpers/factories/users';import { FakeRealtimeService } from '../../helpers/fake-realtime';import { createMcpHarness, parseToolResult, parseResourceResult, type McpHarness } from '../../helpers/mcp-harness';-import { resetTestDb } from '../../helpers/test-db';-import { createTestOrm, type TestOrm } from '../../helpers/test-orm';+import { resetDatabase } from '../../helpers/reset-database';+import { bootTestApp } from '../../helpers/test-app';+import { MikroORM } from '@mikro-orm/core';-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';const realtime = new FakeRealtimeService();const broadcastMock = realtime.broadcastMock;-let orm: TestOrm;+let orm: MikroORM;beforeAll(async () => {- orm = await createTestOrm(testDb);+ orm = (await bootTestApp(realtime)).get(MikroORM);});-beforeEach(() => {- resetTestDb(testDb);+beforeEach(async () => {+ await resetDatabase(orm);broadcastMock.mockClear();delete process.env.DEMO_MODE;});afterAll(async () => {- await orm.close();- testDb.close();+ await (await bootTestApp(realtime)).close();});async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {@@ -72,8 +72,8 @@ const errorText = (result: unknown) =>describe('Tool: create_packing_item', () => {it('creates a packing item', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -87,8 +87,8 @@ describe('Tool: create_packing_item', () => {});it('defaults category to "General"', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -100,8 +100,8 @@ describe('Tool: create_packing_item', () => {});it('broadcasts packing:created event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {await h.client.callTool({ name: 'create_packing_item', arguments: { tripId: trip.id, name: 'Hat' } });expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'packing:created', expect.any(Object));@@ -109,9 +109,9 @@ describe('Tool: create_packing_item', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -123,8 +123,8 @@ describe('Tool: create_packing_item', () => {it('blocks demo user', async () => {process.env.DEMO_MODE = 'true';- const { user } = createUser(testDb, { email: '[email protected]' });- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm, { email: '[email protected]' });+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -156,8 +156,8 @@ const recipientIds = async (itemId: number) =>describe('Tool: create_packing_item sharing', () => {it("puts a personal item on the caller's own list", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -170,11 +170,11 @@ describe('Tool: create_packing_item sharing', () => {});it('records the recipients of a shared item and drops ids off the trip roster', async () => {- const { user } = createUser(testDb);- const { user: mate } = createUser(testDb);- const { user: stranger } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, mate.id);+ const { user } = await makeUser(orm);+ const { user: mate } = await makeUser(orm);+ const { user: stranger } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, mate.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -187,8 +187,8 @@ describe('Tool: create_packing_item sharing', () => {});it('honours the legacy is_private flag', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -199,8 +199,8 @@ describe('Tool: create_packing_item sharing', () => {});it('creates an already-checked item', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -211,8 +211,8 @@ describe('Tool: create_packing_item sharing', () => {});it('keeps a personal item off the rest of the room', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'create_packing_item',@@ -224,8 +224,8 @@ describe('Tool: create_packing_item sharing', () => {});it('refuses a visibility tier that does not exist', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_packing_item',@@ -246,8 +246,8 @@ describe('Tool: create_packing_item sharing', () => {describe('Tool: create_packing_item bag, quantity, weight (#2154)', () => {it('creates the item with its bag, quantity and weight in one write', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const { id: bagId } = await makePackingBag(orm, trip.id, { name: 'Carry-On' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -262,9 +262,9 @@ describe('Tool: create_packing_item bag, quantity, weight (#2154)', () => {});it('refuses a bag from another trip, inserting nothing', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const otherTrip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const otherTrip = await makeTrip(orm, user.id);const { id: foreignBag } = await makePackingBag(orm, otherTrip.id, { name: 'Foreign' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -284,9 +284,9 @@ describe('Tool: create_packing_item bag, quantity, weight (#2154)', () => {describe('Tool: update_packing_item', () => {it('updates packing item name and category', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id, { name: 'Old', category: 'Clothes' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id, { name: 'Old', category: 'Clothes' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_packing_item',@@ -299,9 +299,9 @@ describe('Tool: update_packing_item', () => {});it('counts packed pieces like the REST route does (#2296)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id, { name: 'Shirts' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id, { name: 'Shirts' });await withHarness(user.id, async (h) => {await h.client.callTool({name: 'update_packing_item',@@ -325,9 +325,9 @@ describe('Tool: update_packing_item', () => {});it('broadcasts packing:updated event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'update_packing_item',@@ -338,8 +338,8 @@ describe('Tool: update_packing_item', () => {});it('returns error for item not found', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_packing_item',@@ -350,10 +350,10 @@ describe('Tool: update_packing_item', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_packing_item',@@ -376,9 +376,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {const makeBag = async (tripId: number, name = 'Carry-On') => (await makePackingBag(orm, tripId, { name })).id;it('moves an item into a bag', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);const bagId = await makeBag(trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -391,9 +391,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {});it('takes an item out of its bag with an explicit null', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);const bagId = await makeBag(trip.id);await updateRows(orm, PackingItems, { id: item.id }, { bag: bagId });await withHarness(user.id, async (h) => {@@ -406,9 +406,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {});it('sets the quantity', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'update_packing_item',@@ -419,9 +419,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {});it('sets and clears the weight', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'update_packing_item',@@ -438,9 +438,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {});it('leaves the bag alone when the key is omitted', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);const bagId = await makeBag(trip.id);await updateRows(orm, PackingItems, { id: item.id }, { bag: bagId });await withHarness(user.id, async (h) => {@@ -453,9 +453,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {});it("takes a common item onto the caller's own list, and off everyone else's screen", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'update_packing_item',@@ -472,9 +472,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {});it('hands a private item back to the room when it goes common again', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await updateRows(orm, PackingItems, { id: item.id }, { is_private: 1, owner: user.id });await withHarness(user.id, async (h) => {await h.client.callTool({@@ -489,9 +489,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {});it('refuses a bag id that is not a number', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_packing_item',@@ -504,10 +504,10 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {});it('refuses a bag from another trip (#2154)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const otherTrip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const otherTrip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);const foreignBag = await makeBag(otherTrip.id, 'Foreign');await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -527,9 +527,9 @@ describe('Tool: update_packing_item bag, quantity, weight, privacy', () => {describe('Tool: set_packing_item_sharing', () => {it("moves a common item onto the caller's own list", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_packing_item_sharing',@@ -543,12 +543,12 @@ describe('Tool: set_packing_item_sharing', () => {});it('shares an item with named members and drops ids off the trip roster', async () => {- const { user } = createUser(testDb);- const { user: mate } = createUser(testDb);- const { user: stranger } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, mate.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: mate } = await makeUser(orm);+ const { user: stranger } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, mate.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'set_packing_item_sharing',@@ -560,11 +560,11 @@ describe('Tool: set_packing_item_sharing', () => {});it('returns an item to the common list and forgets its recipients', async () => {- const { user } = createUser(testDb);- const { user: mate } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, mate.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: mate } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, mate.id);+ const item = await makePackingItem(orm, trip.id);await updateRows(orm, PackingItems, { id: item.id }, { is_private: 1, owner: user.id });await addPackingItemRecipients(orm, item.id, [mate.id]);await withHarness(user.id, async (h) => {@@ -578,9 +578,9 @@ describe('Tool: set_packing_item_sharing', () => {});it("rebuilds the room's view: gone for everyone, back for the people who may see it", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'set_packing_item_sharing',@@ -595,11 +595,11 @@ describe('Tool: set_packing_item_sharing', () => {});it('lets only the owner change sharing', async () => {- const { user } = createUser(testDb);- const { user: mate } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, mate.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: mate } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, mate.id);+ const item = await makePackingItem(orm, trip.id);await updateRows(orm, PackingItems, { id: item.id }, { owner: mate.id });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -612,8 +612,8 @@ describe('Tool: set_packing_item_sharing', () => {});it('returns error for item not found', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_packing_item_sharing',@@ -624,10 +624,10 @@ describe('Tool: set_packing_item_sharing', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_packing_item_sharing',@@ -640,9 +640,9 @@ describe('Tool: set_packing_item_sharing', () => {it('blocks demo user', async () => {process.env.DEMO_MODE = 'true';- const { user } = createUser(testDb, { email: '[email protected]' });- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm, { email: '[email protected]' });+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_packing_item_sharing',@@ -653,9 +653,9 @@ describe('Tool: set_packing_item_sharing', () => {});it('refuses a visibility tier that does not exist', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_packing_item_sharing',@@ -678,8 +678,8 @@ describe('Tool: update_packing_bag limit and owner', () => {const makeBag = async (tripId: number) => (await makePackingBag(orm, tripId, { name: 'Carry-On' })).id;it('sets a weight limit', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const bagId = await makeBag(trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -692,8 +692,8 @@ describe('Tool: update_packing_bag limit and owner', () => {});it('lifts the limit with an explicit null', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const bagId = await makeBag(trip.id);await updateRows(orm, PackingBags, { id: bagId }, { weight_limit_grams: 8000 });await withHarness(user.id, async (h) => {@@ -706,8 +706,8 @@ describe('Tool: update_packing_bag limit and owner', () => {});it('leaves the limit alone when the key is omitted', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const bagId = await makeBag(trip.id);await updateRows(orm, PackingBags, { id: bagId }, { weight_limit_grams: 8000 });await withHarness(user.id, async (h) => {@@ -719,10 +719,10 @@ describe('Tool: update_packing_bag limit and owner', () => {});it('assigns the bag to a trip member', async () => {- const { user } = createUser(testDb);- const { user: mate } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, mate.id);+ const { user } = await makeUser(orm);+ const { user: mate } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, mate.id);const bagId = await makeBag(trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({ name: 'update_packing_bag', arguments: { tripId: trip.id, bagId, user_id: mate.id } });@@ -731,9 +731,9 @@ describe('Tool: update_packing_bag limit and owner', () => {});it('leaves the bag unassigned for an id off the trip roster', async () => {- const { user } = createUser(testDb);- const { user: stranger } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const { user: stranger } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const bagId = await makeBag(trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({@@ -745,8 +745,8 @@ describe('Tool: update_packing_bag limit and owner', () => {});it('refuses a weight limit that is not a number', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const bagId = await makeBag(trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -766,9 +766,9 @@ describe('Tool: update_packing_bag limit and owner', () => {describe('Tool: toggle_packing_item', () => {it('checks a packing item', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'toggle_packing_item',@@ -780,9 +780,9 @@ describe('Tool: toggle_packing_item', () => {});it('unchecks a packing item', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await updateRows(orm, PackingItems, { id: item.id }, { checked: 1 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -795,9 +795,9 @@ describe('Tool: toggle_packing_item', () => {});it('broadcasts packing:updated event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'toggle_packing_item',@@ -808,8 +808,8 @@ describe('Tool: toggle_packing_item', () => {});it('returns error for item not found', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'toggle_packing_item',@@ -820,10 +820,10 @@ describe('Tool: toggle_packing_item', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'toggle_packing_item',@@ -840,9 +840,9 @@ describe('Tool: toggle_packing_item', () => {describe('Tool: delete_packing_item', () => {it('deletes an existing packing item', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'delete_packing_item',@@ -855,9 +855,9 @@ describe('Tool: delete_packing_item', () => {});it('broadcasts packing:deleted event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({ name: 'delete_packing_item', arguments: { tripId: trip.id, itemId: item.id } });expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'packing:deleted', expect.any(Object));@@ -865,8 +865,8 @@ describe('Tool: delete_packing_item', () => {});it('returns error for item not found', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'delete_packing_item',@@ -877,10 +877,10 @@ describe('Tool: delete_packing_item', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'delete_packing_item',@@ -897,14 +897,14 @@ describe('Tool: delete_packing_item', () => {describe('Tool: list_packing_items', () => {it("PACKMCP-001: hides another member's own items; narrows to a category, a bag, no bag or a status", async () => {- const { user } = createUser(testDb);- const { user: mate } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, mate.id);+ const { user } = await makeUser(orm);+ const { user: mate } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, mate.id);const { id: bagId } = await makePackingBag(orm, trip.id, { name: 'Carry-On' });- const jacket = createPackingItem(testDb, trip.id, { name: 'Jacket', category: 'Clothes' });- createPackingItem(testDb, trip.id, { name: 'Charger', category: 'Tech' });- const diary = createPackingItem(testDb, trip.id, { name: 'Diary', category: 'Clothes' });+ const jacket = await makePackingItem(orm, trip.id, { name: 'Jacket', category: 'Clothes' });+ await makePackingItem(orm, trip.id, { name: 'Charger', category: 'Tech' });+ const diary = await makePackingItem(orm, trip.id, { name: 'Diary', category: 'Clothes' });await updateRows(orm, PackingItems, { id: jacket.id }, { bag: bagId, checked: 1 });await updateRows(orm, PackingItems, { id: diary.id }, { is_private: 1, owner: mate.id });@@ -924,10 +924,10 @@ describe('Tool: list_packing_items', () => {});it('PACKMCP-002: answers a trip the user is not part of with the access-denied payload', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- createPackingItem(testDb, trip.id, { name: 'Jacket' });+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ await makePackingItem(orm, trip.id, { name: 'Jacket' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'list_packing_items', arguments: { tripId: trip.id } });expect(result.isError).toBe(true);@@ -974,20 +974,20 @@ describe('Packing tools — scope gating', () => {}it('registers all nineteen tools with null scopes (full access)', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const names = await listToolNames(user.id, null);for (const tool of [...READ_TOOLS, ...WRITE_TOOLS]) expect(names).toContain(tool);});it('registers only the read tools with packing:read', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const names = await listToolNames(user.id, ['packing:read']);for (const tool of READ_TOOLS) expect(names).toContain(tool);for (const tool of WRITE_TOOLS) expect(names).not.toContain(tool);});it('registers no packing tools for an unrelated scope', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const names = await listToolNames(user.id, ['budget:read']);for (const tool of [...READ_TOOLS, ...WRITE_TOOLS]) expect(names).not.toContain(tool);});@@ -1000,8 +1000,8 @@ describe('Packing tools — scope gating', () => {describe('Packing tools — packing addon gating', () => {it('registers nothing (tools or resources) when the packing addon is disabled', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await setAddonEnabled(orm, ADDON_IDS.PACKING, false);try {await withHarness(user.id, async (h) => {@@ -1023,9 +1023,9 @@ describe('Packing tools — packing addon gating', () => {describe('Resource: trek://trips/{tripId}/packing', () => {it('returns packing items for a trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- createPackingItem(testDb, trip.id, { name: 'Passport' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await makePackingItem(orm, trip.id, { name: 'Passport' });await withHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/packing` });const items = parseResourceResult(result) as { name: string }[];@@ -1035,9 +1035,9 @@ describe('Resource: trek://trips/{tripId}/packing', () => {});it("hides another member's private items from the requesting user (#858)", async () => {- const { user } = createUser(testDb);- const { user: owner } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const { user: owner } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await insertRow(orm, PackingItems, {trip: trip.id,name: 'Secret gift',@@ -1053,9 +1053,9 @@ describe('Resource: trek://trips/{tripId}/packing', () => {});it('returns the access-denied payload for a non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/packing` });expect(parseResourceResult(result)).toEqual({ error: 'Trip not found or access denied' });@@ -1063,7 +1063,7 @@ describe('Resource: trek://trips/{tripId}/packing', () => {});it('returns the access-denied payload for a malformed trip id', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await withHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: 'trek://trips/not-a-number/packing' });expect(parseResourceResult(result)).toEqual({ error: 'Trip not found or access denied' });@@ -1077,8 +1077,8 @@ describe('Resource: trek://trips/{tripId}/packing', () => {describe('Resource: trek://trips/{tripId}/packing/bags', () => {it('returns the bags with their members', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const { id: bagId } = await makePackingBag(orm, trip.id, { name: 'Carry-On' });await addPackingBagMembers(orm, bagId, [user.id]);await withHarness(user.id, async (h) => {@@ -1091,9 +1091,9 @@ describe('Resource: trek://trips/{tripId}/packing/bags', () => {});it('returns the access-denied payload for a non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/packing/bags` });expect(parseResourceResult(result)).toEqual({ error: 'Trip not found or access denied' });@@ -1128,9 +1128,9 @@ describe('a restricted packing item over MCP', () => {updateRows(orm, PackingItems, { id: itemId }, { is_private: 1, owner: ownerId });it('is ticked off for its owner alone, not for the whole trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await makePrivate(item.id, user.id);await withHarness(user.id, async (h) => {@@ -1147,9 +1147,9 @@ describe('a restricted packing item over MCP', () => {});it('is renamed for its owner alone', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await makePrivate(item.id, user.id);await withHarness(user.id, async (h) => {@@ -1170,9 +1170,9 @@ describe('a restricted packing item over MCP', () => {* delete hands back.*/it('is deleted for its owner alone', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await makePrivate(item.id, user.id);await withHarness(user.id, async (h) => {@@ -1187,9 +1187,9 @@ describe('a restricted packing item over MCP', () => {});it('still tells the whole room about a shared one, unchanged', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createPackingItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makePackingItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({diff --git a/server/tests/unit/mcp/tools-places.test.ts b/server/tests/unit/mcp/tools-places.test.tsindex f0ab0c1c9..eaf9b3fdc 100644--- a/server/tests/unit/mcp/tools-places.test.ts+++ b/server/tests/unit/mcp/tools-places.test.ts@@ -7,7 +7,6 @@* container's registry (tests/helpers/mcp-test-controllers.ts), so the assertions below* exercise the @Tool/@ResourceTemplate path instead of the deleted registrar.*/-import { db as testDb } from '../../../src/db/database';import { BudgetItems } from '../../../src/db/entities/BudgetItems.entity';import { Categories } from '../../../src/db/entities/Categories.entity';import { DayAssignments } from '../../../src/db/entities/DayAssignments.entity';@@ -20,46 +19,36 @@ import { JourneyDomainService } from '../../../src/nest/journey/journey-domain.simport { MapsService } from '../../../src/nest/maps/maps.service';import { PlacesService } from '../../../src/nest/places/places.service';import { StorageService } from '../../../src/nest/storage/storage.service';-import {- createUser,- createTrip,- createPlace,- createDay,- createDayAssignment,- createJourney,-} from '../../helpers/factories';import { makeBudgetItem } from '../../helpers/factories/budget';import { makeTripFile } from '../../helpers/factories/files';import { makeDayAssignment } from '../../helpers/factories/itinerary';-import { linkTripToJourney } from '../../helpers/factories/journeys';+import { linkTripToJourney, makeJourney } from '../../helpers/factories/journeys';+import { makePlace } from '../../helpers/factories/places';import { countRows, findRow, findRows, insertRow, updateRows } from '../../helpers/factories/rows';+import { makeDay, makeTrip } from '../../helpers/factories/trips';+import { makeUser } from '../../helpers/factories/users';import { FakeRealtimeService } from '../../helpers/fake-realtime';import { createMcpHarness, parseToolResult, parseResourceResult, type McpHarness } from '../../helpers/mcp-harness';+import { resetDatabase } from '../../helpers/reset-database';import { bootTestApp } from '../../helpers/test-app';+import { MikroORM } from '@mikro-orm/core';+// PlacesMcp and PlacesService both inject MapsService (search_place and the// import enrichment), so the geo calls are stubbed on the prototype — see// beforeEach — rather than through a module mock.-import { resetTestDb } from '../../helpers/test-db';-import { createTestOrm, type TestOrm } from '../../helpers/test-orm';-import { Readable } from 'node:stream';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());-});-const { searchPlacesMock } = vi.hoisted(() => ({ searchPlacesMock: vi.fn() }));const realtime = new FakeRealtimeService();const broadcastMock = realtime.broadcastMock;-let orm: TestOrm;+let orm: MikroORM;beforeAll(async () => {- orm = await createTestOrm(testDb);+ orm = (await bootTestApp(realtime)).get(MikroORM);});/** Link a journey to a trip so journey-skeleton sync has a target. */@@ -74,8 +63,8 @@ async function imageOf(placeId: number): Promise<string | null | undefined> {return (await findRow(orm, Places, { id: placeId }))!.image_url;}-beforeEach(() => {- resetTestDb(testDb);+beforeEach(async () => {+ await resetDatabase(orm);broadcastMock.mockClear();searchPlacesMock.mockClear();vi.spyOn(MapsService.prototype, 'searchPlaces').mockImplementation(searchPlacesMock as never);@@ -83,8 +72,7 @@ beforeEach(() => {});afterAll(async () => {- await orm.close();- testDb.close();+ await (await bootTestApp(realtime)).close();});async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {@@ -102,8 +90,8 @@ async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>)describe('Tool: create_place', () => {it('creates a place with all fields', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const cat = (await findRow(orm, Categories, {}))!;await withHarness(user.id, async (h) => {@@ -129,8 +117,8 @@ describe('Tool: create_place', () => {});it('creates a place with minimal fields', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -144,8 +132,8 @@ describe('Tool: create_place', () => {});it('persists image_url on the row (#37)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {await h.client.callTool({@@ -159,8 +147,8 @@ describe('Tool: create_place', () => {});it('accepts the photo-proxy path the place picker hands out', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {await h.client.callTool({@@ -176,8 +164,8 @@ describe('Tool: create_place', () => {// The marker builders assemble their HTML as a string, so the scheme pin is the// thing standing between a stored value and the DOM. Same contract as REST.it('refuses an image_url outside the four allowed shapes', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -192,8 +180,8 @@ describe('Tool: create_place', () => {});it('broadcasts place:created event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {await h.client.callTool({ name: 'create_place', arguments: { tripId: trip.id, name: 'Cafe' } });expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'place:created', expect.any(Object));@@ -201,9 +189,9 @@ describe('Tool: create_place', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'create_place', arguments: { tripId: trip.id, name: 'Hack' } });expect(result.isError).toBe(true);@@ -212,8 +200,8 @@ describe('Tool: create_place', () => {it('blocks demo user', async () => {process.env.DEMO_MODE = 'true';- const { user } = createUser(testDb, { email: '[email protected]' });- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm, { email: '[email protected]' });+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'create_place', arguments: { tripId: trip.id, name: 'X' } });expect(result.isError).toBe(true);@@ -227,10 +215,10 @@ describe('Tool: create_place', () => {describe('Tool: set_place_image_from_file (#1242)', () => {it('refuses a file that is no picture, and one from another trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const other = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const other = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id);const pdf = (await makeTripFile(orm, trip.id, { filename: 'a.pdf', original_name: 'a.pdf', mime_type: 'application/pdf' })).id;@@ -254,9 +242,9 @@ describe('Tool: set_place_image_from_file (#1242)', () => {describe('Tool: update_place', () => {it('updates specific fields and preserves others', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Old Name' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Old Name' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -271,9 +259,9 @@ describe('Tool: update_place', () => {});it('takes an e-mail and structured opening hours, and null clears the hours (#2472)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Bakery' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Bakery' });const hours = [{ closed: false, open: '08:00', close: '18:00' },...Array.from({ length: 6 }, () => ({ closed: true })),@@ -307,9 +295,9 @@ describe('Tool: update_place', () => {});it('moving a place drops the country Atlas cached for it, renaming it does not (#2527)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Hotel', lat: 48.8566, lng: 2.3522 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Hotel', lat: 48.8566, lng: 2.3522 });await insertRow(orm, PlaceRegions, {place: place.id,country_code: 'FR',@@ -344,9 +332,9 @@ describe('Tool: update_place', () => {});it('broadcasts place:updated event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'update_place',@@ -359,9 +347,9 @@ describe('Tool: update_place', () => {it('refuses a misspelt field instead of silently updating nothing', async () => {// An assistant wrote stopType for stop_type; the call used to come back as a// success with the place untouched, and the road trip never got its fuel stop.- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Aral Bad Segeberg' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Aral Bad Segeberg' });await withHarness(user.id, async (h) => {const refused = await h.client.callTool({name: 'update_place',@@ -382,9 +370,9 @@ describe('Tool: update_place', () => {});it('sets image_url on an existing place (#37)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Unpictured' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Unpictured' });await withHarness(user.id, async (h) => {await h.client.callTool({@@ -399,9 +387,9 @@ describe('Tool: update_place', () => {// The service reads image_url through a `!== undefined` sentinel, so null is the// only way to say "remove the picture" - an omitted field keeps the old one.it('clears image_url when null is passed, and leaves it alone when omitted', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Pictured' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Pictured' });await updateRows(orm, Places, { id: place.id }, { image_url: '/uploads/places/old.jpg' });await withHarness(user.id, async (h) => {@@ -422,9 +410,9 @@ describe('Tool: update_place', () => {});it('refuses an image_url outside the four allowed shapes', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Pictured' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Pictured' });await updateRows(orm, Places, { id: place.id }, { image_url: 'https://cdn.example.com/keep.jpg' });await withHarness(user.id, async (h) => {@@ -440,8 +428,8 @@ describe('Tool: update_place', () => {});it('returns error for place not found in trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'update_place', arguments: { tripId: trip.id, placeId: 99999 } });expect(result.isError).toBe(true);@@ -449,10 +437,10 @@ describe('Tool: update_place', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const place = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const place = await makePlace(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_place',@@ -469,10 +457,10 @@ describe('Tool: update_place', () => {describe('Tool: bulk_update_places', () => {it('applies the same field to many places in one call', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const a = createPlace(testDb, trip.id, { name: 'A' });- const b = createPlace(testDb, trip.id, { name: 'B' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const a = await makePlace(orm, trip.id, { name: 'A' });+ const b = await makePlace(orm, trip.id, { name: 'B' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -487,10 +475,10 @@ describe('Tool: bulk_update_places', () => {});it('broadcasts place:updated for each updated place', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const a = createPlace(testDb, trip.id);- const b = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const a = await makePlace(orm, trip.id);+ const b = await makePlace(orm, trip.id);await withHarness(user.id, async (h) => {broadcastMock.mockClear();await h.client.callTool({@@ -503,10 +491,10 @@ describe('Tool: bulk_update_places', () => {});it('sets the same image_url on every listed place (#37)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const a = createPlace(testDb, trip.id, { name: 'A' });- const b = createPlace(testDb, trip.id, { name: 'B' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const a = await makePlace(orm, trip.id, { name: 'A' });+ const b = await makePlace(orm, trip.id, { name: 'B' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -523,10 +511,10 @@ describe('Tool: bulk_update_places', () => {// A lone null still counts as a field, which is what makes "strip the pictures// off these eighty places" reachable in one call.it('strips the pictures off a batch when image_url is null', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const a = createPlace(testDb, trip.id, { name: 'A' });- const b = createPlace(testDb, trip.id, { name: 'B' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const a = await makePlace(orm, trip.id, { name: 'A' });+ const b = await makePlace(orm, trip.id, { name: 'B' });await updateRows(orm, Places, { id: { $in: [a.id, b.id] } }, { image_url: 'https://cdn.example.com/old.jpg' });await withHarness(user.id, async (h) => {@@ -542,9 +530,9 @@ describe('Tool: bulk_update_places', () => {});it('errors when no update fields are provided', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const a = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const a = await makePlace(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'bulk_update_places',@@ -555,10 +543,10 @@ describe('Tool: bulk_update_places', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const place = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const place = await makePlace(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'bulk_update_places',@@ -575,9 +563,9 @@ describe('Tool: bulk_update_places', () => {describe('Tool: delete_place', () => {it('deletes an existing place', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'delete_place',@@ -590,9 +578,9 @@ describe('Tool: delete_place', () => {});it('takes the linked expense with it and announces that too (#1298)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id);const { id: itemId } = await makeBudgetItem(orm, trip.id, { name: 'Tickets', total_price: 34, place: place.id });await withHarness(user.id, async (h) => {@@ -603,9 +591,9 @@ describe('Tool: delete_place', () => {});it('broadcasts place:deleted event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({ name: 'delete_place', arguments: { tripId: trip.id, placeId: place.id } });expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'place:deleted', expect.any(Object));@@ -613,8 +601,8 @@ describe('Tool: delete_place', () => {});it('returns error for place not found', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'delete_place', arguments: { tripId: trip.id, placeId: 99999 } });expect(result.isError).toBe(true);@@ -622,10 +610,10 @@ describe('Tool: delete_place', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const place = createPlace(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const place = await makePlace(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'delete_place',@@ -636,12 +624,12 @@ describe('Tool: delete_place', () => {});it('removes the linked journey skeleton when the place is deleted', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const day = createDay(testDb, trip.id);- const place = createPlace(testDb, trip.id);- createDayAssignment(testDb, day.id, place.id);- const journey = createJourney(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const day = await makeDay(orm, trip.id);+ const place = await makePlace(orm, trip.id);+ await makeDayAssignment(orm, day.id, place.id);+ const journey = await makeJourney(orm, user.id);await linkJourney(journey.id, trip.id);// Materialise the skeleton for the assigned place.await seedSkeleton(journey.id, trip.id, place.id, user.id, place.name);@@ -660,10 +648,10 @@ describe('Tool: delete_place', () => {describe('Tool: create_and_assign_place', () => {it('creates a skeleton suggestion in a linked journey', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const day = createDay(testDb, trip.id);- const journey = createJourney(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const day = await makeDay(orm, trip.id);+ const journey = await makeJourney(orm, user.id);await linkJourney(journey.id, trip.id);await withHarness(user.id, async (h) => {@@ -681,9 +669,9 @@ describe('Tool: create_and_assign_place', () => {});it('persists image_url on the place it creates (#37)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const day = createDay(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const day = await makeDay(orm, trip.id);await withHarness(user.id, async (h) => {const result = parseToolResult(@@ -703,7 +691,7 @@ describe('Tool: create_and_assign_place', () => {describe('Tool: search_place', () => {it('returns OSM results when no Google key is configured', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);searchPlacesMock.mockResolvedValue({source: 'openstreetmap',places: [@@ -731,7 +719,7 @@ describe('Tool: search_place', () => {});it('returns google_place_id when Google Maps is configured', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);searchPlacesMock.mockResolvedValue({source: 'google',places: [@@ -762,7 +750,7 @@ describe('Tool: search_place', () => {});it('returns error when place search fails', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);searchPlacesMock.mockRejectedValue(new Error('Search failed'));await withHarness(user.id, async (h) => {@@ -774,7 +762,7 @@ describe('Tool: search_place', () => {// Without the bias a bare name resolves wherever the provider guesses, which is// how "Central Station" used to come back from the wrong continent (#32).it('forwards locationBias and lang to the provider', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);searchPlacesMock.mockResolvedValue({ source: 'google', places: [] });await withHarness(user.id, async (h) => {@@ -797,7 +785,7 @@ describe('Tool: search_place', () => {});it('accepts a bias without an explicit radius', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);searchPlacesMock.mockResolvedValue({ source: 'google', places: [] });await withHarness(user.id, async (h) => {@@ -816,7 +804,7 @@ describe('Tool: search_place', () => {});it('sends one search to Google alone when asked to, and refuses any other provider', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);searchPlacesMock.mockResolvedValue({ source: 'google', places: [] });await withHarness(user.id, async (h) => {@@ -836,7 +824,7 @@ describe('Tool: search_place', () => {});it('refuses a locationBias that is missing a coordinate', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);searchPlacesMock.mockResolvedValue({ source: 'google', places: [] });await withHarness(user.id, async (h) => {@@ -856,11 +844,11 @@ describe('Tool: search_place', () => {describe('Tool: list_places', () => {it('returns all places by default', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place1 = createPlace(testDb, trip.id, { name: 'Orphan Place' });- const place2 = createPlace(testDb, trip.id, { name: 'Assigned Place' });- const day = createDay(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place1 = await makePlace(orm, trip.id, { name: 'Orphan Place' });+ const place2 = await makePlace(orm, trip.id, { name: 'Assigned Place' });+ const day = await makeDay(orm, trip.id);await makeDayAssignment(orm, day.id, place2.id);await withHarness(user.id, async (h) => {@@ -871,11 +859,11 @@ describe('Tool: list_places', () => {});it('returns only unassigned places with assignment=unassigned', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const orphan = createPlace(testDb, trip.id, { name: 'Orphan Place' });- const assigned = createPlace(testDb, trip.id, { name: 'Assigned Place' });- const day = createDay(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const orphan = await makePlace(orm, trip.id, { name: 'Orphan Place' });+ const assigned = await makePlace(orm, trip.id, { name: 'Assigned Place' });+ const day = await makeDay(orm, trip.id);await makeDayAssignment(orm, day.id, assigned.id);await withHarness(user.id, async (h) => {@@ -890,11 +878,11 @@ describe('Tool: list_places', () => {});it('returns only assigned places with assignment=assigned', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const orphan = createPlace(testDb, trip.id, { name: 'Orphan Place' });- const assigned = createPlace(testDb, trip.id, { name: 'Assigned Place' });- const day = createDay(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const orphan = await makePlace(orm, trip.id, { name: 'Orphan Place' });+ const assigned = await makePlace(orm, trip.id, { name: 'Assigned Place' });+ const day = await makeDay(orm, trip.id);await makeDayAssignment(orm, day.id, assigned.id);await withHarness(user.id, async (h) => {@@ -909,10 +897,10 @@ describe('Tool: list_places', () => {});it('returns empty array when all places are assigned', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Only Place' });- const day = createDay(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Only Place' });+ const day = await makeDay(orm, trip.id);await makeDayAssignment(orm, day.id, place.id);await withHarness(user.id, async (h) => {@@ -926,11 +914,11 @@ describe('Tool: list_places', () => {});it('composes with search filter', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const orphan = createPlace(testDb, trip.id, { name: 'Louvre Museum' });- const assigned = createPlace(testDb, trip.id, { name: 'Eiffel Tower' });- const day = createDay(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const orphan = await makePlace(orm, trip.id, { name: 'Louvre Museum' });+ const assigned = await makePlace(orm, trip.id, { name: 'Eiffel Tower' });+ const day = await makeDay(orm, trip.id);await makeDayAssignment(orm, day.id, assigned.id);await withHarness(user.id, async (h) => {@@ -945,9 +933,9 @@ describe('Tool: list_places', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'list_places', arguments: { tripId: trip.id } });expect(result.isError).toBe(true);@@ -961,9 +949,9 @@ describe('Tool: list_places', () => {describe('Tool: rate_place', () => {it("stores the acting user's vote and reports the aggregate", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Rated' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Rated' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -982,9 +970,9 @@ describe('Tool: rate_place', () => {});it('an omitted rating clears the vote', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Rated' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Rated' });await withHarness(user.id, async (h) => {await h.client.callTool({ name: 'rate_place', arguments: { tripId: trip.id, placeId: place.id, rating: 5 } });@@ -996,10 +984,10 @@ describe('Tool: rate_place', () => {});it('returns error for a place outside the trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const other = createTrip(testDb, user.id);- const place = createPlace(testDb, other.id, { name: 'Elsewhere' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const other = await makeTrip(orm, user.id);+ const place = await makePlace(orm, other.id, { name: 'Elsewhere' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1017,12 +1005,12 @@ describe('Tool: rate_place', () => {describe('Tool: bulk_delete_places', () => {it('deletes the trip-scoped ids, skips foreign ones and broadcasts each', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const other = createTrip(testDb, user.id);- const a = createPlace(testDb, trip.id, { name: 'A' });- const b = createPlace(testDb, trip.id, { name: 'B' });- const foreign = createPlace(testDb, other.id, { name: 'Foreign' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const other = await makeTrip(orm, user.id);+ const a = await makePlace(orm, trip.id, { name: 'A' });+ const b = await makePlace(orm, trip.id, { name: 'B' });+ const foreign = await makePlace(orm, other.id, { name: 'Foreign' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1039,10 +1027,10 @@ describe('Tool: bulk_delete_places', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const place = createPlace(testDb, trip.id, { name: 'Theirs' });+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const place = await makePlace(orm, trip.id, { name: 'Theirs' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1060,10 +1048,10 @@ describe('Tool: bulk_delete_places', () => {describe('Resource: trek://trips/{tripId}/places', () => {it('returns all places for a trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- createPlace(testDb, trip.id, { name: 'Eiffel Tower' });- createPlace(testDb, trip.id, { name: 'Louvre' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await makePlace(orm, trip.id, { name: 'Eiffel Tower' });+ await makePlace(orm, trip.id, { name: 'Louvre' });await withHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/places` });@@ -1081,9 +1069,9 @@ describe('Resource: trek://trips/{tripId}/places', () => {// resource this was moved from, so it stays untested here.it('returns access denied for unauthorized trip', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/places` });@@ -1099,8 +1087,8 @@ describe('Resource: trek://trips/{tripId}/places', () => {describe('Tool: import_places_from_url', () => {it('imports a google list, broadcasts each place and reports the count', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const spy = vi.spyOn(PlacesService.prototype, 'importGoogleList').mockResolvedValue({places: [{ id: 1, name: 'A' },@@ -1129,8 +1117,8 @@ describe('Tool: import_places_from_url', () => {it('sends a directions link to the directions importer, the same way the REST route does', async () => {// The parity that matters here is not the wire shape but the dispatch: a pasted// route has to reach the same importer through the tool as through the box.- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const dir = vi.spyOn(PlacesService.prototype, 'importGoogleDirections').mockResolvedValue({places: [{ id: 7, name: 'Berlin' }] as never,listName: 'Berlin \u2192 Prague',@@ -1153,8 +1141,8 @@ describe('Tool: import_places_from_url', () => {});it("surfaces the naver importer's refusal as a tool error", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const spy = vi.spyOn(PlacesService.prototype, 'importNaverList').mockRejectedValue(new DomainError(400, 'List is empty or could not be read'));@@ -1173,8 +1161,8 @@ describe('Tool: import_places_from_url', () => {// enrichImportedList guards on `opts?.enrich && opts.userId`, so without the// third argument the enrichment branch was structurally unreachable (#38).it('passes enrich and the calling user through to the google importer', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const spy = vi.spyOn(PlacesService.prototype, 'importGoogleList').mockResolvedValue({places: [],listName: 'Weekend',@@ -1192,8 +1180,8 @@ describe('Tool: import_places_from_url', () => {});it('passes enrich through to the naver importer too', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const spy = vi.spyOn(PlacesService.prototype, 'importNaverList').mockResolvedValue({places: [],listName: 'Seoul',@@ -1211,8 +1199,8 @@ describe('Tool: import_places_from_url', () => {});it('refuses a non-boolean enrich', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const spy = vi.spyOn(PlacesService.prototype, 'importGoogleList');await withHarness(user.id, async (h) => {@@ -1227,9 +1215,9 @@ describe('Tool: import_places_from_url', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'import_places_from_url',@@ -1246,9 +1234,9 @@ describe('Tool: import_places_from_url', () => {describe('Tool: export_trip_gpx', () => {it('writes the trip places as waypoints and names the file after the trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id, { title: 'Paris Weekend' });- createPlace(testDb, trip.id, { name: 'Eiffel Tower', lat: 48.8584, lng: 2.2945 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id, { title: 'Paris Weekend' });+ await makePlace(orm, trip.id, { name: 'Eiffel Tower', lat: 48.8584, lng: 2.2945 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'export_trip_gpx', arguments: { tripId: trip.id } });@@ -1263,9 +1251,9 @@ describe('Tool: export_trip_gpx', () => {// Same gpxFilename as the REST route (#2165): the title's script survives in// the filename now — the header folding is the controller's job, not ours.it('keeps a non-ASCII trip title in the filename', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id, { title: '沖縄 4泊5日' });- createPlace(testDb, trip.id, { name: '首里城', lat: 26.217, lng: 127.719 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id, { title: '沖縄 4泊5日' });+ await makePlace(orm, trip.id, { name: '首里城', lat: 26.217, lng: 127.719 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'export_trip_gpx', arguments: { tripId: trip.id } });@@ -1276,13 +1264,13 @@ describe('Tool: export_trip_gpx', () => {});it('writes each planned day as a route through its stops in order', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id, { title: 'Paris Weekend' });- const first = createPlace(testDb, trip.id, { name: 'Louvre', lat: 48.8606, lng: 2.3376 });- const second = createPlace(testDb, trip.id, { name: 'Notre Dame', lat: 48.853, lng: 2.3499 });- const day = createDay(testDb, trip.id);- createDayAssignment(testDb, day.id, first.id);- createDayAssignment(testDb, day.id, second.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id, { title: 'Paris Weekend' });+ const first = await makePlace(orm, trip.id, { name: 'Louvre', lat: 48.8606, lng: 2.3376 });+ const second = await makePlace(orm, trip.id, { name: 'Notre Dame', lat: 48.853, lng: 2.3499 });+ const day = await makeDay(orm, trip.id);+ await makeDayAssignment(orm, day.id, first.id);+ await makeDayAssignment(orm, day.id, second.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'export_trip_gpx', arguments: { tripId: trip.id } });@@ -1293,13 +1281,13 @@ describe('Tool: export_trip_gpx', () => {});it('honours the three selection flags', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id, { title: 'Paris Weekend' });- const first = createPlace(testDb, trip.id, { name: 'Louvre', lat: 48.8606, lng: 2.3376 });- const second = createPlace(testDb, trip.id, { name: 'Notre Dame', lat: 48.853, lng: 2.3499 });- const day = createDay(testDb, trip.id);- createDayAssignment(testDb, day.id, first.id);- createDayAssignment(testDb, day.id, second.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id, { title: 'Paris Weekend' });+ const first = await makePlace(orm, trip.id, { name: 'Louvre', lat: 48.8606, lng: 2.3376 });+ const second = await makePlace(orm, trip.id, { name: 'Notre Dame', lat: 48.853, lng: 2.3499 });+ const day = await makeDay(orm, trip.id);+ await makeDayAssignment(orm, day.id, first.id);+ await makeDayAssignment(orm, day.id, second.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1313,9 +1301,9 @@ describe('Tool: export_trip_gpx', () => {});it('errors when every export type is switched off', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id, { title: 'Paris Weekend' });- createPlace(testDb, trip.id, { name: 'Eiffel Tower' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id, { title: 'Paris Weekend' });+ await makePlace(orm, trip.id, { name: 'Eiffel Tower' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1329,8 +1317,8 @@ describe('Tool: export_trip_gpx', () => {// An empty document imports as nothing on the other end, so say so instead.it('errors when the trip has nothing to write', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id, { title: 'Empty' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id, { title: 'Empty' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'export_trip_gpx', arguments: { tripId: trip.id } });@@ -1340,10 +1328,10 @@ describe('Tool: export_trip_gpx', () => {});it('returns access denied for a non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- createPlace(testDb, trip.id, { name: 'Theirs' });+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ await makePlace(orm, trip.id, { name: 'Theirs' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'export_trip_gpx', arguments: { tripId: trip.id } });@@ -1358,9 +1346,9 @@ describe('Tool: export_trip_gpx', () => {describe('Tool: export_trip_kml', () => {it('writes the places as pins and names the file after the trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id, { title: 'Paris Weekend' });- createPlace(testDb, trip.id, { name: 'Eiffel Tower', lat: 48.8584, lng: 2.2945 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id, { title: 'Paris Weekend' });+ await makePlace(orm, trip.id, { name: 'Eiffel Tower', lat: 48.8584, lng: 2.2945 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'export_trip_kml', arguments: { tripId: trip.id } });@@ -1372,11 +1360,11 @@ describe('Tool: export_trip_kml', () => {});it('errors when no place has coordinates, and for a non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const empty = createTrip(testDb, user.id, { title: 'Empty' });- const theirs = createTrip(testDb, other.id);- createPlace(testDb, theirs.id, { name: 'Theirs', lat: 1, lng: 1 });+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const empty = await makeTrip(orm, user.id, { title: 'Empty' });+ const theirs = await makeTrip(orm, other.id);+ await makePlace(orm, theirs.id, { name: 'Theirs', lat: 1, lng: 1 });await withHarness(user.id, async (h) => {const nothing = await h.client.callTool({ name: 'export_trip_kml', arguments: { tripId: empty.id } });@@ -1394,8 +1382,8 @@ describe('Tool: export_trip_kml', () => {describe('Tool: create_and_assign_place (failure paths)', () => {it('reports a missing day without writing the place', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1409,9 +1397,9 @@ describe('Tool: create_and_assign_place (failure paths)', () => {});it('rolls the transaction back and reports failure when the place write throws', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const day = createDay(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const day = await makeDay(orm, trip.id);const spy = vi.spyOn(PlacesService.prototype, 'create').mockImplementation(() => {throw new Error('db exploded');});@@ -1451,14 +1439,14 @@ async function seedSkeleton(journeyId: number, tripId: number, placeId: number,describe('journey hooks on the MCP delete paths', () => {it("delete_place leaves a foreign trip's journey skeleton alone", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const other = createTrip(testDb, user.id);- const journey = createJourney(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const other = await makeTrip(orm, user.id);+ const journey = await makeJourney(orm, user.id);await linkJourney(journey.id, other.id);- const foreign = createPlace(testDb, other.id, { name: 'Theirs' });- const day = createDay(testDb, other.id);- createDayAssignment(testDb, day.id, foreign.id);+ const foreign = await makePlace(orm, other.id, { name: 'Theirs' });+ const day = await makeDay(orm, other.id);+ await makeDayAssignment(orm, day.id, foreign.id);await seedSkeleton(journey.id, other.id, foreign.id, user.id, 'Theirs');expect(await skeletonFor(journey.id, foreign.id)).not.toBeNull();@@ -1480,13 +1468,13 @@ describe('journey hooks on the MCP delete paths', () => {// the entry survived as an orphan instead of being removed. Asserting on the// entry count, not on source_place_id, is what tells the two apart.it('bulk_delete_places detaches the skeletons before the rows go', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const journey = createJourney(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const journey = await makeJourney(orm, user.id);await linkJourney(journey.id, trip.id);- const place = createPlace(testDb, trip.id, { name: 'Doomed' });- const day = createDay(testDb, trip.id);- createDayAssignment(testDb, day.id, place.id);+ const place = await makePlace(orm, trip.id, { name: 'Doomed' });+ const day = await makeDay(orm, trip.id);+ await makeDayAssignment(orm, day.id, place.id);await seedSkeleton(journey.id, trip.id, place.id, user.id, 'Doomed');expect(await skeletonFor(journey.id, place.id)).not.toBeNull();@@ -1508,14 +1496,14 @@ describe('journey hooks on the MCP delete paths', () => {// trip-scoped result), so this is a guard against the scoping regressing when// the hook moved ahead of the delete — not a fix for a live bug.it("bulk_delete_places leaves a foreign trip's skeleton alone", async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const other = createTrip(testDb, user.id);- const journey = createJourney(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const other = await makeTrip(orm, user.id);+ const journey = await makeJourney(orm, user.id);await linkJourney(journey.id, other.id);- const foreign = createPlace(testDb, other.id, { name: 'Theirs' });- const day = createDay(testDb, other.id);- createDayAssignment(testDb, day.id, foreign.id);+ const foreign = await makePlace(orm, other.id, { name: 'Theirs' });+ const day = await makeDay(orm, other.id);+ await makeDayAssignment(orm, day.id, foreign.id);await seedSkeleton(journey.id, other.id, foreign.id, user.id, 'Theirs');await withHarness(user.id, async (h) => {@@ -1537,12 +1525,12 @@ describe('journey hooks on the MCP delete paths', () => {describe('journey hooks on the MCP create and update paths', () => {/** A place planned on a day of a trip with a linked journey, and the skeleton entry made from it. */async function plannedWithSkeleton(placeName: string, skeletonTitle = placeName) {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const day = createDay(testDb, trip.id);- const place = createPlace(testDb, trip.id, { name: placeName });- createDayAssignment(testDb, day.id, place.id);- const journey = createJourney(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const day = await makeDay(orm, trip.id);+ const place = await makePlace(orm, trip.id, { name: placeName });+ await makeDayAssignment(orm, day.id, place.id);+ const journey = await makeJourney(orm, user.id);await linkJourney(journey.id, trip.id);await seedSkeleton(journey.id, trip.id, place.id, user.id, skeletonTitle);return { user, trip, day, place, journey };@@ -1562,8 +1550,8 @@ describe('journey hooks on the MCP create and update paths', () => {it('MCP-PLACES-JRN-002: bulk_update_places carries a new time into the journey entry of every place', async () => {const { user, trip, day, place, journey } = await plannedWithSkeleton('Market');- const second = createPlace(testDb, trip.id, { name: 'Harbour' });- createDayAssignment(testDb, day.id, second.id);+ const second = await makePlace(orm, trip.id, { name: 'Harbour' });+ await makeDayAssignment(orm, day.id, second.id);await seedSkeleton(journey.id, trip.id, second.id, user.id, 'Harbour');await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1599,8 +1587,8 @@ describe('journey hooks on the MCP create and update paths', () => {});it('MCP-PLACES-JRN-004: create_place hands the new place to the journey hook, as POST /places does', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const hook = vi.spyOn(JourneyDomainService.prototype, 'onPlaceCreated');try {await withHarness(user.id, async (h) => {@@ -1615,8 +1603,8 @@ describe('journey hooks on the MCP create and update paths', () => {});it('MCP-PLACES-JRN-005: update_place on a missing place sends nothing and runs no journey hook', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);const hook = vi.spyOn(JourneyDomainService.prototype, 'onPlaceUpdated');broadcastMock.mockClear();try {@@ -1644,9 +1632,9 @@ describe('place tools and a website without a scheme (#2483)', () => {const websiteOf = async (placeId: number) => (await findRow(orm, Places, { id: placeId }))!.website;it('MCP-PLACES-2483-01: create_place, create_and_assign_place, update_place and bulk_update_places store https', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const day = createDay(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const day = await makeDay(orm, trip.id);await withHarness(user.id, async (h) => {const created = parseToolResult(@@ -1683,8 +1671,8 @@ describe('place tools and a website without a scheme (#2483)', () => {});it('MCP-PLACES-2483-02: a script link or another scheme is still refused and stores nothing', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {for (const website of ['javascript:alert(1)', 'mailto:[email protected]', 'Chapelle']) {@@ -1701,7 +1689,7 @@ describe('place tools and a website without a scheme (#2483)', () => {});it('MCP-PLACES-2483-03: tools/list still describes the field as a plain capped string', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await withHarness(user.id, async (h) => {const { tools } = await h.client.listTools();for (const name of ['create_place', 'create_and_assign_place', 'update_place', 'bulk_update_places']) {diff --git a/server/tests/unit/mcp/tools-plugin-pois.test.ts b/server/tests/unit/mcp/tools-plugin-pois.test.tsindex 7db7bddef..534dc1579 100644--- a/server/tests/unit/mcp/tools-plugin-pois.test.ts+++ b/server/tests/unit/mcp/tools-plugin-pois.test.ts@@ -4,24 +4,20 @@* counterparts of the GET /api/plugins feed and GET /api/plugin-pois. Both go through* PluginPoisService, so the gate, the window and the normalization are the REST ones.*/-import { db as testDb } from '../../../src/db/database';import { Plugins } from '../../../src/db/entities/Plugins.entity';import { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.service';-import { createUser } from '../../helpers/factories';import { makePlugin } from '../../helpers/factories/plugins';import { deleteRows } from '../../helpers/factories/rows';+import { makeUser } from '../../helpers/factories/users';import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';-import { resetTestDb } from '../../helpers/test-db';-import { createTestOrm, type TestOrm } from '../../helpers/test-orm';+import { resetDatabase } from '../../helpers/reset-database';+import { bootTestApp } from '../../helpers/test-app';+import { MikroORM } from '@mikro-orm/core';import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';const { pluginsEnabled } = vi.hoisted(() => ({ pluginsEnabled: vi.fn(() => true) }));-vi.mock('../../../src/db/database', async () => {- const { createSnapshotTestDb, buildDbMock } = await import('../../helpers/db-mock');- return buildDbMock(createSnapshotTestDb());-});vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));const providersOfMock = vi.spyOn(PluginHooks.prototype, 'providersOf');@@ -36,14 +32,14 @@ const trailheads = {};const bbox = { south: 47, west: 11, north: 47.5, east: 11.5 };-let orm: TestOrm;+let orm: MikroORM;beforeAll(async () => {- orm = await createTestOrm(testDb);+ orm = (await bootTestApp()).get(MikroORM);});beforeEach(async () => {- resetTestDb(testDb);+ await resetDatabase(orm);await deleteRows(orm, Plugins);await makePlugin(orm, 'trail-finder', {name: 'Trail Finder',@@ -57,8 +53,7 @@ beforeEach(async () => {});afterAll(async () => {- await orm.close();- testDb.close();+ await (await bootTestApp()).close();});async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {@@ -75,7 +70,7 @@ const search = (h: McpHarness, args: Record<string, unknown>) =>describe('Tool: list_plugin_poi_categories', () => {it('names the categories a provider answers, labelled in the requested language', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await withHarness(user.id, async (h) => {const res = await h.client.callTool({ name: 'list_plugin_poi_categories', arguments: { lang: 'de' } });expect(parseToolResult(res)).toEqual({@@ -96,7 +91,7 @@ describe('Tool: list_plugin_poi_categories', () => {});it('is empty while the plugin runtime is switched off', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);pluginsEnabled.mockReturnValue(false);await withHarness(user.id, async (h) => {const res = await h.client.callTool({ name: 'list_plugin_poi_categories', arguments: {} });@@ -107,7 +102,7 @@ describe('Tool: list_plugin_poi_categories', () => {describe('Tool: search_plugin_pois', () => {it('returns the plugin answer in the search_pois row shape, asked as the requesting user', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);categoryPoisMock.mockResolvedValue([{id: 'th-1',@@ -149,7 +144,7 @@ describe('Tool: search_plugin_pois', () => {});it('refuses an undeclared category and an inverted box without asking the plugin', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await withHarness(user.id, async (h) => {const unknown = await search(h, { pluginId: 'trail-finder', category: 'huts', bbox });expect(unknown.isError).toBe(true);@@ -165,7 +160,7 @@ describe('Tool: search_plugin_pois', () => {});it('takes the box search_pois takes and refuses an edge off the globe without asking the plugin', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await withHarness(user.id, async (h) => {const { tools } = await h.client.listTools();const bboxOf = (name: string) => tools.find((t) => t.name === name)?.inputSchema.properties?.bbox;@@ -182,7 +177,7 @@ describe('Tool: search_plugin_pois', () => {});it('turns a failing plugin into an error result', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);categoryPoisMock.mockRejectedValue(new Error('timed out'));await withHarness(user.id, async (h) => {const res = await search(h, { pluginId: 'trail-finder', category: 'trailheads', bbox });diff --git a/server/tests/unit/mcp/tools-plugin-search.test.ts b/server/tests/unit/mcp/tools-plugin-search.test.tsindex 87f3ed885..77105a670 100644--- a/server/tests/unit/mcp/tools-plugin-search.test.ts+++ b/server/tests/unit/mcp/tools-plugin-search.test.ts@@ -2,12 +2,13 @@* Unit tests for the search_places_via_plugins MCP tool (src/nest/plugins/* contributions/plugin-search.mcp.ts), the MCP counterpart of GET /api/plugin-search.*/-import { db as testDb } from '../../../src/db/database';import { PluginHooks } from '../../../src/nest/plugins/plugin-hooks.service';-import { createUser } from '../../helpers/factories';+import { makeUser } from '../../helpers/factories/users';import { FakeRealtimeService } from '../../helpers/fake-realtime';import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';-import { resetTestDb } from '../../helpers/test-db';+import { resetDatabase } from '../../helpers/reset-database';+import { bootTestApp } from '../../helpers/test-app';+import { MikroORM } from '@mikro-orm/core';import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';@@ -15,10 +16,6 @@ const { pluginsEnabled } = vi.hoisted(() => ({pluginsEnabled: vi.fn(() => true),}));-vi.mock('../../../src/db/database', async () => {- const { createSnapshotTestDb, buildDbMock } = await import('../../helpers/db-mock');- return buildDbMock(createSnapshotTestDb());-});// The admin kill switch reads live env; drive it from the test instead of the process.vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));@@ -28,16 +25,22 @@ const broadcastMock = realtime.broadcastMock;const providersOfMock = vi.spyOn(PluginHooks.prototype, 'providersOf');const searchPlacesMock = vi.spyOn(PluginHooks.prototype, 'searchPlaces');-beforeEach(() => {- resetTestDb(testDb);+let orm: MikroORM;++beforeAll(async () => {+ orm = (await bootTestApp(realtime)).get(MikroORM);+});++beforeEach(async () => {+ await resetDatabase(orm);broadcastMock.mockClear();pluginsEnabled.mockReturnValue(true);providersOfMock.mockReset().mockReturnValue([]);searchPlacesMock.mockReset().mockResolvedValue([]);});-afterAll(() => {- testDb.close();+afterAll(async () => {+ await (await bootTestApp(realtime)).close();});async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {@@ -58,7 +61,7 @@ const call = async (h: McpHarness, args: Record<string, unknown>) =>describe('Tool: search_places_via_plugins', () => {it('returns what the providers found, with the rating open data cannot carry', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);providersOfMock.mockReturnValue(['guide']);searchPlacesMock.mockResolvedValue([{ id: 'h1', name: 'Hotel Bellevue', lat: 46.5, lng: 6.6, rating: 4.6, address: 'Lakeside 1' },@@ -84,7 +87,7 @@ describe('Tool: search_places_via_plugins', () => {});it('passes the bias and the limit through, and refuses a coordinate off the globe', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);providersOfMock.mockReturnValue(['guide']);await withHarness(user.id, async (h) => {@@ -106,7 +109,7 @@ describe('Tool: search_places_via_plugins', () => {});it('answers with an empty list when no plugin provides an index, without asking one', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await withHarness(user.id, async (h) => {const payload = parseToolResult(await call(h, { query: 'hotel' })) as PlacesPayload;expect(payload.places).toEqual([]);@@ -115,7 +118,7 @@ describe('Tool: search_places_via_plugins', () => {});it('answers with an empty list while the plugin runtime is switched off', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);pluginsEnabled.mockReturnValue(false);providersOfMock.mockReturnValue(['guide']);@@ -127,7 +130,7 @@ describe('Tool: search_places_via_plugins', () => {});it('skips a provider that fails and still returns the other one', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);providersOfMock.mockReturnValue(['broken', 'guide']);searchPlacesMock.mockImplementation(async (pluginId: string) => {if (pluginId === 'broken') throw new Error('timed out');