From 8decdab0c361621fd339fa0761b59831bda00d71 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Tue, 24 Feb 2026 00:01:39 +0100 Subject: [PATCH] Refactor notification tests to improve assertions and add locale support --- backend/api/tests/unit/create-comment.unit.test.ts | 5 +---- backend/api/tests/unit/get-notifications.unit.test.ts | 9 +++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/api/tests/unit/create-comment.unit.test.ts b/backend/api/tests/unit/create-comment.unit.test.ts index 8b2a414a..bace89ef 100644 --- a/backend/api/tests/unit/create-comment.unit.test.ts +++ b/backend/api/tests/unit/create-comment.unit.test.ts @@ -116,10 +116,7 @@ describe('createComment', () => { 'new_endorsement', ) expect(supabaseNotifications.insertNotificationToSupabase).toBeCalledTimes(1) - expect(supabaseNotifications.insertNotificationToSupabase).toBeCalledWith( - expect.any(Object), - expect.any(Object), - ) + expect(supabaseNotifications.insertNotificationToSupabase).toBeCalledWith(expect.any(Object)) expect(emailHelpers.sendNewEndorsementEmail).toBeCalledTimes(1) expect(emailHelpers.sendNewEndorsementEmail).toBeCalledWith( mockOnUser, diff --git a/backend/api/tests/unit/get-notifications.unit.test.ts b/backend/api/tests/unit/get-notifications.unit.test.ts index 4281200f..accf3948 100644 --- a/backend/api/tests/unit/get-notifications.unit.test.ts +++ b/backend/api/tests/unit/get-notifications.unit.test.ts @@ -23,22 +23,23 @@ describe('getNotifications', () => { const mockProps = { limit: 10, after: 2, + locale: 'fr', } const mockAuth = {uid: '321'} as AuthedUser const mockReq = {} as any - const mockNotifications = {} as any + const mockNotifications = [] as any ;(mockPg.map as jest.Mock).mockResolvedValue(mockNotifications) const result = await getNotifications(mockProps, mockAuth, mockReq) - expect(result).toBe(mockNotifications) + expect(result).toEqual(mockNotifications) expect(mockPg.map).toBeCalledTimes(1) expect(mockPg.map).toBeCalledWith( sqlMatch( - 'from user_notifications un left join notification_templates nt on un.template_id = nt.id', + 'from user_notifications un left join notification_templates nt on un.template_id = nt.id left join notification_template_translations ntt on nt.id = ntt.template_id and ntt.locale = $4', ), - [mockAuth.uid, mockProps.limit, mockProps.after], + [mockAuth.uid, mockProps.limit, mockProps.after, mockProps.locale], expect.any(Function), ) })