/** * Unit tests for the globe Atlas MCP tools (atlas-globe.mcp.ts): * list_atlas_flight_routes, list_atlas_badges and list_atlas_travellers, through * a real MCP session on the booted container. They answer as the REST routes * do, the admin switch for the travellers included. */ import { setAppSetting, setUserSetting } from '../../helpers/factories/settings'; import { makeUser } from '../../helpers/factories/users'; import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness'; import { resetDatabase } from '../../helpers/reset-database'; import { bootTestApp } from '../../helpers/test-app'; import { MikroORM } from '@mikro-orm/core'; import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'; let orm: MikroORM; beforeAll(async () => { orm = (await bootTestApp()).get(MikroORM); }); beforeEach(async () => { await resetDatabase(orm); delete process.env.DEMO_MODE; }); afterAll(async () => { await (await bootTestApp()).close(); }); async function withHarness(userId: number, fn: (h: McpHarness) => Promise) { const h = await createMcpHarness({ userId, withResources: false }); try { await fn(h); } finally { await h.cleanup(); } } async function call(h: McpHarness, name: string, args: Record = {}) { return h.client.callTool({ name, arguments: args }); } describe('flights, badges and travellers', () => { it('ATGLOBE-MCP-010: list_atlas_flight_routes answers the empty flight map of a user without flights', async () => { const { user } = await makeUser(orm); await withHarness(user.id, async (h) => { expect(parseToolResult(await call(h, 'list_atlas_flight_routes'))).toEqual({ routes: [], airports: [], totals: { flights: 0, km: 0, airports: 0, longestKm: 0 }, }); }); }); it('ATGLOBE-MCP-011: list_atlas_badges answers every badge with its progress', async () => { const { user } = await makeUser(orm); await withHarness(user.id, async (h) => { const { badges } = parseToolResult(await call(h, 'list_atlas_badges')) as { badges: Array<{ id: string; earned: boolean; current: number }>; }; expect(badges.find((b) => b.id === 'countries-5')).toMatchObject({ earned: false, current: 0 }); }); }); it('ATGLOBE-MCP-012: list_atlas_travellers leaves out the hidden, and everybody while the admin switch is off', async () => { const { user } = await makeUser(orm); const { user: shown } = await makeUser(orm); const { user: hiddenUser } = await makeUser(orm); await setUserSetting(orm, hiddenUser.id, 'atlas_hidden', 'true'); await withHarness(user.id, async (h) => { const on = parseToolResult(await call(h, 'list_atlas_travellers', { ids: [shown.id, hiddenUser.id] })) as { people: Array<{ id: number }>; }; expect(on.people.map((p) => p.id)).toEqual([shown.id]); await setAppSetting(orm, 'atlas_compare_enabled', 'false'); expect(parseToolResult(await call(h, 'list_atlas_travellers', { ids: [shown.id] }))).toEqual({ people: [] }); const empty = await call(h, 'list_atlas_travellers', { ids: [] }); expect(empty.isError).toBe(true); }); }); });