mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
fix(places): say where a result came from, and stop asking questions in the form
Six changes to the place picker and the card behind it, all of them about a panel saying less and meaning more. The TREK place index has no switch in the admin panel any more. It decides whether a search leaves the instance at all, which is a property of the deployment rather than a taste: an operator pins TREK_PLACES_ENABLED=false in their compose file, and it cannot be turned off from a browser by whoever holds an admin account that day. The switch never shipped, so nothing to migrate. The standing "Using OpenStreetMap" notice above the search box is gone. It was a sentence about configuration in the middle of a form about a place, and it answered a question nobody asked while leaving the real one open. Each result now carries a small mark instead: TREK, OpenStreetMap or Google. It sits on the row rather than above the list, because a list can be two indexes interleaved and a heading could only name one of them. The saved-places filters open across the full width of the row. Two of them sit side by side, only one can be open at a time, and list names were being cut at about ten characters for no reason. Three empty states use the mascot the rest of TREK uses. The place details panel no longer tells the reader to go and ask an administrator for a Google key, the saved-places list and the road trip rail no longer explain themselves in two lines of grey text. That needed one new mood, `sad`: `sleepy` reads as falling asleep, which is a different thing from finding nothing. The Kind of stop field is out of the place form. It is a road trip concept, and the road trip view already sets it from the stop's own number, where the choice is next to what it changes.
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
deriveHttp,
|
||||
deriveSession,
|
||||
deriveDemo,
|
||||
deriveMaps,
|
||||
deriveOidc,
|
||||
deriveSmtp,
|
||||
deriveMcp,
|
||||
@@ -270,3 +271,16 @@ describe('deriveAll', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('deriveMaps', () => {
|
||||
it('TREK_PLACES_ENABLED is on unless it says the literal "false"', () => {
|
||||
// Fail-open, and deliberately not the boolean-like family the switches
|
||||
// above accept: a typo must not silently drop a whole install back to
|
||||
// Nominatim, whose usage policy forbids what TREK was doing with it.
|
||||
expect(deriveMaps({} as never).trekPlacesEnabled).toBe(true);
|
||||
expect(deriveMaps({ TREK_PLACES_ENABLED: 'false' } as never).trekPlacesEnabled).toBe(false);
|
||||
for (const value of ['true', 'FALSE', '0', 'no', '']) {
|
||||
expect(deriveMaps({ TREK_PLACES_ENABLED: value } as never).trekPlacesEnabled, value).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -495,91 +495,6 @@ describe('AddonsService transit provider', () => {
|
||||
* PlaceShadowService.enabled(), which reads the same key itself — if the two
|
||||
* diverge the admin panel shows "off" while the log keeps collecting picks.
|
||||
*/
|
||||
/**
|
||||
* The index switch reads fail-OPEN, like places_enrich_enabled and unlike the
|
||||
* three Google flags: nothing backfills a row on upgrade, so an absent row has
|
||||
* to mean on, or every existing install would silently lose the index.
|
||||
*
|
||||
* It has to keep agreeing with MapsService.trekPlacesEnabled(), which reads the
|
||||
* same key itself. If the two diverge, the admin panel shows "off" while every
|
||||
* search and keystroke keeps leaving the instance.
|
||||
*/
|
||||
describe('AddonsService trek places flag', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('ADDONS-SVC-094 an unset flag reads as ON, and only the literal "false" turns it off', () => {
|
||||
dbMock._stmt.get.mockReturnValueOnce(undefined);
|
||||
expect(svc().getTrekPlaces()).toEqual({ enabled: true });
|
||||
expect(dbMock.prepare).toHaveBeenLastCalledWith(
|
||||
"SELECT value FROM app_settings WHERE key = 'trek_places_enabled'",
|
||||
);
|
||||
|
||||
dbMock._stmt.get.mockReturnValueOnce({ value: 'false' });
|
||||
expect(svc().getTrekPlaces()).toEqual({ enabled: false });
|
||||
|
||||
// Anything else is on. A garbled row must not silently disable the default
|
||||
// search path for a whole install.
|
||||
for (const value of ['true', 'FALSE', '0', '']) {
|
||||
dbMock._stmt.get.mockReturnValueOnce({ value });
|
||||
expect(svc().getTrekPlaces(), value).toEqual({ enabled: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('ADDONS-SVC-095 the setter round-trips through the getter under its own key', () => {
|
||||
// Keyed store rather than an echo assertion: the write has to produce the
|
||||
// exact string the read compares against, so a setter persisting '0' fails
|
||||
// here instead of silently reading back ON in production.
|
||||
//
|
||||
// The reader inlines its key in the SQL and binds nothing, the way the
|
||||
// other fail-open flag does, so the statement text is what identifies the
|
||||
// row here — not the bound parameter the writer uses.
|
||||
const stored = new Map<string, string>();
|
||||
let lastSql = '';
|
||||
dbMock.prepare.mockImplementation((sql: string) => {
|
||||
lastSql = sql;
|
||||
return dbMock._stmt;
|
||||
});
|
||||
dbMock._stmt.run.mockImplementation((key: string, value: string) => {
|
||||
stored.set(key, value);
|
||||
});
|
||||
dbMock._stmt.get.mockImplementation((key?: string) => {
|
||||
const wanted = key ?? (lastSql.match(/key = '([^']+)'/)?.[1] ?? '');
|
||||
const value = stored.get(wanted);
|
||||
return value === undefined ? undefined : { value };
|
||||
});
|
||||
|
||||
expect(svc().updateTrekPlaces(false)).toEqual({ enabled: false });
|
||||
expect(dbMock._stmt.run).toHaveBeenLastCalledWith('trek_places_enabled', 'false');
|
||||
expect(svc().getTrekPlaces()).toEqual({ enabled: false });
|
||||
|
||||
expect(svc().updateTrekPlaces(true)).toEqual({ enabled: true });
|
||||
expect(dbMock._stmt.run).toHaveBeenLastCalledWith('trek_places_enabled', 'true');
|
||||
expect(svc().getTrekPlaces()).toEqual({ enabled: true });
|
||||
expect([...stored.keys()]).toEqual(['trek_places_enabled']);
|
||||
});
|
||||
|
||||
it('ADDONS-SVC-096 answers the same as MapsService.trekPlacesEnabled() for every stored value', () => {
|
||||
// The admin panel and the six call paths that gate on this must never
|
||||
// disagree: showing "off" while queries keep leaving is worse than either
|
||||
// default on its own.
|
||||
const maps = new MapsService(new DatabaseService(dbConn), {} as never);
|
||||
const rows: Array<[{ value: string } | undefined, boolean]> = [
|
||||
[undefined, true],
|
||||
[{ value: 'false' }, false],
|
||||
[{ value: 'true' }, true],
|
||||
[{ value: 'garbage' }, true],
|
||||
];
|
||||
|
||||
for (const [row, expected] of rows) {
|
||||
dbMock._stmt.get.mockReturnValueOnce(row).mockReturnValueOnce(row);
|
||||
expect(svc().getTrekPlaces()).toEqual({ enabled: expected });
|
||||
expect(maps.trekPlacesEnabled()).toBe(expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('AddonsService place shadow flag', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -49,8 +49,6 @@ const addonsStub = () => ({
|
||||
getPlacesEnrich: vi.fn(() => ({ enabled: true })),
|
||||
updatePlacesEnrich: vi.fn((enabled: boolean) => ({ enabled })),
|
||||
// Fail-open too, and the only switch here about egress rather than spending.
|
||||
getTrekPlaces: vi.fn(() => ({ enabled: true })),
|
||||
updateTrekPlaces: vi.fn((enabled: boolean) => ({ enabled })),
|
||||
getCollabFeatures: vi.fn(() => ({ chat: false })),
|
||||
updateCollabFeatures: vi.fn(() => ({ features: { chat: true }, changed: true })),
|
||||
getTransitProvider: vi.fn(() => ({ provider: 'transitous', googleKeySource: null })),
|
||||
@@ -302,26 +300,6 @@ describe('AdminController feature toggles', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('ADMIN-TOGGLE-005 trek-places forwards the body value and audits the stored one', () => {
|
||||
// The audit row carries what the service stored, not what the request
|
||||
// asked for: this switch decides whether every search leaves the instance,
|
||||
// so a row claiming it was turned off when it was not would be worse than
|
||||
// no row at all.
|
||||
const updateTrekPlaces = vi.fn(() => ({ enabled: true }));
|
||||
const c = adminCtl(svc(), undefined, { ...addonsStub(), updateTrekPlaces } as unknown as AddonsService);
|
||||
expect(c.updateTrekPlaces(user, { enabled: false }, req)).toEqual({ enabled: true });
|
||||
expect(updateTrekPlaces).toHaveBeenCalledWith(false);
|
||||
expect(writeAudit).toHaveBeenCalledWith({ userId: user.id, action: 'admin.trek_places', ip: '1.2.3.4', details: { enabled: true } });
|
||||
});
|
||||
|
||||
it('ADMIN-TOGGLE-005b trek-places reads through to AddonsService instead of a controller-side default', () => {
|
||||
const getTrekPlaces = vi.fn(() => ({ enabled: false }));
|
||||
const c = adminCtl(svc(), undefined, { ...addonsStub(), getTrekPlaces } as unknown as AddonsService);
|
||||
expect(c.getTrekPlaces()).toEqual({ enabled: false });
|
||||
expect(getTrekPlaces).toHaveBeenCalledTimes(1);
|
||||
expect(writeAudit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ADMIN-TOGGLE-004 place-shadow forwards the body value and audits the stored one', () => {
|
||||
// The handler audits result.enabled. A service that declines the flip must
|
||||
// not leave behind an audit row claiming the shadow log was switched on.
|
||||
|
||||
@@ -27,6 +27,22 @@ import { MapsService } from '../../../src/nest/maps/maps.service';
|
||||
import type { DatabaseService } from '../../../src/nest/database/database.service';
|
||||
import type { PlacePhotoCacheService } from '../../../src/nest/place-photos/place-photo-cache.service';
|
||||
|
||||
// The index switch is an environment variable now, not an admin row: it decides
|
||||
// whether a search leaves the instance at all, so it is pinned by the operator
|
||||
// rather than flippable from a browser. `setTrekPlaces()` below drives it.
|
||||
const trekPlaces = vi.hoisted(() => ({ on: true }));
|
||||
vi.mock('../../../src/app-config', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../../../src/app-config')>();
|
||||
return {
|
||||
...actual,
|
||||
readEnv: () => {
|
||||
const env = actual.readEnv();
|
||||
return { ...env, maps: { ...env.maps, trekPlacesEnabled: trekPlaces.on } };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
const INPUT = 'Café Kröpel';
|
||||
|
||||
const hit = (over: Record<string, unknown> = {}) => ({
|
||||
@@ -47,11 +63,8 @@ const hit = (over: Record<string, unknown> = {}) => ({
|
||||
* `'false'` to the key resolver and send the fallback at Google for real.
|
||||
*/
|
||||
function make(enabled = true) {
|
||||
const database = {
|
||||
get: vi.fn((sql: string) =>
|
||||
sql.includes('trek_places_enabled') && !enabled ? { value: 'false' } : undefined,
|
||||
),
|
||||
} as unknown as DatabaseService;
|
||||
trekPlaces.on = enabled;
|
||||
const database = { get: vi.fn(() => undefined) } as unknown as DatabaseService;
|
||||
return new MapsService(database, {} as PlacePhotoCacheService);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,22 @@ import { MapsService } from '../../../src/nest/maps/maps.service';
|
||||
import type { DatabaseService } from '../../../src/nest/database/database.service';
|
||||
import type { PlacePhotoCacheService } from '../../../src/nest/place-photos/place-photo-cache.service';
|
||||
|
||||
// The index switch is an environment variable now, not an admin row: it decides
|
||||
// whether a search leaves the instance at all, so it is pinned by the operator
|
||||
// rather than flippable from a browser. `setTrekPlaces()` below drives it.
|
||||
const trekPlaces = vi.hoisted(() => ({ on: true }));
|
||||
vi.mock('../../../src/app-config', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../../../src/app-config')>();
|
||||
return {
|
||||
...actual,
|
||||
readEnv: () => {
|
||||
const env = actual.readEnv();
|
||||
return { ...env, maps: { ...env.maps, trekPlacesEnabled: trekPlaces.on } };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
/** An index row, far enough from the OSM one below not to be deduped. */
|
||||
const indexHit = (name: string, lat = 35.31, lng = 139.53) => ({
|
||||
gers: name.toLowerCase().replace(/\W/g, ''),
|
||||
@@ -62,11 +78,8 @@ const osmAnswer = (rows: unknown[]) => ({ ok: true, json: async () => rows });
|
||||
* `'false'` to the API-key resolver, which would send the fallback at Google.
|
||||
*/
|
||||
function make(enabled = true) {
|
||||
const database = {
|
||||
get: vi.fn((sql: string) =>
|
||||
sql.includes('trek_places_enabled') && !enabled ? { value: 'false' } : undefined,
|
||||
),
|
||||
} as unknown as DatabaseService;
|
||||
trekPlaces.on = enabled;
|
||||
const database = { get: vi.fn(() => undefined) } as unknown as DatabaseService;
|
||||
return new MapsService(database, {} as PlacePhotoCacheService);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user