mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
b3d69aa760
The corpus behind "is our own index good enough to replace Nominatim". When somebody searches and then picks a result, the client posts the query, the rank and the pick. Nothing else: no user, no trip, no session, and coordinates only to three decimals. Deliberately decoupled from the search endpoint. Correlating a response with a later pick would mean handing out a ticket on POST /api/maps/search and threading it through all fifteen call sites; the client already holds everything the row needs at the moment of the pick. Evaluation happens offline afterwards: export the corpus, run it against a candidate index, count how often the pick came back in the top five. That is why collection can start before such an index exists, which is the whole point, because the corpus needs weeks of real use and the index needs a server, and those two waits should not be serial. Off unless an admin switches it on, and it reads === 'true' rather than !== 'false'. The three older places switches fail open because a migration backfilled a row for installs already using them; nothing uses this one, so an instance that upgrades and never visits the admin panel logs nothing. Reading is admin only, retention is 180 days, and the switch state is on the unauthenticated app-config endpoint on purpose: whether an instance records what its users search for is something a visitor may know before logging in.
65 lines
2.4 KiB
TypeScript
65 lines
2.4 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { PlaceShadowController } from '../../../src/nest/place-shadow/place-shadow.controller';
|
|
import type { PlaceShadowService } from '../../../src/nest/place-shadow/place-shadow.service';
|
|
import type { PlaceShadowPickDto } from '../../../src/nest/place-shadow/place-shadow.dto';
|
|
|
|
function makeController(svc: Partial<PlaceShadowService>) {
|
|
return new PlaceShadowController(svc as PlaceShadowService);
|
|
}
|
|
|
|
const BODY = {
|
|
query: 'ecklife rostock',
|
|
source: 'search:nominatim',
|
|
liveRank: 2,
|
|
liveCount: 6,
|
|
pickedName: 'Ecklife',
|
|
pickedLat: 54.083,
|
|
pickedLng: 12.132,
|
|
} as PlaceShadowPickDto;
|
|
|
|
describe('PlaceShadowController', () => {
|
|
describe('POST /api/place-shadow/pick', () => {
|
|
it('answers 200 { recorded: false } when the log is off, never an error', () => {
|
|
const record = vi.fn().mockReturnValue(false);
|
|
expect(makeController({ record }).pick(BODY)).toEqual({ recorded: false });
|
|
expect(record).toHaveBeenCalledWith(BODY);
|
|
});
|
|
|
|
it('reports a written row', () => {
|
|
expect(makeController({ record: vi.fn().mockReturnValue(true) }).pick(BODY)).toEqual({ recorded: true });
|
|
});
|
|
});
|
|
|
|
describe('GET /api/place-shadow/export', () => {
|
|
const page = { version: 1 as const, generatedAt: 'now', rows: [], nextAfter: null };
|
|
|
|
it('passes a positive cursor through', () => {
|
|
const exp = vi.fn().mockReturnValue(page);
|
|
makeController({ export: exp }).export('42');
|
|
expect(exp).toHaveBeenCalledWith(42);
|
|
});
|
|
|
|
it('starts from the beginning for anything that is not a positive integer', () => {
|
|
const exp = vi.fn().mockReturnValue(page);
|
|
const c = makeController({ export: exp });
|
|
for (const bad of [undefined, '', 'abc', '0', '-5', '1.5', '1e400']) {
|
|
c.export(bad);
|
|
}
|
|
expect(exp.mock.calls.every(([arg]) => arg === undefined)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('DELETE /api/place-shadow', () => {
|
|
it('reports how many rows went', () => {
|
|
expect(makeController({ clear: vi.fn().mockReturnValue(17) }).clear()).toEqual({ removed: 17 });
|
|
});
|
|
});
|
|
|
|
describe('GET /api/place-shadow/summary', () => {
|
|
it('hands the service summary straight back', () => {
|
|
const summary = { enabled: true, total: 3 };
|
|
expect(makeController({ summary: vi.fn().mockReturnValue(summary) }).summary()).toBe(summary);
|
|
});
|
|
});
|
|
});
|