fix(wanderer): offer the connection and run the watch where a trip switched Tours on

With Tours off for the instance, a trip that switched it on opened the wanderer
import, but Settings hid the connection and the watch cron never ran. The addon
feed now tells each user whether wanderer applies to them, and the watch looks
for every user who has Tours on somewhere; the others only take their turn.
This commit is contained in:
Maurice
2026-11-23 15:13:35 +01:00
parent c289541c43
commit 8b9de04960
6 changed files with 53 additions and 8 deletions
@@ -1,5 +1,6 @@
import { AddonsController } from '../../../src/nest/addons/addons.controller';
import type { AddonsService } from '../../../src/nest/addons/addons.service';
import type { User } from '../../../src/types';
import { describe, it, expect, vi } from 'vitest';
@@ -20,8 +21,8 @@ describe('AddonsController (parity with the legacy GET /api/addons route)', () =
const list = vi.fn().mockReturnValue(feed);
const svc = makeService({ list } as Partial<AddonsService>);
expect(await new AddonsController(svc).list()).toBe(feed);
expect(await new AddonsController(svc).list({ id: 4 } as User)).toBe(feed);
expect(list).toHaveBeenCalledTimes(1);
expect(list).toHaveBeenCalledWith();
expect(list).toHaveBeenCalledWith(4);
});
});
@@ -145,6 +145,18 @@ describe('TripAddonsService: routes without a trip', () => {
expect(await addons.isEnabledAnywhere('roadtrip')).toBe(true);
});
it('TRIPADDON-SVC-016: the feed offers wanderer to a user once a trip of theirs switched Tours on', async () => {
const { owner, trip } = await ownedTrip();
const { user: stranger } = await makeUser(orm());
await setAddonEnabled(orm(), 'tours', false);
await addons.updateToursWanderer(true);
expect((await addons.list(owner.id)).toursWanderer).toBe(false);
await svc.setTripOverride(trip.id, owner.id, 'tours', true);
expect((await addons.list(owner.id)).toursWanderer).toBe(true);
expect((await addons.list(stranger.id)).toursWanderer).toBe(false);
expect((await addons.list()).toursWanderer).toBe(false);
});
it('TRIPADDON-SVC-013: tripsWithAddon keeps the trips the addon applies to, in their order, each as isEnabledForTrip says', async () => {
const { owner, trip: off } = await ownedTrip();
const on = await makeTrip(orm(), owner.id);
@@ -18,7 +18,7 @@ import { WandererClient, WandererError } from '../../../src/nest/wanderer/wander
import { createSnapshotTestDb } from '../../helpers/db-mock';
import { makePlace } from '../../helpers/factories/places';
import { countRows, deleteRows, findRow, insertRow, updateRows } from '../../helpers/factories/rows';
import { setAddonEnabled, setAppSetting } from '../../helpers/factories/settings';
import { setAddonEnabled, setAppSetting, setTripAddon } from '../../helpers/factories/settings';
import { makeTour, makeTourSource } from '../../helpers/factories/tours';
import { makeTrip } from '../../helpers/factories/trips';
import { makeUser } from '../../helpers/factories/users';
@@ -129,6 +129,21 @@ describe('WandererWatchService.run', () => {
expect(await connection(user.id)).toMatchObject({ watch_last_run_at: null });
});
it('WWATCH-014: with Tours off for the instance, a user whose trip switched it on is watched, the others only take their turn', async () => {
await setAddonEnabled(orm(), 'tours', false);
const opened = await fixture();
const closed = await fixture();
await setTripAddon(orm(), opened.trip.id, 'tours', true);
await watch.run(NOW);
expect(client.trail).toHaveBeenCalledTimes(1);
expect(await hintRow(opened.placeId)).toMatchObject({ checked_at: '2026-10-20 10:00:00' });
expect(await hintRow(closed.placeId)).toBeNull();
expect(await connection(closed.user.id)).toMatchObject({
watch_last_run_at: '2026-10-20 10:00:00',
watch_failures: 0,
});
});
it('WWATCH-002: a record as imported writes a quiet look, tells nobody and never fetches a GPX', async () => {
const { user, placeId } = await fixture();
const before = await countRows(orm(), Places);