⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
test(reminders): verify rollback after real notification writes
Tinb1297f67ed33
diff --git a/tests/api-integration/reminder-atomicity.test.ts b/tests/api-integration/reminder-atomicity.test.tsindex 9a9ff5bd5..7bf2bbbe2 100644--- a/tests/api-integration/reminder-atomicity.test.ts+++ b/tests/api-integration/reminder-atomicity.test.ts@@ -9,15 +9,18 @@ vi.mock(>();return {...actual,- persistNotification: (+ persistNotification: async (...args: Parameters<typeof actual.persistNotification>) => {- if (m.fail) throw new Error("temporary notification failure");- return actual.persistNotification(...args);+ const notification = await actual.persistNotification(...args);+ if (m.fail)+ throw new Error("temporary notification failure after insert");+ return notification;},};},);+import { sql } from "drizzle-orm";import db, { schema } from "../../apps/api/src/database";import { checkDueDateReminders } from "../../apps/api/src/scheduler/due-date-reminders";import { DUE_DATE_DURATION_MS } from "../../apps/api/src/scheduler/reminder-timing";@@ -28,7 +31,7 @@ import {} from "./helpers/fixtures";beforeEach(resetTestDatabase);-it("rolls back the reminder claim when notification creation fails, then retries once", async () => {+async function createReminderTask() {const { workspace, user } = await createWorkspaceMember();const { project, columns } = await createProjectFixture({workspaceId: workspace.id,@@ -42,6 +45,10 @@ it("rolls back the reminder claim when notification creation fails, then retriesnumber: 1,dueDate: new Date(Date.now() + (1440 - 5) * 60000 - DUE_DATE_DURATION_MS),});+}++it("rolls back both writes after a successful notification insert, then retries once", async () => {+ await createReminderTask();m.fail = true;expect(await checkDueDateReminders()).toEqual({ degraded: true });expect(await db.select().from(schema.taskReminderSentTable)).toHaveLength(0);@@ -52,3 +59,29 @@ it("rolls back the reminder claim when notification creation fails, then retriesexpect(await db.select().from(schema.taskReminderSentTable)).toHaveLength(1);expect(await db.select().from(schema.notificationTable)).toHaveLength(1);});++it("releases the reminder claim after PostgreSQL rejects the notification insert", async () => {+ await createReminderTask();+ m.fail = false;+ await db.execute(sql`CREATE FUNCTION reject_reminder_notification() RETURNS trigger AS $$+ BEGIN RAISE EXCEPTION 'test notification insert failure'; END;+ $$ LANGUAGE plpgsql`);+ await db.execute(sql`CREATE TRIGGER reject_reminder_notification BEFORE INSERT ON notification+ FOR EACH ROW EXECUTE FUNCTION reject_reminder_notification()`);+ try {+ expect(await checkDueDateReminders()).toEqual({ degraded: true });+ expect(await db.select().from(schema.taskReminderSentTable)).toHaveLength(+ 0,+ );+ expect(await db.select().from(schema.notificationTable)).toHaveLength(0);+ } finally {+ await db.execute(+ sql`DROP TRIGGER reject_reminder_notification ON notification`,+ );+ await db.execute(sql`DROP FUNCTION reject_reminder_notification()`);+ }+ expect(await checkDueDateReminders()).toEqual({ degraded: false });+ await checkDueDateReminders();+ expect(await db.select().from(schema.taskReminderSentTable)).toHaveLength(1);+ expect(await db.select().from(schema.notificationTable)).toHaveLength(1);+});