Refactor notification tests to improve assertions and add locale support

This commit is contained in:
MartinBraquet
2026-02-24 00:01:39 +01:00
parent b710fa9f60
commit 8decdab0c3
2 changed files with 6 additions and 8 deletions

View File

@@ -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,

View File

@@ -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),
)
})