Skip reminder habit evaluation for completed delivery slots
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { expect, test, spyOn } from "bun:test";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { fixture } from "../habits/test-fixture";
|
||||
import { reminderDeliveries, reminderSettings } from "../db/schema";
|
||||
@@ -213,3 +213,21 @@ test("messages include names only for the applicable reminders in the delivery b
|
||||
expect(JSON.parse(sent[1]!).allowed_mentions.parse).toEqual([]);
|
||||
} finally { f.close(); }
|
||||
});
|
||||
|
||||
|
||||
test('delivered slots skip habit evaluation while later slots and retries remain eligible', async () => {
|
||||
const { f } = await setup(); const sent: string[] = [];
|
||||
const { HabitService } = await import('../habits/service');
|
||||
let sync: ReturnType<typeof spyOn> | undefined;
|
||||
try {
|
||||
f.db.update(reminderSettings).set({ quietStart: '00:00', quietEnd: '00:00', reminders: [
|
||||
{ type: 'date', date: '2026-09-04', time: '10:00' }, { type: 'date', date: '2026-09-04', time: '12:00' },
|
||||
] }).run();
|
||||
const tick = (clock: string) => sendDueReminders(f.db, config, transport(sent), () => Date.parse(`2026-09-04T${clock}:00Z`));
|
||||
await tick('08:00'); expect(sent).toHaveLength(1);
|
||||
sync = spyOn(HabitService.prototype, 'sync');
|
||||
for (let i = 0; i < 5; i++) await tick('08:30');
|
||||
expect(sync).not.toHaveBeenCalled(); expect(sent).toHaveLength(1);
|
||||
await tick('10:00'); expect(sync).toHaveBeenCalled(); expect(sent).toHaveLength(2);
|
||||
} finally { sync?.mockRestore(); f.close(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user