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:
Maurice
2026-11-23 15:42:09 +01:00
parent 5e8cc0b90a
commit 8349c5066b
4 changed files with 89 additions and 10 deletions
@@ -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', () => {