Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

test: await notification handlers before resetting the database

Tinf001d5e64b7d
diff --git a/tests/api-integration/notification-delivery-events.test.ts b/tests/api-integration/notification-delivery-events.test.ts
index e8614100c..f41738322 100644
--- a/tests/api-integration/notification-delivery-events.test.ts
+++ b/tests/api-integration/notification-delivery-events.test.ts
@@ -22,6 +22,17 @@ vi.mock("../../apps/api/src/utils/outbound-request", async (original) => ({
sendOutboundRequest: vi.fn(async () => new Response(null, { status: 200 })),
}));
+vi.mock("../../apps/api/src/events", async (original) => {
+ const events = await original<typeof import("../../apps/api/src/events")>();
+ return {
+ ...events,
+ // Delivery assertions and the next test's TRUNCATE must wait for every
+ // subscriber, including work that continues after the mocked HTTP send.
+ publishEvent: (...args: Parameters<typeof events.publishEvent>) =>
+ events.publishEvent(args[0], args[1], { waitForHandlers: true }),
+ };
+});
+
afterEach(() => vi.unstubAllEnvs());
beforeEach(async () => {
vi.stubEnv("NOTIFICATION_SECRET_ENCRYPTION_KEY", "notification-test-key");