diff --git a/tests/smoke.test.cjs b/tests/smoke.test.cjs index e28fb93..a85a1d2 100644 --- a/tests/smoke.test.cjs +++ b/tests/smoke.test.cjs @@ -221,6 +221,8 @@ check('syncClient.ts passes the #151 push bounds to sendInBatches', () => { assert.match(merge, /size: BATCH_SIZE,/); assert.match(body('pushChanges'), /\.orderBy\(asc\(syncOutbox\.createdAt\)\)/); assert.match(body('pushChanges'), /classifyOutbox\(unsynced, results,/); + // Only the ids kept by classifyOutbox are marked, never the whole outbox. + assert.match(body('pushChanges'), /\.where\(inArray\(syncOutbox\.id, markIds\)\)/); // Number(null) is 0: a missing Retry-After must go through parseRetryAfter assert.match(src, /retryAfter: parseRetryAfter\(res\.headers\.get\('Retry-After'\)\)/); }); diff --git a/web/src/app/api/sync/route.test.ts b/web/src/app/api/sync/route.test.ts index 46f9c43..c90b828 100644 --- a/web/src/app/api/sync/route.test.ts +++ b/web/src/app/api/sync/route.test.ts @@ -525,4 +525,19 @@ describe('POST /api/sync: results contract (#151)', () => { expect(typeof result.error).toBe('string'); expect((result.error as string).length).toBeGreaterThan(0); }); + + it('answers a refused operation replayed with the same key skipped with an error again', async () => { + // The app replays a refusal with its outbox id as key. If the server + // remembered the key of a refused operation, the replay would come back + // `skipped` without `error` and the app would mark it synced: lost. + const { A, B } = await seed(); + const op = { idempotencyKey: u(), entityType: 'taskTag', action: 'create', entityId: A.task, data: { tagId: B.tag } }; + const [first] = await raw(B.userId, [op]); + expect(first.status).toBe('skipped'); + expect(typeof first.error).toBe('string'); + const [replay] = await raw(B.userId, [op]); + expect(replay.status).toBe('skipped'); + expect(typeof replay.error).toBe('string'); + expect((replay.error as string).length).toBeGreaterThan(0); + }); });