Skip to content

Commit de95d37

Browse files
committed
fix on tests
1 parent 541e892 commit de95d37

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

src/notifications/domain/useCases/GetUnreadCount.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export class GetUnreadCount implements UseCase<number> {
88
this.notificationsRepository = notificationsRepository
99
}
1010

11+
/**
12+
* Use case for retrieving the number of unread notifications for the current user.
13+
*
14+
* @returns {Promise<number>} - A promise that resolves to the number of unread notifications.
15+
*/
1116
async execute(): Promise<number> {
1217
return await this.notificationsRepository.getUnreadCount()
1318
}

src/notifications/domain/useCases/MarkAsRead.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export class MarkAsRead implements UseCase<void> {
88
this.notificationsRepository = notificationsRepository
99
}
1010

11+
/**
12+
* Use case for marking a notification as read.
13+
*
14+
* @param notificationId - The ID of the notification to mark as read.
15+
* @returns {Promise<void>} - A promise that resolves when the notification is marked as read.
16+
*/
1117
async execute(notificationId: number): Promise<void> {
1218
return await this.notificationsRepository.markAsRead(notificationId)
1319
}

test/functional/notifications/GetUnreadCount.test.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/functional/notifications/MarkAsRead.test.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/integration/notifications/NotificationsRepository.test.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ describe('NotificationsRepository', () => {
7373
test('should throw error when trying to delete notification with wrong ID', async () => {
7474
const nonExistentNotificationId = 99999
7575

76-
const expectedError = new WriteError()
76+
const expectedError = new WriteError(
77+
`[404] Notification ${nonExistentNotificationId} not found.`
78+
)
7779

7880
await expect(sut.deleteNotification(nonExistentNotificationId)).rejects.toThrow(expectedError)
7981
})
@@ -84,18 +86,28 @@ describe('NotificationsRepository', () => {
8486
const notification = notifications[0]
8587
expect(notification).toHaveProperty('id')
8688
expect(notification).toHaveProperty('type')
87-
expect(notification.type).toBe(NotificationType.ASSIGNROLE)
8889
expect(notification).toHaveProperty('sentTimestamp')
8990
expect(notification).toHaveProperty('displayAsRead')
90-
expect(notification).toHaveProperty('dataverseDisplayName')
91-
92-
expect(notification).toHaveProperty('roleAssignments')
93-
expect(notification.roleAssignments).toBeDefined()
94-
expect(notification.roleAssignments?.length).toBeGreaterThan(0)
95-
expect(notification.roleAssignments?.[0]).toHaveProperty('roleName')
96-
expect(notification.roleAssignments?.[0]).toHaveProperty('assignee')
97-
expect(notification.roleAssignments?.[0]).toHaveProperty('roleId')
98-
expect(notification.roleAssignments?.[0]).toHaveProperty('definitionPointId')
91+
})
92+
93+
test('should find notification with ASSIGNROLE type', async () => {
94+
const notifications: Notification[] = await sut.getAllNotificationsByUser(true)
95+
96+
// Find a notification with ASSIGNROLE type
97+
const assignRoleNotification = notifications.find((n) => n.type === NotificationType.ASSIGNROLE)
98+
99+
expect(assignRoleNotification).toBeDefined()
100+
expect(assignRoleNotification?.type).toBe(NotificationType.ASSIGNROLE)
101+
expect(assignRoleNotification?.sentTimestamp).toBeDefined()
102+
expect(assignRoleNotification?.displayAsRead).toBeDefined()
103+
expect(assignRoleNotification?.dataverseDisplayName).toBeDefined()
104+
105+
expect(assignRoleNotification?.roleAssignments).toBeDefined()
106+
expect(assignRoleNotification?.roleAssignments?.length).toBeGreaterThan(0)
107+
expect(assignRoleNotification?.roleAssignments?.[0]).toHaveProperty('roleName')
108+
expect(assignRoleNotification?.roleAssignments?.[0]).toHaveProperty('assignee')
109+
expect(assignRoleNotification?.roleAssignments?.[0]).toHaveProperty('roleId')
110+
expect(assignRoleNotification?.roleAssignments?.[0]).toHaveProperty('definitionPointId')
99111
})
100112

101113
test('should return array when inAppNotificationFormat is false', async () => {
@@ -107,7 +119,6 @@ describe('NotificationsRepository', () => {
107119
test('should return unread count', async () => {
108120
const unreadCount = await sut.getUnreadCount()
109121

110-
console.log('unreadCount', unreadCount)
111122
expect(typeof unreadCount).toBe('number')
112123
expect(unreadCount).toBeGreaterThanOrEqual(0)
113124
})

0 commit comments

Comments
 (0)