mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
fix(dawarich): name stays never read before reading unnamed ones again
Unnamed stays are now read again at the end of a run, from the budget the others left and at most 20 per window, so new stays get their names and a Dawarich without a geocoder is not asked about every stay on each run.
This commit is contained in:
@@ -355,6 +355,18 @@ describe('DawarichVisitSuggestionsRepository', () => {
|
||||
last_seen_at: '2026-03-01T00:00:00Z',
|
||||
});
|
||||
});
|
||||
|
||||
it('DVSREPO-033: renameNewVisit names a stay nobody acted on, and leaves an accepted one as it is', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const fresh = await seed(user.id, { source_visit_id: 'a', name: 'Unnamed stay' });
|
||||
const accepted = await seed(user.id, { source_visit_id: 'b', name: 'Mine', state: 'accepted' });
|
||||
|
||||
await suggestions.renameNewVisit(fresh, 'Cinisi, Italy');
|
||||
await suggestions.renameNewVisit(accepted, 'Cinisi, Italy');
|
||||
|
||||
expect(await rawRow(fresh)).toMatchObject({ name: 'Cinisi, Italy', state: 'new' });
|
||||
expect(await rawRow(accepted)).toMatchObject({ name: 'Mine', state: 'accepted' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('listCandidatesForWindow/deleteById/stampMissingIfUnset (DSY7/DSY8/DSY9)', () => {
|
||||
|
||||
@@ -368,6 +368,34 @@ describe('DawarichSyncService, naming a stay Dawarich sends without a name (#310
|
||||
expect(listGeocodedPoints).toHaveBeenCalledTimes(listVisits.mock.calls.length);
|
||||
expect((await rows()).map((r) => r.name)).toEqual(['Unknown Location', 'Unknown Location', 'Unknown Location']);
|
||||
});
|
||||
|
||||
it('DAWARICH-SYNC-096: a stay never read is named before unnamed stays are read again, and those only a few per run', async () => {
|
||||
const unnamed = Array.from({ length: 25 }, (_, i) => nameless(1000 + i));
|
||||
withVisits(...unnamed);
|
||||
await svc.syncUser(USER);
|
||||
expect((await rows()).every((r) => r.name === 'Unnamed stay')).toBe(true);
|
||||
|
||||
const fresh = visit({
|
||||
id: 1100,
|
||||
name: 'Unknown Location',
|
||||
place: null,
|
||||
started_at: `${VISIT_DAY}T15:00:00Z`,
|
||||
ended_at: `${VISIT_DAY}T17:00:00Z`,
|
||||
});
|
||||
withVisits(...unnamed, fresh);
|
||||
listVisits.mockClear();
|
||||
listGeocodedPoints
|
||||
.mockReset()
|
||||
.mockImplementation(async (_creds: DawarichCreds, from: Date) =>
|
||||
from.toISOString().startsWith(`${VISIT_DAY}T15:00`) ? [{ city: 'Cinisi', country_name: 'Italy' }] : [],
|
||||
);
|
||||
await svc.syncUser(USER);
|
||||
|
||||
const firstAsked = (listGeocodedPoints.mock.calls[0] as [DawarichCreds, Date, Date])[1];
|
||||
expect(firstAsked.toISOString()).toBe(`${VISIT_DAY}T15:00:00.000Z`);
|
||||
expect(listGeocodedPoints).toHaveBeenCalledTimes(21 * listVisits.mock.calls.length);
|
||||
expect((await rows()).find((r) => r.source_visit_id === '1100')?.name).toBe('Cinisi, Italy');
|
||||
});
|
||||
});
|
||||
|
||||
describe('DawarichSyncService — new visits', () => {
|
||||
|
||||
Reference in New Issue
Block a user