mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
chore: move maps backend to proper DI
This commit is contained in:
@@ -39,7 +39,14 @@ const { broadcastMock } = vi.hoisted(() => ({ broadcastMock: vi.fn() }));
|
||||
vi.mock('../../../src/websocket', () => ({ broadcast: broadcastMock }));
|
||||
|
||||
const { searchPlacesMock } = vi.hoisted(() => ({ searchPlacesMock: vi.fn() }));
|
||||
vi.mock('../../../src/services/mapsService', () => ({ searchPlaces: searchPlacesMock }));
|
||||
// The maps bridge is what the legacy places registrar (and placeEnrichment, in
|
||||
// the same import graph) consume since the maps DI fold — mock every export it
|
||||
// provides so the named imports resolve.
|
||||
vi.mock('../../../src/nest/maps/maps.bridge', () => ({
|
||||
searchPlaces: searchPlacesMock,
|
||||
getMapsKey: vi.fn(() => null),
|
||||
getPlacePhoto: vi.fn(async () => ({ photoUrl: null, attribution: null })),
|
||||
}));
|
||||
|
||||
import { createTables } from '../../../src/db/schema';
|
||||
import { runMigrations } from '../../../src/db/migrations';
|
||||
|
||||
@@ -35,13 +35,6 @@ vi.mock('../../../src/config', () => ({
|
||||
const { broadcastMock } = vi.hoisted(() => ({ broadcastMock: vi.fn() }));
|
||||
vi.mock('../../../src/websocket', () => ({ broadcast: broadcastMock }));
|
||||
|
||||
vi.mock('../../../src/services/mapsService', () => ({
|
||||
searchPlaces: vi.fn(),
|
||||
getPlaceDetails: vi.fn().mockResolvedValue({ name: 'Eiffel Tower', address: 'Paris' }),
|
||||
reverseGeocode: vi.fn().mockResolvedValue({ name: 'Paris', address: 'France' }),
|
||||
resolveGoogleMapsUrl: vi.fn().mockResolvedValue({ lat: 48.8566, lng: 2.3522, name: 'Paris' }),
|
||||
}));
|
||||
|
||||
vi.mock('../../../src/services/weatherService', () => ({
|
||||
getWeather: vi.fn().mockResolvedValue({ temp: 20, condition: 'sunny' }),
|
||||
getDetailedWeather: vi.fn().mockResolvedValue({ hourly: [] }),
|
||||
@@ -52,7 +45,21 @@ import { runMigrations } from '../../../src/db/migrations';
|
||||
import { resetTestDb } from '../../helpers/test-db';
|
||||
import { createUser } from '../../helpers/factories';
|
||||
import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';
|
||||
import * as mapsService from '../../../src/services/mapsService';
|
||||
import { MapsService } from '../../../src/nest/maps/maps.service';
|
||||
|
||||
// The geo tools live on the DI-discovered maps.mcp.ts since the maps fold; the
|
||||
// test registry builds a real MapsService over the mocked db proxy, so stub the
|
||||
// provider methods on the prototype (no auto-restore in the vitest config —
|
||||
// these survive across tests, exactly like the old module mock did).
|
||||
const getPlaceDetailsSpy = vi
|
||||
.spyOn(MapsService.prototype, 'getPlaceDetails')
|
||||
.mockResolvedValue({ name: 'Eiffel Tower', address: 'Paris' } as never);
|
||||
vi.spyOn(MapsService.prototype, 'reverseGeocode').mockResolvedValue({ name: 'Paris', address: 'France' });
|
||||
vi.spyOn(MapsService.prototype, 'resolveGoogleMapsUrl').mockResolvedValue({
|
||||
lat: 48.8566,
|
||||
lng: 2.3522,
|
||||
name: 'Paris',
|
||||
} as never);
|
||||
|
||||
beforeAll(() => {
|
||||
createTables(testDb);
|
||||
@@ -305,8 +312,7 @@ describe('Tool: get_place_details', () => {
|
||||
});
|
||||
|
||||
it('returns isError when service returns null', async () => {
|
||||
const { getPlaceDetails } = await import('../../../src/services/mapsService');
|
||||
(getPlaceDetails as ReturnType<typeof vi.fn>).mockResolvedValueOnce(null);
|
||||
getPlaceDetailsSpy.mockResolvedValueOnce(null as never);
|
||||
const { user } = createUser(testDb);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({
|
||||
|
||||
@@ -10,7 +10,6 @@ vi.mock('../../../../src/websocket', () => ({ broadcast: vi.fn() }));
|
||||
const permissionsStub = { checkPermission: vi.fn(() => true) };
|
||||
vi.mock('../../../../src/services/tripAccess', () => ({ verifyTripAccess: vi.fn() }));
|
||||
vi.mock('../../../../src/services/placeService', () => ({ createPlace: vi.fn() }));
|
||||
vi.mock('../../../../src/services/mapsService', () => ({ searchNominatim: vi.fn() }));
|
||||
|
||||
import { BookingImportService } from '../../../../src/nest/booking-import/booking-import.service';
|
||||
|
||||
@@ -21,7 +20,10 @@ function make(opts: { kit?: boolean; ai?: boolean; extract?: any; parse?: any })
|
||||
const extractor = { isAvailable: () => opts.kit ?? false, extract: vi.fn(opts.extract ?? (async () => [])) };
|
||||
const llmParse = { isAvailable: () => opts.ai ?? false, parse: vi.fn(opts.parse ?? (async () => ({ kiItems: [], warnings: [] }))) };
|
||||
const reservations = { create: vi.fn() };
|
||||
return { svc: new BookingImportService(extractor as any, llmParse as any, new DatabaseService(dbConn), reservations as never, permissionsStub as never), extractor, llmParse, reservations };
|
||||
// budget/addons/realtime/maps ride the confirm() path only — the preview()
|
||||
// tests never reach them, so stubs beyond the positional slots aren't needed.
|
||||
const maps = { searchNominatim: vi.fn() };
|
||||
return { svc: new BookingImportService(extractor as any, llmParse as any, new DatabaseService(dbConn), reservations as never, permissionsStub as never, undefined as never, undefined as never, undefined as never, maps as never), extractor, llmParse, reservations, maps };
|
||||
}
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -5,11 +5,11 @@
|
||||
*/
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
|
||||
// placeEnrichment pulls in the DB, websocket and maps service at import time;
|
||||
// placeEnrichment pulls in the DB, websocket and the maps bridge at import time;
|
||||
// stub them so the pure match selector can be tested in isolation.
|
||||
vi.mock('../../../src/db/database', () => ({ db: {}, getPlaceWithTags: () => null }));
|
||||
vi.mock('../../../src/websocket', () => ({ broadcast: () => {} }));
|
||||
vi.mock('../../../src/services/mapsService', () => ({
|
||||
vi.mock('../../../src/nest/maps/maps.bridge', () => ({
|
||||
getMapsKey: () => null,
|
||||
searchPlaces: async () => ({ places: [], source: 'none' }),
|
||||
getPlacePhoto: async () => ({ photoUrl: '', attribution: null }),
|
||||
|
||||
@@ -11,7 +11,7 @@ vi.mock('../../../src/app-config', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../../../src/app-config')>();
|
||||
return { ...actual, getAppUrl: () => 'https://trek.example.com' };
|
||||
});
|
||||
vi.mock('../../../src/services/mapsService', () => ({ buildUserAgent: () => 'TREK-Test-UA' }));
|
||||
vi.mock('../../../src/nest/maps/maps.helpers', () => ({ buildUserAgent: () => 'TREK-Test-UA' }));
|
||||
|
||||
const fetchMock = vi.fn();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user