Skip to content

Commit 8decdab

Browse files
committed
Refactor notification tests to improve assertions and add locale support
1 parent b710fa9 commit 8decdab

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

backend/api/tests/unit/create-comment.unit.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ describe('createComment', () => {
116116
'new_endorsement',
117117
)
118118
expect(supabaseNotifications.insertNotificationToSupabase).toBeCalledTimes(1)
119-
expect(supabaseNotifications.insertNotificationToSupabase).toBeCalledWith(
120-
expect.any(Object),
121-
expect.any(Object),
122-
)
119+
expect(supabaseNotifications.insertNotificationToSupabase).toBeCalledWith(expect.any(Object))
123120
expect(emailHelpers.sendNewEndorsementEmail).toBeCalledTimes(1)
124121
expect(emailHelpers.sendNewEndorsementEmail).toBeCalledWith(
125122
mockOnUser,

backend/api/tests/unit/get-notifications.unit.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ describe('getNotifications', () => {
2323
const mockProps = {
2424
limit: 10,
2525
after: 2,
26+
locale: 'fr',
2627
}
2728
const mockAuth = {uid: '321'} as AuthedUser
2829
const mockReq = {} as any
29-
const mockNotifications = {} as any
30+
const mockNotifications = [] as any
3031

3132
;(mockPg.map as jest.Mock).mockResolvedValue(mockNotifications)
3233

3334
const result = await getNotifications(mockProps, mockAuth, mockReq)
3435

35-
expect(result).toBe(mockNotifications)
36+
expect(result).toEqual(mockNotifications)
3637
expect(mockPg.map).toBeCalledTimes(1)
3738
expect(mockPg.map).toBeCalledWith(
3839
sqlMatch(
39-
'from user_notifications un left join notification_templates nt on un.template_id = nt.id',
40+
'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',
4041
),
41-
[mockAuth.uid, mockProps.limit, mockProps.after],
42+
[mockAuth.uid, mockProps.limit, mockProps.after, mockProps.locale],
4243
expect.any(Function),
4344
)
4445
})

0 commit comments

Comments
 (0)