Revalidate reminders synchronously after readiness yields

This commit is contained in:
syntaxbullet
2026-09-08 16:24:33 +02:00
parent 149ec36c77
commit 27beb01144
2 changed files with 55 additions and 30 deletions

View File

@@ -245,3 +245,23 @@ test('reminder catch-up yields and rechecks opt-out before claiming or sending',
expect(f.db.select().from(reminderDeliveries).all()).toHaveLength(0);
} finally { f.close(); }
});
test('an opt-out queued at readiness completion prevents the final reminder POST', async () => {
const { f } = await setup(); let posts = 0, evaluations = 0;
const { HabitService } = await import('../habits/service');
const original = HabitService.withPrepared;
const prepare = spyOn(HabitService, 'withPrepared').mockImplementation((db, user, now, run) => original(db, user, now, service => {
const result = run(service);
if (++evaluations === 2) queueMicrotask(() => f.db.update(reminderSettings).set({ enabled: false }).run());
return result;
}));
try {
await sendDueReminders(f.db, config, async url => {
if (!url.endsWith('/users/@me/channels')) posts++;
return Response.json({ id: '223456789012345678' });
}, () => Date.parse('2026-09-04T18:00:00Z'));
expect(evaluations).toBe(2);
expect(posts).toBe(0);
expect(f.db.select().from(reminderDeliveries).get()?.status).toBe('skipped');
} finally { prepare.mockRestore(); f.close(); }
});