Skip to content

armgit / TREK

Public Imported from GitHub
0

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.

test(db): run the feeds and invite, journey, leg transport mode, memories and notes MCP suites on the real database module

Maurice97a3389409f8
diff --git a/server/scripts/test-mocks-baseline.json b/server/scripts/test-mocks-baseline.json
index 965163146..147b6b20a 100644
--- a/server/scripts/test-mocks-baseline.json
+++ b/server/scripts/test-mocks-baseline.json
@@ -63,11 +63,6 @@
"tests/setup.ts": 1,
"tests/unit/auto-backup.test.ts": 1,
"tests/unit/db/database-lazy-open.test.ts": 1,
- "tests/unit/mcp/tools-feeds-invite.test.ts": 1,
- "tests/unit/mcp/tools-journey.test.ts": 1,
- "tests/unit/mcp/tools-leg-transport-mode.test.ts": 1,
- "tests/unit/mcp/tools-memories.test.ts": 1,
- "tests/unit/mcp/tools-notes.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,
diff --git a/server/tests/postgres/snapshot-suites-baseline.json b/server/tests/postgres/snapshot-suites-baseline.json
index c0c5cb871..a0f9e4dd7 100644
--- a/server/tests/postgres/snapshot-suites-baseline.json
+++ b/server/tests/postgres/snapshot-suites-baseline.json
@@ -1,9 +1,4 @@
[
- "tests/unit/mcp/tools-feeds-invite.test.ts",
- "tests/unit/mcp/tools-journey.test.ts",
- "tests/unit/mcp/tools-leg-transport-mode.test.ts",
- "tests/unit/mcp/tools-memories.test.ts",
- "tests/unit/mcp/tools-notes.test.ts",
"tests/unit/mcp/tools-notifications.test.ts",
"tests/unit/mcp/tools-packing-advanced.test.ts",
"tests/unit/mcp/tools-packing.test.ts",
diff --git a/server/tests/unit/mcp/tools-feeds-invite.test.ts b/server/tests/unit/mcp/tools-feeds-invite.test.ts
index 6a9cbb5a1..d684cec9f 100644
--- a/server/tests/unit/mcp/tools-feeds-invite.test.ts
+++ b/server/tests/unit/mcp/tools-feeds-invite.test.ts
@@ -7,25 +7,21 @@
* interesting part: trip access before permission, share_manage on reads as
* well as writes, and demo mode refused on every write.
*/
-import { db as testDb } from '../../../src/db/database';
import { AppSettings } from '../../../src/db/entities/AppSettings.entity';
import { AuditLog } from '../../../src/db/entities/AuditLog.entity';
import { TripInviteTokens } from '../../../src/db/entities/TripInviteTokens.entity';
import { Trips } from '../../../src/db/entities/Trips.entity';
import { Users } from '../../../src/db/entities/Users.entity';
import { invalidatePermissionsCache } from '../../../src/nest/permissions/permissions-cache';
-import { createUser, createTrip, addTripMember } from '../../helpers/factories';
import { countRows, deleteRows, findRow, insertRow, updateRows } from '../../helpers/factories/rows';
+import { addTripMember, makeTrip } from '../../helpers/factories/trips';
+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 { 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 BASE = 'https://trek.example';
@@ -42,10 +38,10 @@ function textOf(result: ToolResult): string {
return content.find((c) => c.type === 'text')?.text ?? '';
}
-let orm: TestOrm;
+let orm: MikroORM;
beforeAll(async () => {
- orm = await createTestOrm(testDb);
+ orm = (await bootTestApp()).get(MikroORM);
});
async function tripToken(tripId: number): Promise<string | null> {
@@ -75,12 +71,12 @@ interface InviteResult {
}
beforeEach(async () => {
- resetTestDb(testDb);
+ await resetDatabase(orm);
// trip_invite_tokens is not in the shared helper's RESET_TABLES, and trip ids
// restart after a DELETE-based reset, so a leftover row would attach itself
// to the next test's trip.
await deleteRows(orm, TripInviteTokens);
- // The permission levels are cached in module state that resetTestDb knows
+ // The permission levels are cached in module state that resetDatabase knows
// nothing about, so the one test that lowers share_manage would otherwise
// keep the lowered level alive for every test after it.
await invalidatePermissionsCache();
@@ -90,8 +86,7 @@ beforeEach(async () => {
afterAll(async () => {
delete process.env.APP_URL;
- await orm.close();
- testDb.close();
+ await (await bootTestApp()).close();
});
async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {
@@ -109,8 +104,8 @@ async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>)
describe('Tool: get_trip_calendar_feed', () => {
it('answers null while the feed is off and the subscribable URL once it is on', 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 off = payload<FeedResult>(
await h.client.callTool({ name: 'get_trip_calendar_feed', arguments: { tripId: trip.id } }),
@@ -126,10 +121,10 @@ describe('Tool: get_trip_calendar_feed', () => {
});
it('reads the feed of a trip the user is a member of once share_manage is lowered to trip_member', async () => {
- const { user: owner } = createUser(testDb);
- const { user: member } = createUser(testDb);
- const trip = createTrip(testDb, owner.id);
- addTripMember(testDb, trip.id, member.id);
+ const { user: owner } = await makeUser(orm);
+ const { user: member } = await makeUser(orm);
+ const trip = await makeTrip(orm, owner.id);
+ await addTripMember(orm, trip.id, member.id);
await insertRow(orm, AppSettings, { key: 'perm_share_manage', value: 'trip_member' });
await withHarness(owner.id, async (h) => {
await h.client.callTool({ name: 'enable_trip_calendar_feed', arguments: { tripId: trip.id } });
@@ -145,8 +140,8 @@ describe('Tool: get_trip_calendar_feed', () => {
describe('Tool: enable_trip_calendar_feed', () => {
it('mints one token and hands back the same URL on a second call', 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 first = payload<FeedResult>(
await h.client.callTool({ name: 'enable_trip_calendar_feed', arguments: { tripId: trip.id } }),
@@ -166,8 +161,8 @@ describe('Tool: enable_trip_calendar_feed', () => {
describe('Tool: rotate_trip_calendar_feed', () => {
it('replaces the token so the old URL stops resolving', 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: 'enable_trip_calendar_feed', arguments: { tripId: trip.id } });
const before = await tripToken(trip.id);
@@ -183,8 +178,8 @@ describe('Tool: rotate_trip_calendar_feed', () => {
describe('Tool: disable_trip_calendar_feed', () => {
it('clears the token and answers a null URL', 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: 'enable_trip_calendar_feed', arguments: { tripId: trip.id } });
const result = payload<FeedResult>(
@@ -205,9 +200,9 @@ describe('trip calendar feed gates', () => {
];
it.each(TRIP_FEED_TOOLS)('%s refuses a trip the user cannot reach', async (name) => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const foreign = createTrip(testDb, other.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const foreign = await makeTrip(orm, other.id);
await updateRows(orm, Trips, { id: foreign.id }, { feed_token: 'foreign-token' });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name, arguments: { tripId: foreign.id } });
@@ -220,7 +215,7 @@ describe('trip calendar feed gates', () => {
});
it.each(TRIP_FEED_TOOLS)('%s refuses a trip id that does not exist', async (name) => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name, arguments: { tripId: 987654 } });
expect(result.isError).toBe(true);
@@ -229,10 +224,10 @@ describe('trip calendar feed gates', () => {
});
it.each(TRIP_FEED_TOOLS)('%s refuses a member without share_manage', async (name) => {
- const { user: owner } = createUser(testDb);
- const { user: member } = createUser(testDb);
- const trip = createTrip(testDb, owner.id);
- addTripMember(testDb, trip.id, member.id);
+ const { user: owner } = await makeUser(orm);
+ const { user: member } = await makeUser(orm);
+ const trip = await makeTrip(orm, owner.id);
+ await addTripMember(orm, trip.id, member.id);
await updateRows(orm, Trips, { id: trip.id }, { feed_token: 'owner-token' });
await withHarness(member.id, async (h) => {
const result = await h.client.callTool({ name, arguments: { tripId: trip.id } });
@@ -246,8 +241,8 @@ describe('trip calendar feed gates', () => {
'%s refuses a demo account',
async (name) => {
process.env.DEMO_MODE = 'true';
- const { user: demo } = createUser(testDb, { email: '[email protected]' });
- const trip = createTrip(testDb, demo.id);
+ const { user: demo } = await makeUser(orm, { email: '[email protected]' });
+ const trip = await makeTrip(orm, demo.id);
await updateRows(orm, Trips, { id: trip.id }, { feed_token: 'demo-token' });
await withHarness(demo.id, async (h) => {
const result = await h.client.callTool({ name, arguments: { tripId: trip.id } });
@@ -265,7 +260,7 @@ describe('trip calendar feed gates', () => {
describe('Tool: get_all_trips_calendar_feed', () => {
it('answers null while the feed is off and the user URL once it is on', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const off = payload<FeedResult>(await h.client.callTool({ name: 'get_all_trips_calendar_feed', arguments: {} }));
expect(off.feed_url).toBeNull();
@@ -279,8 +274,8 @@ describe('Tool: get_all_trips_calendar_feed', () => {
describe('Tool: enable_all_trips_calendar_feed', () => {
it('mints the calling user their own token and leaves everybody else alone', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const first = payload<FeedResult>(
await h.client.callTool({ name: 'enable_all_trips_calendar_feed', arguments: {} }),
@@ -300,7 +295,7 @@ describe('Tool: enable_all_trips_calendar_feed', () => {
describe('Tool: rotate_all_trips_calendar_feed', () => {
it('replaces the token so the old URL stops resolving', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
await h.client.callTool({ name: 'enable_all_trips_calendar_feed', arguments: {} });
const before = await userToken(user.id);
@@ -316,7 +311,7 @@ describe('Tool: rotate_all_trips_calendar_feed', () => {
describe('Tool: disable_all_trips_calendar_feed', () => {
it('clears the token and answers a null URL', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
await h.client.callTool({ name: 'enable_all_trips_calendar_feed', arguments: {} });
const result = payload<FeedResult>(
@@ -330,7 +325,7 @@ describe('Tool: disable_all_trips_calendar_feed', () => {
describe('calendar feed tools, the lean variant (#2602)', () => {
it('tell a model how to ask for a feed without the per-day summaries', 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 [
@@ -352,7 +347,7 @@ describe('all-trips calendar feed gates', () => {
'%s refuses a demo account',
async (name) => {
process.env.DEMO_MODE = 'true';
- const { user: demo } = createUser(testDb, { email: '[email protected]' });
+ const { user: demo } = await makeUser(orm, { email: '[email protected]' });
await updateRows(orm, Users, { id: demo.id }, { feed_token: 'demo-user-token' });
await withHarness(demo.id, async (h) => {
const result = await h.client.callTool({ name, arguments: {} });
@@ -370,8 +365,8 @@ describe('all-trips calendar feed gates', () => {
describe('Tool: get_trip_invite_link', () => {
it('answers null without a link, then the token and the join URL', 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 none = payload<InviteResult>(
await h.client.callTool({ name: 'get_trip_invite_link', arguments: { tripId: trip.id } }),
@@ -391,8 +386,8 @@ describe('Tool: get_trip_invite_link', () => {
describe('Tool: create_trip_invite_link', () => {
it('stores the token against the trip and audits who minted it', 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 created = payload<InviteResult>(
await h.client.callTool({ name: 'create_trip_invite_link', arguments: { tripId: trip.id } }),
@@ -409,9 +404,9 @@ describe('Tool: create_trip_invite_link', () => {
});
it('takes an expiry as a number or as the digits-only string the contract allows', async () => {
- const { user } = createUser(testDb);
- const numeric = createTrip(testDb, user.id);
- const stringy = createTrip(testDb, user.id);
+ const { user } = await makeUser(orm);
+ const numeric = await makeTrip(orm, user.id);
+ const stringy = await makeTrip(orm, user.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'create_trip_invite_link',
@@ -431,9 +426,9 @@ describe('Tool: create_trip_invite_link', () => {
});
it('reads a non-positive or empty expiry as no expiry at all', async () => {
- const { user } = createUser(testDb);
- const zero = createTrip(testDb, user.id);
- const blank = createTrip(testDb, user.id);
+ const { user } = await makeUser(orm);
+ const zero = await makeTrip(orm, user.id);
+ const blank = await makeTrip(orm, user.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({ name: 'create_trip_invite_link', arguments: { tripId: zero.id, expires_in_days: 0 } });
await h.client.callTool({
@@ -446,8 +441,8 @@ describe('Tool: create_trip_invite_link', () => {
});
it('rejects an expiry the shared contract does not admit', 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_trip_invite_link',
@@ -459,8 +454,8 @@ describe('Tool: create_trip_invite_link', () => {
});
it('rotates in place: a second call replaces the token and keeps one row', 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 first = payload<InviteResult>(
await h.client.callTool({ name: 'create_trip_invite_link', arguments: { tripId: trip.id } }),
@@ -477,8 +472,8 @@ describe('Tool: create_trip_invite_link', () => {
describe('Tool: delete_trip_invite_link', () => {
it('removes the link and audits the revocation', 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_trip_invite_link', arguments: { tripId: trip.id } });
const result = payload<{ success: boolean }>(
@@ -496,9 +491,9 @@ describe('trip invite link gates', () => {
const INVITE_TOOLS = ['get_trip_invite_link', 'create_trip_invite_link', 'delete_trip_invite_link'];
it.each(INVITE_TOOLS)('%s refuses a trip the user cannot reach', async (name) => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const foreign = createTrip(testDb, other.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const foreign = await makeTrip(orm, other.id);
await withHarness(other.id, async (h) => {
await h.client.callTool({ name: 'create_trip_invite_link', arguments: { tripId: foreign.id } });
});
@@ -512,7 +507,7 @@ describe('trip invite link gates', () => {
});
it.each(INVITE_TOOLS)('%s refuses a trip id that does not exist', async (name) => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name, arguments: { tripId: 987654 } });
expect(result.isError).toBe(true);
@@ -521,10 +516,10 @@ describe('trip invite link gates', () => {
});
it.each(INVITE_TOOLS)('%s refuses a member without share_manage', async (name) => {
- const { user: owner } = createUser(testDb);
- const { user: member } = createUser(testDb);
- const trip = createTrip(testDb, owner.id);
- addTripMember(testDb, trip.id, member.id);
+ const { user: owner } = await makeUser(orm);
+ const { user: member } = await makeUser(orm);
+ const trip = await makeTrip(orm, owner.id);
+ await addTripMember(orm, trip.id, member.id);
await withHarness(owner.id, async (h) => {
await h.client.callTool({ name: 'create_trip_invite_link', arguments: { tripId: trip.id } });
});
@@ -539,8 +534,8 @@ describe('trip invite link gates', () => {
it.each(['create_trip_invite_link', 'delete_trip_invite_link'])('%s refuses a demo account', async (name) => {
process.env.DEMO_MODE = 'true';
- const { user: demo } = createUser(testDb, { email: '[email protected]' });
- const trip = createTrip(testDb, demo.id);
+ const { user: demo } = await makeUser(orm, { email: '[email protected]' });
+ const trip = await makeTrip(orm, demo.id);
await insertRow(orm, TripInviteTokens, { trip: trip.id, token: 'seeded-token', createdByRef: demo.id });
await withHarness(demo.id, async (h) => {
const result = await h.client.callTool({ name, arguments: { tripId: trip.id } });
diff --git a/server/tests/unit/mcp/tools-journey.test.ts b/server/tests/unit/mcp/tools-journey.test.ts
index 65f297ecc..fad45ed63 100644
--- a/server/tests/unit/mcp/tools-journey.test.ts
+++ b/server/tests/unit/mcp/tools-journey.test.ts
@@ -4,28 +4,24 @@
* and create_journey_entry returns the enriched entry (parsed tags, photos array).
*/
import { ADDON_IDS } from '../../../src/addons';
-import { db as testDb } from '../../../src/db/database';
import { JourneyEntries } from '../../../src/db/entities/JourneyEntries.entity';
import { JourneyEntryPhotos } from '../../../src/db/entities/JourneyEntryPhotos.entity';
import { JourneyPhotos } from '../../../src/db/entities/JourneyPhotos.entity';
import { Journeys } from '../../../src/db/entities/Journeys.entity';
import { TrekPhotos } from '../../../src/db/entities/TrekPhotos.entity';
-import { createUser, createTrip } from '../../helpers/factories';
import { addJourneyContributor } from '../../helpers/factories/journeys';
import { createRow, findRow, insertRow } from '../../helpers/factories/rows';
+import { setAddonEnabled } from '../../helpers/factories/settings';
+import { 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 { setAddonEnabled } 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());
-});
-
/*
* get_journey_stats resolves a country per stop. The real lookup loads and
* indexes 4MB of gzipped admin-0 boundaries on first call, which is Atlas'
@@ -50,24 +46,23 @@ realtime.broadcastToUserMock.mockImplementation((...args) =>
broadcastMock(...(args as unknown as Parameters<typeof broadcastMock>)),
);
-beforeEach(() => {
- resetTestDb(testDb);
+beforeEach(async () => {
+ await resetDatabase(orm);
// The `when:` gate reads the injected AddonsService, so the toggle is the row
// the admin panel writes — and this addon ships disabled by default.
- setAddonEnabled(testDb, ADDON_IDS.JOURNEY, true);
+ await setAddonEnabled(orm, ADDON_IDS.JOURNEY, true);
broadcastMock.mockClear();
delete process.env.DEMO_MODE;
});
-let orm: TestOrm;
+let orm: MikroORM;
beforeAll(async () => {
- orm = await createTestOrm(testDb);
+ orm = (await bootTestApp(realtime)).get(MikroORM);
});
afterAll(async () => {
- await orm.close();
- testDb.close();
+ await (await bootTestApp(realtime)).close();
});
async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {
@@ -81,7 +76,7 @@ async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>)
describe('Tool: create_journey', () => {
it('returns the fully-hydrated journey, not a bare row', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'create_journey',
@@ -101,7 +96,7 @@ describe('Tool: create_journey', () => {
describe('Tool: create_journey_entry', () => {
it('returns the enriched entry with parsed tags and a photos array', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = (
parseToolResult(
@@ -127,7 +122,7 @@ describe('Tool: create_journey_entry', () => {
describe('Tool: update_journey_entry', () => {
it('returns the enriched entry (parsed tags, photos array)', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = (
parseToolResult(
@@ -157,7 +152,7 @@ describe('Tool: update_journey_entry', () => {
});
it('creates a draft and publishes it, as the REST route does (#696)', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = (
parseToolResult(await h.client.callTool({ name: 'create_journey', arguments: { title: 'J' } })) as any
@@ -186,7 +181,7 @@ describe('Tool: update_journey_entry', () => {
describe('Tool: update_journey_preferences', () => {
it('returns the updated preference, not { success }', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = (
parseToolResult(
@@ -215,7 +210,7 @@ describe('Tool: update_journey_preferences', () => {
/** A journey owned by someone else — every access check must refuse it. */
async function foreignJourney() {
- const { user: other } = createUser(testDb);
+ const { user: other } = await makeUser(orm);
const j = await createRow(orm, Journeys, {
user: other.id,
title: 'Not yours',
@@ -239,7 +234,7 @@ async function seedJourney(h: McpHarness, title = 'J') {
describe('journey read tools', () => {
it('list_journeys returns the caller-visible journeys', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
await seedJourney(h, 'Alpha');
const data = parseToolResult(await h.client.callTool({ name: 'list_journeys', arguments: {} })) as any;
@@ -248,7 +243,7 @@ describe('journey read tools', () => {
});
it('get_journey hydrates entries, contributors and trips', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const data = parseToolResult(
@@ -263,7 +258,7 @@ describe('journey read tools', () => {
});
it('get_journey refuses a journey the caller cannot see', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'get_journey', arguments: { journeyId } });
@@ -272,7 +267,7 @@ describe('journey read tools', () => {
});
it('list_journey_entries returns the entries', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
await h.client.callTool({
@@ -290,7 +285,7 @@ describe('journey read tools', () => {
});
it('list_journey_entries refuses a foreign journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'list_journey_entries', arguments: { journeyId } });
@@ -299,7 +294,7 @@ describe('journey read tools', () => {
});
it('MCP-JRN-ENTRY-001: list_journey_entries keeps the days from/to name and names its journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h, 'Berlin 2026');
const days = [
@@ -330,7 +325,7 @@ describe('journey read tools', () => {
});
it('MCP-JRN-ENTRY-002: list_journey_entries refuses a day that is no calendar day', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const result = await h.client.callTool({
@@ -342,7 +337,7 @@ describe('journey read tools', () => {
});
it('MCP-JRN-ENTRY-003: get_journey_entry answers one entry with its photos and its journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h, 'Japan');
const created = parseToolResult(
@@ -362,8 +357,8 @@ describe('journey read tools', () => {
});
it('MCP-JRN-ENTRY-004: get_journey_entry does not show an entry of a journal the caller cannot see', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
let entryId = 0;
await withHarness(other.id, async (h) => {
const journey = await seedJourney(h, 'Private');
@@ -385,7 +380,7 @@ describe('journey read tools', () => {
});
it('list_journey_contributors returns the contributor rows', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const data = parseToolResult(
@@ -399,7 +394,7 @@ describe('journey read tools', () => {
});
it('list_journey_contributors refuses a foreign journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'list_journey_contributors', arguments: { journeyId } });
@@ -408,7 +403,7 @@ describe('journey read tools', () => {
});
it('get_journey_suggestions and list_journey_available_trips answer with arrays', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const s = parseToolResult(await h.client.callTool({ name: 'get_journey_suggestions', arguments: {} })) as any;
const t = parseToolResult(
@@ -422,7 +417,7 @@ describe('journey read tools', () => {
describe('journey write tools', () => {
it('update_journey applies the change and refuses a foreign journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
@@ -439,7 +434,7 @@ describe('journey write tools', () => {
});
it('update_journey switches the preparation of recorded days on and refuses a value that is no boolean', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const updated = parseToolResult(
@@ -458,7 +453,7 @@ describe('journey write tools', () => {
});
it('update_journey answers what the changed settings held before, flags as booleans, and only those', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h, 'Before');
const updated = parseToolResult(
@@ -478,7 +473,7 @@ describe('journey write tools', () => {
});
it('update_journey takes the trip tracks and the cover gradient the REST route takes, and clears a subtitle', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const updated = parseToolResult(
@@ -506,7 +501,7 @@ describe('journey write tools', () => {
});
it('delete_journey removes it and refuses a foreign journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
@@ -523,8 +518,8 @@ describe('journey write tools', () => {
});
it('add_journey_trip links a trip, remove_journey_trip unlinks it', 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 journey = await seedJourney(h);
const added = parseToolResult(
@@ -545,8 +540,8 @@ describe('journey write tools', () => {
});
it('add_journey_trip refuses a foreign journey; remove_journey_trip is idempotent but refuses one', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
@@ -582,7 +577,7 @@ describe('journey write tools', () => {
});
it('create_journey_entry refuses a foreign journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
@@ -594,7 +589,7 @@ describe('journey write tools', () => {
});
it('update_journey_entry and delete_journey_entry refuse an unknown entry', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
expect(
(
@@ -616,7 +611,7 @@ describe('journey write tools', () => {
});
it('delete_journey_entry removes an owned entry', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = (
@@ -638,7 +633,7 @@ describe('journey write tools', () => {
});
it('reorder_journey_entries reorders, and rejects IDs from outside the journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const a = (
@@ -678,7 +673,7 @@ describe('journey write tools', () => {
});
it('reorder_journey_entry_photos refuses ids that are not the entry photos (#824)', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = (
@@ -701,8 +696,8 @@ describe('journey write tools', () => {
});
it('contributor tools add, re-role and remove; each refuses a foreign journey', async () => {
- const { user } = createUser(testDb);
- const { user: guest } = createUser(testDb);
+ const { user } = await makeUser(orm);
+ const { user: guest } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
@@ -759,7 +754,7 @@ describe('journey write tools', () => {
});
it('update_journey_preferences refuses a foreign journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
@@ -824,7 +819,7 @@ async function seedGalleryPhoto(journeyId: number, entryId?: number): Promise<nu
describe('journey photo tools', () => {
it('link_journey_photo and unlink_journey_photo put a gallery photo on an entry and take it off, telling the tabs', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id, { title: 'Vik' });
@@ -858,7 +853,7 @@ describe('journey photo tools', () => {
});
it('move_journey_photos moves photos between entries of a journey and refuses one of another journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const from = await seedEntry(h, journey.id, { title: 'Vik' });
@@ -882,7 +877,7 @@ describe('journey photo tools', () => {
});
it('set_journey_photo_caption answers the caption it replaced and refuses a photo of another journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const other = await seedJourney(h, 'Other');
@@ -905,7 +900,7 @@ describe('journey photo tools', () => {
describe('journey entry fields', () => {
it('create_journey_entry persists the place, coordinates, weather, tags, verdict, visibility and type', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id, {
@@ -933,7 +928,7 @@ describe('journey entry fields', () => {
});
it('create_journey_entry accepts a one-sided verdict and fills the other side in', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id, { pros_cons: { pros: ['cheap'] } });
@@ -942,7 +937,7 @@ describe('journey entry fields', () => {
});
it('create_journey_entry defaults to a private entry when neither is given', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const row = await entryRow((await seedEntry(h, journey.id)).id);
@@ -952,7 +947,7 @@ describe('journey entry fields', () => {
});
it('create_journey_entry refuses coordinates off the globe and an unknown visibility', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
for (const bad of [{ location_lat: 91 }, { location_lng: -181 }, { visibility: 'friends' }]) {
@@ -969,7 +964,7 @@ describe('journey entry fields', () => {
});
it('update_journey_entry corrects the place and its coordinates', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id, {
@@ -996,7 +991,7 @@ describe('journey entry fields', () => {
});
it('update_journey_entry sets weather, tags, the verdict, visibility and sort_order', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id);
@@ -1028,7 +1023,7 @@ describe('journey entry fields', () => {
});
it('update_journey_entry promotes a trip-derived skeleton to a real entry', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id, { type: 'skeleton', title: 'Blue Lagoon' });
@@ -1040,7 +1035,7 @@ describe('journey entry fields', () => {
});
it('update_journey_entry clears a field on null and leaves the omitted ones alone', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id, {
@@ -1081,7 +1076,7 @@ describe('journey entry fields', () => {
});
it('update_journey_entry answers what the named fields held before, decoded, and nothing for the rest', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id, {
@@ -1112,7 +1107,7 @@ describe('journey entry fields', () => {
* does too, and get_journey_stats is where the effect shows.
*/
it('update_journey_entry switches a stop out of the figures and back', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const airport = await seedEntry(h, journey.id, {
@@ -1165,7 +1160,7 @@ describe('journey entry fields', () => {
});
it('update_journey_entry refuses a stats_excluded that is not a boolean', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id);
@@ -1182,7 +1177,7 @@ describe('journey entry fields', () => {
});
it('update_journey_entry refuses an unknown visibility and an out-of-range longitude', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
const entry = await seedEntry(h, journey.id);
@@ -1223,7 +1218,7 @@ describe('Tool: get_journey_stats', () => {
}
it('answers with the distance, days and countries get_journey does not carry', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await twoStopJourney(h);
@@ -1255,7 +1250,7 @@ describe('Tool: get_journey_stats', () => {
});
it('leaves the route out unless include_route asks for it', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await twoStopJourney(h);
@@ -1280,7 +1275,7 @@ describe('Tool: get_journey_stats', () => {
});
it('refuses a journey the caller cannot see', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
expect(
@@ -1297,7 +1292,7 @@ describe('Tool: get_journey_stats', () => {
describe('journey share-link tools', () => {
it('creates, reads and revokes the link', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
// No link yet — the tool answers with a null shareLink, not an error.
@@ -1336,7 +1331,7 @@ describe('journey share-link tools', () => {
});
it('passes the share flags through, and an omitted flag keeps its value', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await seedJourney(h);
await h.client.callTool({
@@ -1358,8 +1353,8 @@ describe('journey share-link tools', () => {
});
it('get_journey_share_link is owner-only, like create and delete', async () => {
- const { user: owner } = createUser(testDb);
- const { user: guest } = createUser(testDb);
+ const { user: owner } = await makeUser(orm);
+ const { user: guest } = await makeUser(orm);
let journeyId = 0;
await withHarness(owner.id, async (h) => {
const journey = await seedJourney(h);
@@ -1382,7 +1377,7 @@ describe('journey share-link tools', () => {
});
it('every share tool refuses a foreign journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const { journeyId } = await foreignJourney();
await withHarness(user.id, async (h) => {
for (const name of ['get_journey_share_link', 'create_journey_share_link', 'delete_journey_share_link']) {
@@ -1415,7 +1410,7 @@ describe('demo mode', () => {
it.each(WRITES)('%s is blocked for a demo user', async (name, args) => {
process.env.DEMO_MODE = 'true';
- const { user } = createUser(testDb, { email: '[email protected]' });
+ const { user } = await makeUser(orm, { email: '[email protected]' });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name, arguments: args });
expect(result.isError).toBe(true);
@@ -1424,7 +1419,7 @@ describe('demo mode', () => {
it('list_journeys still answers for a demo user', async () => {
process.env.DEMO_MODE = 'true';
- const { user } = createUser(testDb, { email: '[email protected]' });
+ const { user } = await makeUser(orm, { email: '[email protected]' });
await withHarness(user.id, async (h) => {
const data = parseToolResult(await h.client.callTool({ name: 'list_journeys', arguments: {} })) as any;
expect(Array.isArray(data.journeys)).toBe(true);
@@ -1451,7 +1446,7 @@ async function createJourney(h: McpHarness, title = 'Eurotrip'): Promise<any> {
describe('Resource: trek://journeys', () => {
it('returns the journeys of the current user', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await createJourney(h);
const data = parseResourceResult(await h.client.readResource({ uri: 'trek://journeys' })) as any[];
@@ -1463,7 +1458,7 @@ describe('Resource: trek://journeys', () => {
describe('Resource: trek://journeys/{journeyId}', () => {
it('returns the hydrated journey', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await createJourney(h);
const data = parseResourceResult(await h.client.readResource({ uri: `trek://journeys/${journey.id}` })) as any;
@@ -1474,8 +1469,8 @@ describe('Resource: trek://journeys/{journeyId}', () => {
});
it('answers the legacy denial payload for a bad id and an inaccessible journey', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
await withHarness(other.id, async (hOther) => {
const foreign = await createJourney(hOther, 'Private');
await withHarness(user.id, async (h) => {
@@ -1490,7 +1485,7 @@ describe('Resource: trek://journeys/{journeyId}', () => {
describe('Resource: trek://journeys/{journeyId}/entries', () => {
it('returns the enriched entries', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await createJourney(h);
await h.client.callTool({
@@ -1509,7 +1504,7 @@ describe('Resource: trek://journeys/{journeyId}/entries', () => {
describe('Resource: trek://journeys/{journeyId}/contributors', () => {
it('returns the contributors, with the legacy [] fallback shape', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const journey = await createJourney(h);
const data = parseResourceResult(
@@ -1523,15 +1518,15 @@ describe('Resource: trek://journeys/{journeyId}/contributors', () => {
describe('Journey resource gating', () => {
it('does not register the resources when the journey addon is off', async () => {
- const { user } = createUser(testDb);
- setAddonEnabled(testDb, ADDON_IDS.JOURNEY, false);
+ const { user } = await makeUser(orm);
+ await setAddonEnabled(orm, ADDON_IDS.JOURNEY, false);
await withHarness(user.id, async (h) => {
await expect(h.client.readResource({ uri: 'trek://journeys' })).rejects.toThrow();
});
});
it('does not register the resources without the journey:read scope', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const h = await createMcpHarness({ realtime, userId: user.id, scopes: ['trips:read'] });
try {
await expect(h.client.readResource({ uri: 'trek://journeys' })).rejects.toThrow();
diff --git a/server/tests/unit/mcp/tools-leg-transport-mode.test.ts b/server/tests/unit/mcp/tools-leg-transport-mode.test.ts
index a097118bb..f2c163cd7 100644
--- a/server/tests/unit/mcp/tools-leg-transport-mode.test.ts
+++ b/server/tests/unit/mcp/tools-leg-transport-mode.test.ts
@@ -2,41 +2,38 @@
* Unit tests for MCP leg-mode tools: set_leg_transport_mode,
* set_day_default_transport_mode.
*/
-import { db as testDb } from '../../../src/db/database';
import { DayAssignments } from '../../../src/db/entities/DayAssignments.entity';
import { Days } from '../../../src/db/entities/Days.entity';
-import { createUser, createTrip, createDay, createPlace, createDayAssignment } from '../../helpers/factories';
+import { makeDayAssignment } from '../../helpers/factories/itinerary';
+import { makePlace } from '../../helpers/factories/places';
import { findRow, 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, 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;
-beforeEach(() => {
- resetTestDb(testDb);
+beforeEach(async () => {
+ await resetDatabase(orm);
broadcastMock.mockClear();
delete process.env.DEMO_MODE;
});
-let orm: TestOrm;
+let orm: MikroORM;
beforeAll(async () => {
- orm = await createTestOrm(testDb);
+ orm = (await bootTestApp(realtime)).get(MikroORM);
});
afterAll(async () => {
- await orm.close();
- testDb.close();
+ await (await bootTestApp(realtime)).close();
});
async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {
@@ -54,11 +51,11 @@ async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>)
describe('Tool: set_assignment_route_excluded (#2532)', () => {
it('takes a stop out of the route and puts it back, broadcasting each change', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const place = createPlace(testDb, trip.id);
- const assignment = createDayAssignment(testDb, day.id, place.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);
+ const assignment = await makeDayAssignment(orm, day.id, place.id);
await withHarness(user.id, async (h) => {
const out = parseToolResult(
await h.client.callTool({
@@ -80,12 +77,12 @@ describe('Tool: set_assignment_route_excluded (#2532)', () => {
});
it('rejects an assignment of another trip', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const other = createTrip(testDb, user.id);
- const day = createDay(testDb, other.id);
- const place = createPlace(testDb, other.id);
- const assignment = createDayAssignment(testDb, day.id, place.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const other = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, other.id);
+ const place = await makePlace(orm, other.id);
+ const assignment = await makeDayAssignment(orm, day.id, place.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'set_assignment_route_excluded',
@@ -98,11 +95,11 @@ describe('Tool: set_assignment_route_excluded (#2532)', () => {
describe('Tool: set_leg_transport_mode', () => {
it('sets the outgoing leg mode (default direction)', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const place = createPlace(testDb, trip.id);
- const assignment = createDayAssignment(testDb, day.id, place.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);
+ const assignment = await makeDayAssignment(orm, day.id, place.id);
// Seed the incoming column so the assertion below proves it survives; the factory
// leaves it NULL, so without this it would pass whether or not the tool touched it.
await updateRows(orm, DayAssignments, { id: assignment.id }, { incoming_leg_transport_mode: 'walking' });
@@ -120,11 +117,11 @@ describe('Tool: set_leg_transport_mode', () => {
});
it('sets the incoming leg mode without clobbering the outgoing column (column independence)', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const place = createPlace(testDb, trip.id);
- const assignment = createDayAssignment(testDb, day.id, place.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);
+ const assignment = await makeDayAssignment(orm, day.id, place.id);
// Seed the outgoing column so we prove incoming does NOT touch it (panel item 4).
await updateRows(orm, DayAssignments, { id: assignment.id }, { leg_transport_mode: 'driving' });
@@ -141,12 +138,12 @@ describe('Tool: set_leg_transport_mode', () => {
it('rejects an assignment belonging to another trip (cross-trip join)', async () => {
// Proves the `AND d.trip_id = ?` join in getAssignmentForTrip; a 99999 id cannot.
- const { user } = createUser(testDb);
- const trip1 = createTrip(testDb, user.id);
- const trip2 = createTrip(testDb, user.id);
- const day2 = createDay(testDb, trip2.id);
- const place2 = createPlace(testDb, trip2.id);
- const assignment2 = createDayAssignment(testDb, day2.id, place2.id);
+ const { user } = await makeUser(orm);
+ const trip1 = await makeTrip(orm, user.id);
+ const trip2 = await makeTrip(orm, user.id);
+ const day2 = await makeDay(orm, trip2.id);
+ const place2 = await makePlace(orm, trip2.id);
+ const assignment2 = await makeDayAssignment(orm, day2.id, place2.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'set_leg_transport_mode',
@@ -157,11 +154,11 @@ describe('Tool: set_leg_transport_mode', () => {
});
it('clears the leg mode with null (inherit day default)', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const place = createPlace(testDb, trip.id);
- const assignment = createDayAssignment(testDb, day.id, place.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);
+ const assignment = await makeDayAssignment(orm, day.id, place.id);
await updateRows(orm, DayAssignments, { id: assignment.id }, { leg_transport_mode: 'cycling' });
await withHarness(user.id, async (h) => {
@@ -175,8 +172,8 @@ describe('Tool: set_leg_transport_mode', () => {
});
it('returns error when assignment 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_leg_transport_mode',
@@ -187,12 +184,12 @@ describe('Tool: set_leg_transport_mode', () => {
});
it('returns access denied for non-member', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const trip = createTrip(testDb, other.id);
- const day = createDay(testDb, trip.id);
- const place = createPlace(testDb, trip.id);
- const assignment = createDayAssignment(testDb, day.id, place.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const trip = await makeTrip(orm, other.id);
+ const day = await makeDay(orm, trip.id);
+ const place = await makePlace(orm, trip.id);
+ const assignment = await makeDayAssignment(orm, day.id, place.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'set_leg_transport_mode',
@@ -204,11 +201,11 @@ describe('Tool: set_leg_transport_mode', () => {
it('blocks demo user', async () => {
process.env.DEMO_MODE = 'true';
- const { user } = createUser(testDb, { email: '[email protected]' });
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const place = createPlace(testDb, trip.id);
- const assignment = createDayAssignment(testDb, day.id, place.id);
+ const { user } = await makeUser(orm, { email: '[email protected]' });
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const place = await makePlace(orm, trip.id);
+ const assignment = await makeDayAssignment(orm, day.id, place.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'set_leg_transport_mode',
@@ -225,9 +222,9 @@ describe('Tool: set_leg_transport_mode', () => {
describe('Tool: set_day_default_transport_mode', () => {
it('sets the day default transport mode', 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 = await h.client.callTool({
@@ -241,9 +238,9 @@ describe('Tool: set_day_default_transport_mode', () => {
});
it('clears the day default with null', 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 updateRows(orm, Days, { id: day.id }, { default_transport_mode: 'driving' });
await withHarness(user.id, async (h) => {
@@ -258,11 +255,11 @@ describe('Tool: set_day_default_transport_mode', () => {
it('returns the day with its populated assignments array', async () => {
// setDefaultTransportMode returns { ...day, assignments }; exercise the non-empty case (panel item 4).
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const place = createPlace(testDb, trip.id);
- const assignment = createDayAssignment(testDb, day.id, place.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);
+ const assignment = await makeDayAssignment(orm, day.id, place.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
@@ -277,10 +274,10 @@ describe('Tool: set_day_default_transport_mode', () => {
});
it('rejects a day belonging to another trip (cross-trip join)', async () => {
- const { user } = createUser(testDb);
- const trip1 = createTrip(testDb, user.id);
- const trip2 = createTrip(testDb, user.id);
- const day2 = createDay(testDb, trip2.id);
+ const { user } = await makeUser(orm);
+ const trip1 = await makeTrip(orm, user.id);
+ const trip2 = await makeTrip(orm, user.id);
+ const day2 = await makeDay(orm, trip2.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'set_day_default_transport_mode',
@@ -291,8 +288,8 @@ describe('Tool: set_day_default_transport_mode', () => {
});
it('returns error when day 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_day_default_transport_mode',
@@ -303,10 +300,10 @@ describe('Tool: set_day_default_transport_mode', () => {
});
it('returns access denied for non-member', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const trip = createTrip(testDb, other.id);
- const day = createDay(testDb, trip.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const trip = await makeTrip(orm, other.id);
+ const day = await makeDay(orm, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'set_day_default_transport_mode',
@@ -318,9 +315,9 @@ describe('Tool: set_day_default_transport_mode', () => {
it('blocks demo user', async () => {
process.env.DEMO_MODE = 'true';
- const { user } = createUser(testDb, { email: '[email protected]' });
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
+ const { user } = await makeUser(orm, { email: '[email protected]' });
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'set_day_default_transport_mode',
diff --git a/server/tests/unit/mcp/tools-memories.test.ts b/server/tests/unit/mcp/tools-memories.test.ts
index c0f487c12..48da70768 100644
--- a/server/tests/unit/mcp/tools-memories.test.ts
+++ b/server/tests/unit/mcp/tools-memories.test.ts
@@ -8,7 +8,6 @@
* route performs, and what lands in the DB.
*/
import { ADDON_IDS } from '../../../src/addons';
-import { db as testDb } from '../../../src/db/database';
import { JourneyEntryPhotos } from '../../../src/db/entities/JourneyEntryPhotos.entity';
import { JourneyPhotos } from '../../../src/db/entities/JourneyPhotos.entity';
import { PhotoProviders } from '../../../src/db/entities/PhotoProviders.entity';
@@ -16,20 +15,18 @@ import { TrekPhotos } from '../../../src/db/entities/TrekPhotos.entity';
import { ImmichService } from '../../../src/nest/memories/immich.service';
import { PhotoCaptureBackfillService } from '../../../src/nest/memories/photo-capture-backfill.service';
import { SynologyService } from '../../../src/nest/memories/synology.service';
-import { createUser, createJourney, createJourneyEntry, addJourneyContributor } from '../../helpers/factories';
+import { addJourneyContributor, makeJourney, makeJourneyEntry } from '../../helpers/factories/journeys';
import { countRows, deleteRows, findRow, findRows, upsertRow } from '../../helpers/factories/rows';
+import { setAddonEnabled } from '../../helpers/factories/settings';
+import { makeUser } from '../../helpers/factories/users';
import { FakeRealtimeService } from '../../helpers/fake-realtime';
import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';
-import { resetTestDb, setAddonEnabled } 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());
-});
-
const realtime = new FakeRealtimeService();
const broadcastMock = realtime.broadcastMock;
// The suite asserts both channels on one recorder, as its module mock did.
@@ -60,7 +57,7 @@ const IMMICH_ASSET = {
const SYNOLOGY_ASSET = { id: 's1', takenAt: '2026-07-02T10:00:00.000Z', lat: 48.1, lng: 11.6 };
/**
- * photo_providers is seed data, so resetTestDb leaves it alone and a toggle
+ * photo_providers is seed data, so resetDatabase leaves it alone and a toggle
* leaks into the next case. Every case states what it needs.
*/
async function setProviderEnabled(id: string, enabled: boolean): Promise<void> {
@@ -72,8 +69,8 @@ async function removeProvider(id: string): Promise<void> {
}
beforeEach(async () => {
- resetTestDb(testDb);
- setAddonEnabled(testDb, ADDON_IDS.JOURNEY, true);
+ await resetDatabase(orm);
+ await setAddonEnabled(orm, ADDON_IDS.JOURNEY, true);
await setProviderEnabled('immich', true);
await setProviderEnabled('synologyphotos', true);
broadcastMock.mockClear();
@@ -95,15 +92,14 @@ beforeEach(async () => {
backfillRun.mockClear();
});
-let orm: TestOrm;
+let orm: MikroORM;
beforeAll(async () => {
- orm = await createTestOrm(testDb);
+ orm = (await bootTestApp(realtime)).get(MikroORM);
});
afterAll(async () => {
- await orm.close();
- testDb.close();
+ await (await bootTestApp(realtime)).close();
});
async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>, scopes?: string[] | null) {
@@ -121,7 +117,7 @@ async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>,
describe('Tool: search_provider_photos', () => {
it('searches Immich with the page and size coercion the REST route applies', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'search_provider_photos',
@@ -137,7 +133,7 @@ describe('Tool: search_provider_photos', () => {
});
it('turns a 1-based page into the offset Synology paginates by', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'search_provider_photos',
@@ -152,7 +148,7 @@ describe('Tool: search_provider_photos', () => {
});
it("defaults Synology to its own page size, not Immich's", async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
await h.client.callTool({ name: 'search_provider_photos', arguments: { provider: 'synologyphotos' } });
expect(synologySearch).toHaveBeenCalledWith(user.id, undefined, undefined, 0, 100, 0);
@@ -160,7 +156,7 @@ describe('Tool: search_provider_photos', () => {
});
it('tells Synology which zone the dates are meant in, so a tool call is fixable too', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'search_provider_photos',
@@ -174,7 +170,7 @@ describe('Tool: search_provider_photos', () => {
});
it('refuses a provider the admin has switched off, without calling it', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await setProviderEnabled('synologyphotos', false);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
@@ -188,7 +184,7 @@ describe('Tool: search_provider_photos', () => {
});
it('refuses a provider that is not in the provider table at all', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await removeProvider('synologyphotos');
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
@@ -202,7 +198,7 @@ describe('Tool: search_provider_photos', () => {
});
it('passes the upstream refusal through verbatim', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
immichSearch.mockResolvedValue({ error: 'Immich not configured', status: 400 });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'search_provider_photos', arguments: { provider: 'immich' } });
@@ -212,7 +208,7 @@ describe('Tool: search_provider_photos', () => {
});
it('rejects a page size past the cap instead of quietly clamping it', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'search_provider_photos',
@@ -224,7 +220,7 @@ describe('Tool: search_provider_photos', () => {
});
it('rejects an unknown provider name at the schema', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'search_provider_photos',
@@ -235,7 +231,7 @@ describe('Tool: search_provider_photos', () => {
});
it('is not registered when every photo provider is switched off', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await setProviderEnabled('immich', false);
await setProviderEnabled('synologyphotos', false);
await withHarness(user.id, async (h) => {
@@ -247,8 +243,8 @@ describe('Tool: search_provider_photos', () => {
});
it('is not registered while the journey addon is off, however the provider rows read', async () => {
- const { user } = createUser(testDb);
- setAddonEnabled(testDb, ADDON_IDS.JOURNEY, false);
+ const { user } = await makeUser(orm);
+ await setAddonEnabled(orm, ADDON_IDS.JOURNEY, false);
await withHarness(user.id, async (h) => {
const names = (await h.client.listTools()).tools.map((t) => t.name);
expect(names).not.toContain('search_provider_photos');
@@ -258,10 +254,10 @@ describe('Tool: search_provider_photos', () => {
});
it('refuses mid-session once the journey addon goes off, without calling the provider', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
// Registered while journey was on; the flip lands after session start.
- setAddonEnabled(testDb, ADDON_IDS.JOURNEY, false);
+ await setAddonEnabled(orm, ADDON_IDS.JOURNEY, false);
const result = await h.client.callTool({
name: 'search_provider_photos',
arguments: { provider: 'immich' },
@@ -273,7 +269,7 @@ describe('Tool: search_provider_photos', () => {
});
it('is registered again as soon as one provider is on', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await setProviderEnabled('immich', true);
await setProviderEnabled('synologyphotos', false);
await withHarness(user.id, async (h) => {
@@ -282,7 +278,7 @@ describe('Tool: search_provider_photos', () => {
});
it('is not registered for a token without journey read access', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(
user.id,
async (h) => {
@@ -299,7 +295,7 @@ describe('Tool: search_provider_photos', () => {
describe('Tool: list_provider_albums', () => {
it('lists the Immich albums', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const data = parseToolResult(
await h.client.callTool({
@@ -313,7 +309,7 @@ describe('Tool: list_provider_albums', () => {
});
it('keeps the passphrase a shared Synology album needs to be opened again', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const data = parseToolResult(
await h.client.callTool({
@@ -326,7 +322,7 @@ describe('Tool: list_provider_albums', () => {
});
it('refuses a disabled provider', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await setProviderEnabled('immich', false);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({ name: 'list_provider_albums', arguments: { provider: 'immich' } });
@@ -336,7 +332,7 @@ describe('Tool: list_provider_albums', () => {
});
it('passes the upstream refusal through', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
synologyAlbums.mockResolvedValue({ success: false, error: { message: 'Synology not configured', status: 400 } });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
@@ -355,7 +351,7 @@ describe('Tool: list_provider_albums', () => {
describe('Tool: list_provider_album_photos', () => {
it('reads one Immich album', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const data = parseToolResult(
await h.client.callTool({
@@ -370,7 +366,7 @@ describe('Tool: list_provider_album_photos', () => {
});
it('forwards the passphrase to Synology', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'list_provider_album_photos',
@@ -381,7 +377,7 @@ describe('Tool: list_provider_album_photos', () => {
});
it('refuses a disabled provider', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await setProviderEnabled('synologyphotos', false);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
@@ -394,7 +390,7 @@ describe('Tool: list_provider_album_photos', () => {
});
it('passes an album that could not be fetched through as an error', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
immichAlbumPhotos.mockResolvedValue({ error: 'Failed to fetch album', status: 404 });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
@@ -442,9 +438,9 @@ async function entryPhotoRows(entryId: number) {
describe('Tool: add_journey_provider_photos', () => {
it('attaches provider assets to an entry and records them against the journey', async () => {
- const { user } = createUser(testDb);
- const journey = createJourney(testDb, user.id);
- const entry = createJourneyEntry(testDb, journey.id, user.id);
+ const { user } = await makeUser(orm);
+ const journey = await makeJourney(orm, user.id);
+ const entry = await makeJourneyEntry(orm, journey.id, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -473,9 +469,9 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('adds to the gallery alone when no entry is named', async () => {
- const { user } = createUser(testDb);
- const journey = createJourney(testDb, user.id);
- const entry = createJourneyEntry(testDb, journey.id, user.id);
+ const { user } = await makeUser(orm);
+ const journey = await makeJourney(orm, user.id);
+ const entry = await makeJourneyEntry(orm, journey.id, user.id);
await withHarness(user.id, async (h) => {
const data = parseToolResult(
await h.client.callTool({
@@ -494,9 +490,9 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('skips an asset that is already on the entry rather than duplicating it', async () => {
- const { user } = createUser(testDb);
- const journey = createJourney(testDb, user.id);
- const entry = createJourneyEntry(testDb, journey.id, user.id);
+ const { user } = await makeUser(orm);
+ const journey = await makeJourney(orm, user.id);
+ const entry = await makeJourneyEntry(orm, journey.id, user.id);
await withHarness(user.id, async (h) => {
const args = { journeyId: journey.id, entryId: entry.id, provider: 'immich', asset_ids: ['dup-1'] };
await h.client.callTool({ name: 'add_journey_provider_photos', arguments: args });
@@ -510,9 +506,9 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('queues the capture backfill for what it actually attached', async () => {
- const { user } = createUser(testDb);
- const journey = createJourney(testDb, user.id);
- const entry = createJourneyEntry(testDb, journey.id, user.id);
+ const { user } = await makeUser(orm);
+ const journey = await makeJourney(orm, user.id);
+ const entry = await makeJourneyEntry(orm, journey.id, user.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -526,8 +522,8 @@ describe('Tool: add_journey_provider_photos', () => {
it('tells the journey once the capture times have landed, exactly as the REST routes do', async () => {
// Same shared rule as POST /api/journeys/:id/gallery/provider-photos: the
// gallery re-sorts on the event instead of waiting for a reload (#1587).
- const { user } = createUser(testDb);
- const journey = createJourney(testDb, user.id);
+ const { user } = await makeUser(orm);
+ const journey = await makeJourney(orm, user.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -544,11 +540,11 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('refuses a contributor who may only read the journey', async () => {
- const { user: owner } = createUser(testDb);
- const { user: viewer } = createUser(testDb);
- const journey = createJourney(testDb, owner.id);
- const entry = createJourneyEntry(testDb, journey.id, owner.id);
- addJourneyContributor(testDb, journey.id, viewer.id, 'viewer');
+ const { user: owner } = await makeUser(orm);
+ const { user: viewer } = await makeUser(orm);
+ const journey = await makeJourney(orm, owner.id);
+ const entry = await makeJourneyEntry(orm, journey.id, owner.id);
+ await addJourneyContributor(orm, journey.id, viewer.id, 'viewer');
await withHarness(viewer.id, async (h) => {
const result = await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -561,7 +557,7 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('refuses a journey that does not exist', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -573,10 +569,10 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('refuses an entry that belongs to another journey', async () => {
- const { user } = createUser(testDb);
- const mine = createJourney(testDb, user.id);
- const other = createJourney(testDb, user.id);
- const foreignEntry = createJourneyEntry(testDb, other.id, user.id);
+ const { user } = await makeUser(orm);
+ const mine = await makeJourney(orm, user.id);
+ const other = await makeJourney(orm, user.id);
+ const foreignEntry = await makeJourneyEntry(orm, other.id, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -590,9 +586,9 @@ describe('Tool: add_journey_provider_photos', () => {
it('blocks the demo user', async () => {
process.env.DEMO_MODE = 'true';
- const { user } = createUser(testDb, { email: '[email protected]' });
- const journey = createJourney(testDb, user.id);
- const entry = createJourneyEntry(testDb, journey.id, user.id);
+ const { user } = await makeUser(orm, { email: '[email protected]' });
+ const journey = await makeJourney(orm, user.id);
+ const entry = await makeJourneyEntry(orm, journey.id, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -604,9 +600,9 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('refuses a batch past the per-call cap and writes nothing', async () => {
- const { user } = createUser(testDb);
- const journey = createJourney(testDb, user.id);
- const entry = createJourneyEntry(testDb, journey.id, user.id);
+ const { user } = await makeUser(orm);
+ const journey = await makeJourney(orm, user.id);
+ const entry = await makeJourneyEntry(orm, journey.id, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -623,8 +619,8 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('rejects a provider the journey could never resolve', async () => {
- const { user } = createUser(testDb);
- const journey = createJourney(testDb, user.id);
+ const { user } = await makeUser(orm);
+ const journey = await makeJourney(orm, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'add_journey_provider_photos',
@@ -636,15 +632,15 @@ describe('Tool: add_journey_provider_photos', () => {
});
it('is not registered while the journey addon is off', async () => {
- const { user } = createUser(testDb);
- setAddonEnabled(testDb, ADDON_IDS.JOURNEY, false);
+ const { user } = await makeUser(orm);
+ await setAddonEnabled(orm, ADDON_IDS.JOURNEY, false);
await withHarness(user.id, async (h) => {
expect((await h.client.listTools()).tools.map((t) => t.name)).not.toContain('add_journey_provider_photos');
});
});
it('is not registered for a read-only journey token', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
await withHarness(
user.id,
async (h) => {
diff --git a/server/tests/unit/mcp/tools-notes.test.ts b/server/tests/unit/mcp/tools-notes.test.ts
index d82a77c0c..65c11372c 100644
--- a/server/tests/unit/mcp/tools-notes.test.ts
+++ b/server/tests/unit/mcp/tools-notes.test.ts
@@ -5,27 +5,25 @@
* create_collab_note, update_collab_note, delete_collab_note (CollabMcp,
* DI-discovered via the same registry).
*/
-import { db as testDb } from '../../../src/db/database';
import { CollabNotes } from '../../../src/db/entities/CollabNotes.entity';
import { DayNotes } from '../../../src/db/entities/DayNotes.entity';
import { TripFiles } from '../../../src/db/entities/TripFiles.entity';
import { NotificationsService } from '../../../src/nest/notifications/notifications.service';
-import { createUser, createTrip, createDay, createDayNote, createCollabNote } from '../../helpers/factories';
+import { makeCollabNote } from '../../helpers/factories/collab';
import { makeTripFile } from '../../helpers/factories/files';
+import { makeDayNote } from '../../helpers/factories/itinerary';
import { countRows, findRow, updateRows } from '../../helpers/factories/rows';
+import { setCollabFeature } from '../../helpers/factories/settings';
+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 { resetTestDb, setCollabFeature } from '../../helpers/test-db';
-import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
+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());
-});
-
const { unlinkSyncMock } = vi.hoisted(() => ({
unlinkSyncMock: vi.fn(),
}));
@@ -37,22 +35,21 @@ vi.mock('fs', async (importOriginal) => {
const realtime = new FakeRealtimeService();
const broadcastMock = realtime.broadcastMock;
-beforeEach(() => {
- resetTestDb(testDb);
+beforeEach(async () => {
+ await resetDatabase(orm);
broadcastMock.mockClear();
unlinkSyncMock.mockClear();
delete process.env.DEMO_MODE;
});
-let orm: TestOrm;
+let orm: MikroORM;
beforeAll(async () => {
- orm = await createTestOrm(testDb);
+ orm = (await bootTestApp(realtime)).get(MikroORM);
});
afterAll(async () => {
- await orm.close();
- testDb.close();
+ await (await bootTestApp(realtime)).close();
});
/** The stored day note; fails the case when it is gone. */
@@ -84,9 +81,9 @@ async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>)
describe('Tool: create_day_note', () => {
it('creates a note on a day', 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 = await h.client.callTool({
name: 'create_day_note',
@@ -100,7 +97,7 @@ describe('Tool: create_day_note', () => {
});
it('describes text as the title and time as the body, as the planner shows them', 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_day_note', 'update_day_note']) {
@@ -116,9 +113,9 @@ describe('Tool: create_day_note', () => {
});
it('takes a body of 2000 characters, the bound the planner allows, and refuses one more', 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 body = 'b'.repeat(2000);
const result = await h.client.callTool({
@@ -137,9 +134,9 @@ describe('Tool: create_day_note', () => {
});
it('defaults icon to 📝', 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 = await h.client.callTool({
name: 'create_day_note',
@@ -151,9 +148,9 @@ describe('Tool: create_day_note', () => {
});
it('broadcasts dayNote:created event', 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) => {
await h.client.callTool({ name: 'create_day_note', arguments: { tripId: trip.id, dayId: day.id, text: 'Note' } });
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'dayNote:created', expect.any(Object));
@@ -161,9 +158,9 @@ describe('Tool: create_day_note', () => {
});
it('persists a palette color and an explicit position', 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 = await h.client.callTool({
name: 'create_day_note',
@@ -177,9 +174,9 @@ describe('Tool: create_day_note', () => {
});
it('stores no color and appends at the bottom when neither is given', 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 = await h.client.callTool({
name: 'create_day_note',
@@ -193,9 +190,9 @@ describe('Tool: create_day_note', () => {
});
it('refuses a color outside the note palette and writes nothing', 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 = await h.client.callTool({
name: 'create_day_note',
@@ -207,10 +204,10 @@ describe('Tool: create_day_note', () => {
});
it('returns error when day does not belong to trip', async () => {
- const { user } = createUser(testDb);
- const trip1 = createTrip(testDb, user.id);
- const trip2 = createTrip(testDb, user.id);
- const dayFromTrip2 = createDay(testDb, trip2.id);
+ const { user } = await makeUser(orm);
+ const trip1 = await makeTrip(orm, user.id);
+ const trip2 = await makeTrip(orm, user.id);
+ const dayFromTrip2 = await makeDay(orm, trip2.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'create_day_note',
@@ -221,10 +218,10 @@ describe('Tool: create_day_note', () => {
});
it('returns access denied for non-member', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const trip = createTrip(testDb, other.id);
- const day = createDay(testDb, trip.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const trip = await makeTrip(orm, other.id);
+ const day = await makeDay(orm, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'create_day_note',
@@ -241,10 +238,10 @@ describe('Tool: create_day_note', () => {
describe('Tool: update_day_note', () => {
it('updates note text, time, icon', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id, { text: 'Old text', time: '09:00', icon: '📝' });
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id, { text: 'Old text', time: '09:00', icon: '📝' });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_day_note',
@@ -258,11 +255,11 @@ describe('Tool: update_day_note', () => {
});
it('edits a note whose body is longer than 250 characters without shortening it', 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 longBody = 'Opening hours and the ticket links. '.repeat(20);
- const note = createDayNote(testDb, day.id, trip.id, { text: 'Museum day', time: longBody });
+ const note = await makeDayNote(orm, day.id, trip.id, { text: 'Museum day', time: longBody });
await withHarness(user.id, async (h) => {
const renamed = await h.client.callTool({
name: 'update_day_note',
@@ -282,10 +279,10 @@ describe('Tool: update_day_note', () => {
});
it('refuses an empty title on update and keeps the stored one', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id, { text: 'Keep me' });
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id, { text: 'Keep me' });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_day_note',
@@ -297,10 +294,10 @@ describe('Tool: update_day_note', () => {
});
it('trims text whitespace', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_day_note',
@@ -312,10 +309,10 @@ describe('Tool: update_day_note', () => {
});
it('sets color and moves the note within the day', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id, { sort_order: 9999 });
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id, { sort_order: 9999 });
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'update_day_note',
@@ -328,10 +325,10 @@ describe('Tool: update_day_note', () => {
});
it('clears the color with an explicit null', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id);
await updateRows(orm, DayNotes, { id: note.id }, { color: '#2563eb' });
await withHarness(user.id, async (h) => {
await h.client.callTool({
@@ -343,10 +340,10 @@ describe('Tool: update_day_note', () => {
});
it('keeps the stored color and position when neither is sent', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id, { sort_order: 3 });
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id, { sort_order: 3 });
await updateRows(orm, DayNotes, { id: note.id }, { color: '#9333ea' });
await withHarness(user.id, async (h) => {
await h.client.callTool({
@@ -360,10 +357,10 @@ describe('Tool: update_day_note', () => {
});
it('refuses a color outside the note palette', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_day_note',
@@ -375,10 +372,10 @@ describe('Tool: update_day_note', () => {
});
it('broadcasts dayNote:updated event', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'update_day_note',
@@ -389,9 +386,9 @@ describe('Tool: update_day_note', () => {
});
it('returns error when note not found', 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 = await h.client.callTool({
name: 'update_day_note',
@@ -402,11 +399,11 @@ describe('Tool: update_day_note', () => {
});
it('returns access denied for non-member', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const trip = createTrip(testDb, other.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const trip = await makeTrip(orm, other.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_day_note',
@@ -423,10 +420,10 @@ describe('Tool: update_day_note', () => {
describe('Tool: delete_day_note', () => {
it('deletes a day note', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'delete_day_note',
@@ -439,10 +436,10 @@ describe('Tool: delete_day_note', () => {
});
it('broadcasts dayNote:deleted event', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'delete_day_note',
@@ -453,9 +450,9 @@ describe('Tool: delete_day_note', () => {
});
it('returns error when note not found', 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 = await h.client.callTool({
name: 'delete_day_note',
@@ -466,11 +463,11 @@ describe('Tool: delete_day_note', () => {
});
it('returns access denied for non-member', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const trip = createTrip(testDb, other.id);
- const day = createDay(testDb, trip.id);
- const note = createDayNote(testDb, day.id, trip.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const trip = await makeTrip(orm, other.id);
+ const day = await makeDay(orm, trip.id);
+ const note = await makeDayNote(orm, day.id, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'delete_day_note',
@@ -500,19 +497,19 @@ describe('Day-note tools — scope gating', () => {
}
it('registers all three 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 WRITE_TOOLS) expect(names).toContain(tool);
});
it('registers no day-note tools with trips:read only (all three are writes)', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const names = await listToolNames(user.id, ['trips:read']);
for (const tool of WRITE_TOOLS) expect(names).not.toContain(tool);
});
it('registers no day-note 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 WRITE_TOOLS) expect(names).not.toContain(tool);
});
@@ -525,11 +522,11 @@ describe('Day-note tools — scope gating', () => {
describe('Resource: trek://trips/{tripId}/days/{dayId}/notes', () => {
it('returns the day notes ordered by sort_order', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const day = createDay(testDb, trip.id);
- createDayNote(testDb, day.id, trip.id, { text: 'Second', sort_order: 5 });
- createDayNote(testDb, day.id, trip.id, { text: 'First', sort_order: 1 });
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const day = await makeDay(orm, trip.id);
+ await makeDayNote(orm, day.id, trip.id, { text: 'Second', sort_order: 5 });
+ await makeDayNote(orm, day.id, trip.id, { text: 'First', sort_order: 1 });
await withHarness(user.id, async (h) => {
const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/days/${day.id}/notes` });
const notes = parseResourceResult(result) as { text: string }[];
@@ -540,10 +537,10 @@ describe('Resource: trek://trips/{tripId}/days/{dayId}/notes', () => {
});
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 day = createDay(testDb, trip.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const trip = await makeTrip(orm, other.id);
+ const day = await makeDay(orm, trip.id);
await withHarness(user.id, async (h) => {
const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/days/${day.id}/notes` });
expect(parseResourceResult(result)).toEqual({ error: 'Trip not found or access denied' });
@@ -551,7 +548,7 @@ describe('Resource: trek://trips/{tripId}/days/{dayId}/notes', () => {
});
it('returns the access-denied payload for a malformed 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/1/days/not-a-number/notes' });
expect(parseResourceResult(result)).toEqual({ error: 'Trip not found or access denied' });
@@ -565,8 +562,8 @@ describe('Resource: trek://trips/{tripId}/days/{dayId}/notes', () => {
describe('Tool: create_collab_note', () => {
it('creates a collab note 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);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'create_collab_note',
@@ -581,8 +578,8 @@ describe('Tool: create_collab_note', () => {
});
it('defaults category to "General" and color to "#6366f1"', 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_collab_note',
@@ -595,8 +592,8 @@ describe('Tool: create_collab_note', () => {
});
it('persists the website link', 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_collab_note',
@@ -609,8 +606,8 @@ describe('Tool: create_collab_note', () => {
});
it('stores no website when none is given', 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_collab_note',
@@ -622,8 +619,8 @@ describe('Tool: create_collab_note', () => {
});
it('broadcasts collab:note: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_collab_note', arguments: { tripId: trip.id, title: 'Note' } });
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'collab:note:created', expect.any(Object));
@@ -631,9 +628,9 @@ describe('Tool: create_collab_note', () => {
});
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_collab_note',
@@ -650,9 +647,9 @@ describe('Tool: create_collab_note', () => {
describe('Tool: update_collab_note', () => {
it('updates collab note fields', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id, { title: 'Old', color: '#6366f1' });
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id, { title: 'Old', color: '#6366f1' });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_collab_note',
@@ -666,9 +663,9 @@ describe('Tool: update_collab_note', () => {
});
it('sets the website link on an existing note', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'update_collab_note',
@@ -679,9 +676,9 @@ describe('Tool: update_collab_note', () => {
});
it('clears the website with an explicit null', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id);
await updateRows(orm, CollabNotes, { id: note.id }, { website: 'https://example.com/old' });
await withHarness(user.id, async (h) => {
await h.client.callTool({
@@ -693,9 +690,9 @@ describe('Tool: update_collab_note', () => {
});
it('keeps the stored website when the field is not sent', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id);
await updateRows(orm, CollabNotes, { id: note.id }, { website: 'https://example.com/keep' });
await withHarness(user.id, async (h) => {
await h.client.callTool({
@@ -707,9 +704,9 @@ describe('Tool: update_collab_note', () => {
});
it('refuses a website past the tool cap, the way the sibling text fields are capped', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_collab_note',
@@ -721,9 +718,9 @@ describe('Tool: update_collab_note', () => {
});
it('broadcasts collab:note:updated event', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({
name: 'update_collab_note',
@@ -734,8 +731,8 @@ describe('Tool: update_collab_note', () => {
});
it('returns error when note 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_collab_note',
@@ -746,10 +743,10 @@ describe('Tool: update_collab_note', () => {
});
it('returns access denied for non-member', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const trip = createTrip(testDb, other.id);
- const note = createCollabNote(testDb, trip.id, other.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const trip = await makeTrip(orm, other.id);
+ const note = await makeCollabNote(orm, trip.id, other.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_collab_note',
@@ -766,9 +763,9 @@ describe('Tool: update_collab_note', () => {
describe('Tool: delete_collab_note', () => {
it('deletes a collab note', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'delete_collab_note',
@@ -781,9 +778,9 @@ describe('Tool: delete_collab_note', () => {
});
it('deletes associated trip_files records from the database', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id);
// Insert a trip_file linked to this note
await makeTripFile(orm, trip.id, {
note: note.id,
@@ -808,9 +805,9 @@ describe('Tool: delete_collab_note', () => {
});
it('broadcasts collab:note:deleted event', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- const note = createCollabNote(testDb, trip.id, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ const note = await makeCollabNote(orm, trip.id, user.id);
await withHarness(user.id, async (h) => {
await h.client.callTool({ name: 'delete_collab_note', arguments: { tripId: trip.id, noteId: note.id } });
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'collab:note:deleted', expect.any(Object));
@@ -818,8 +815,8 @@ describe('Tool: delete_collab_note', () => {
});
it('returns error when note 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_collab_note',
@@ -830,10 +827,10 @@ describe('Tool: delete_collab_note', () => {
});
it('returns access denied for non-member', async () => {
- const { user } = createUser(testDb);
- const { user: other } = createUser(testDb);
- const trip = createTrip(testDb, other.id);
- const note = createCollabNote(testDb, trip.id, other.id);
+ const { user } = await makeUser(orm);
+ const { user: other } = await makeUser(orm);
+ const trip = await makeTrip(orm, other.id);
+ const note = await makeCollabNote(orm, trip.id, other.id);
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'delete_collab_note',
@@ -850,9 +847,9 @@ describe('Tool: delete_collab_note', () => {
// never attaches.
describe('Resource: trek://trips/{tripId}/collab-notes', () => {
it('returns collab notes with username', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- createCollabNote(testDb, trip.id, user.id, { title: 'Ideas' });
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ await makeCollabNote(orm, trip.id, user.id, { title: 'Ideas' });
await withHarness(user.id, async (h) => {
const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/collab-notes` });
@@ -864,9 +861,9 @@ describe('Resource: trek://trips/{tripId}/collab-notes', () => {
});
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}/collab-notes` });
@@ -878,8 +875,8 @@ describe('Resource: trek://trips/{tripId}/collab-notes', () => {
describe('create_collab_note, as the Collab tab posts it', () => {
it('MCP-COLLAB-002: notifies the fellow travellers like the route does, after the room heard of the note', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
const send = vi
.spyOn((await bootTestApp(realtime)).get(NotificationsService), 'send')
.mockResolvedValue({ attempted: 0, delivered: 0 });
@@ -921,10 +918,10 @@ describe('Tool: list_collab_notes', () => {
}
it('MCP-COLLAB-010: lists the notes of the trip, pinned first, with their author and files', async () => {
- const { user } = createUser(testDb);
- const trip = createTrip(testDb, user.id);
- createCollabNote(testDb, trip.id, user.id, { title: 'Ideas' });
- const pinned = createCollabNote(testDb, trip.id, user.id, { title: 'Restaurants' });
+ const { user } = await makeUser(orm);
+ const trip = await makeTrip(orm, user.id);
+ await makeCollabNote(orm, trip.id, user.id, { title: 'Ideas' });
+ const pinned = await makeCollabNote(orm, trip.id, user.id, { title: 'Restaurants' });
await updateRows(orm, CollabNotes, { id: pinned.id }, { pinned: 1 });
const { isError, data } = await listNotes(user.id, trip.id);
expect(isError).not.toBe(true);
@@ -934,17 +931,17 @@ describe('Tool: list_collab_notes', () => {
});
it('MCP-COLLAB-011: refuses a trip the user is not part of, and reads nothing', async () => {
- const { user } = createUser(testDb);
- const { user: owner } = createUser(testDb);
- const trip = createTrip(testDb, owner.id);
- createCollabNote(testDb, trip.id, owner.id, { title: 'Private' });
+ const { user } = await makeUser(orm);
+ const { user: owner } = await makeUser(orm);
+ const trip = await makeTrip(orm, owner.id);
+ await makeCollabNote(orm, trip.id, owner.id, { title: 'Private' });
const { isError, data } = await listNotes(user.id, trip.id);
expect(isError).toBe(true);
expect(data).toBeNull();
});
it('MCP-COLLAB-012: is a read, offered only while the notes are switched on', async () => {
- const { user } = createUser(testDb);
+ const { user } = await makeUser(orm);
const names = async () => {
const h = await createMcpHarness({ realtime, userId: user.id, withResources: false });
try {
@@ -954,11 +951,11 @@ describe('Tool: list_collab_notes', () => {
}
};
expect(await names()).toContainEqual(['list_collab_notes', true]);
- setCollabFeature(testDb, 'notes', false);
+ await setCollabFeature(orm, 'notes', false);
try {
expect((await names()).map(([name]) => name)).not.toContain('list_collab_notes');
} finally {
- setCollabFeature(testDb, 'notes', true);
+ await setCollabFeature(orm, 'notes', true);
}
});
});