From e4993af909946338ac1f8eca3ab2c6e0f4ea978d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 6 Aug 2026 03:57:55 +0200 Subject: [PATCH] test: cover notification diagnostic attribution --- .../diagnostic/__tests__/route.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/api/admin/notifications/diagnostic/__tests__/route.test.ts b/src/app/api/admin/notifications/diagnostic/__tests__/route.test.ts index 8581ebece..59f1ec717 100644 --- a/src/app/api/admin/notifications/diagnostic/__tests__/route.test.ts +++ b/src/app/api/admin/notifications/diagnostic/__tests__/route.test.ts @@ -97,6 +97,8 @@ interface DiagnosticEnvelope { configPresent: boolean; }>; recentPushAttempts: Array<{ + recordUserId: string; + recipientUserId: string; eventType: string; channel: string; result: string; @@ -341,6 +343,8 @@ describe("GET /api/admin/notifications/diagnostic — recentPushAttempts", () => // mapping step normalises to an ISO string under `at`. vi.mocked(prisma.pushAttempt.findMany).mockResolvedValue([ { + recordUserId: "managed-record", + recipientUserId: ADMIN_USER_ID, eventType: "MEDICATION_REMINDER", channel: "APNS", result: "ok", @@ -348,6 +352,8 @@ describe("GET /api/admin/notifications/diagnostic — recentPushAttempts", () => createdAt: new Date("2026-05-22T09:00:00.000Z"), }, { + recordUserId: ADMIN_USER_ID, + recipientUserId: ADMIN_USER_ID, eventType: "MOOD_REMINDER", channel: "TELEGRAM", result: "error", @@ -362,6 +368,8 @@ describe("GET /api/admin/notifications/diagnostic — recentPushAttempts", () => expect(res.status).toBe(200); expect(body.data.recentPushAttempts).toEqual([ { + recordUserId: "managed-record", + recipientUserId: ADMIN_USER_ID, eventType: "MEDICATION_REMINDER", channel: "APNS", result: "ok", @@ -369,6 +377,8 @@ describe("GET /api/admin/notifications/diagnostic — recentPushAttempts", () => at: "2026-05-22T09:00:00.000Z", }, { + recordUserId: ADMIN_USER_ID, + recipientUserId: ADMIN_USER_ID, eventType: "MOOD_REMINDER", channel: "TELEGRAM", result: "error", @@ -386,11 +396,11 @@ describe("GET /api/admin/notifications/diagnostic — recentPushAttempts", () => expect(vi.mocked(prisma.pushAttempt.findMany)).toHaveBeenCalledTimes(1); const args = vi.mocked(prisma.pushAttempt.findMany).mock.calls[0]?.[0] as { - where: { userId: string }; + where: { recipientUserId: string }; orderBy: { createdAt: "desc" }; take: number; }; - expect(args.where.userId).toBe(ADMIN_USER_ID); + expect(args.where.recipientUserId).toBe(ADMIN_USER_ID); expect(args.orderBy).toEqual({ createdAt: "desc" }); expect(args.take).toBe(20); });