fix(offline): park a queued delete that a switched-off addon refuses

The 404 a route answers while its addon is off keeps the entity on the server, so
the queued delete is parked as failed and offered for retry instead of dropped.
This commit is contained in:
Maurice
2026-11-23 14:53:34 +01:00
parent fd10ce2876
commit 56ce66f666
2 changed files with 24 additions and 4 deletions
+7 -4
View File
@@ -248,6 +248,8 @@ const TEMP_REF_LISTS = ['orderedIds'] as const
// day, the walk or the stop (TripAccessGuard, TourVisitsService). Any other 404,
// the Tours addon turned off among them, fails like any other refusal.
const GONE_WALK_PARTS = new Set(['Trip not found', 'Assignment not found', 'City walk not found', 'Station not found'])
// The 404 of a route whose addon is off (AddonGuard, TripAddonGuard).
const ADDON_OFF = / addon is not enabled$/
/**
* The body with every link to an offline-created entity pointed at the real id
@@ -427,14 +429,15 @@ async function reconcileStationVisits(mutation: QueuedMutation, data: unknown, a
/**
* A 404 that means the write did what it set out to do: a DELETE of something
* the server no longer has, or a mark of a walk's stop whose stop, day, walk or
* trip is gone, since its visits went with it.
* trip is gone, since its visits went with it. An addon switched off for the
* trip or the instance keeps the entity, so that 404 is a refusal.
*/
function doneByNotFound(mutation: QueuedMutation, err: unknown): boolean {
if (mutation.method === 'DELETE') return true
if (mutation.resource !== 'tourStationVisits') return false
// Called on a 404 only, so the server answered.
const reason = (err as { response: { data?: { error?: unknown } } }).response.data?.error
return typeof reason === 'string' && GONE_WALK_PARTS.has(reason)
if (typeof reason === 'string' && ADDON_OFF.test(reason)) return false
if (mutation.method === 'DELETE') return true
return mutation.resource === 'tourStationVisits' && typeof reason === 'string' && GONE_WALK_PARTS.has(reason)
}
/** Visits, days, day notes, the trip itself and a walk's marks, each from the answer its route gives. */
@@ -561,6 +561,23 @@ describe('mutationQueue.flush: a write the server keeps failing on', () => {
expect(await offlineDb.places.get(5)).toBeUndefined();
expect(await mutationQueue.failedCount()).toBe(0);
});
it.each([
{ resource: 'packingItems', url: '/trips/1/packing/5', label: 'Packing' },
{ resource: 'budgetItems', url: '/trips/1/budget/5', label: 'Costs' },
{ resource: 'tripFiles', url: '/trips/1/files/5/permanent', label: 'Documents' },
{ resource: undefined, url: '/trips/1/files/trash/empty', label: 'Documents' },
])('parks a DELETE of $url that the $label addon being off refuses', async ({ resource, url, label }) => {
const id = generateUUID();
const entityId = resource ? 5 : undefined;
await mutationQueue.enqueue(makeMutation({ id, method: 'DELETE', url, body: undefined, resource, entityId }));
server.use(http.delete(`/api${url}`, () => HttpResponse.json({ error: `${label} addon is not enabled` }, { status: 404 })));
await mutationQueue.flush();
expect(await offlineDb.mutationQueue.get(id)).toMatchObject({ status: 'failed', attempts: 1 });
expect(await mutationQueue.failedCount()).toBe(1);
});
});
describe('mutationQueue: parked changes', () => {