Revalidate reminders synchronously after readiness yields
This commit is contained in:
@@ -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(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user