-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDeleteNotificationByUser.test.ts
More file actions
46 lines (40 loc) · 1.78 KB
/
Copy pathDeleteNotificationByUser.test.ts
File metadata and controls
46 lines (40 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { DeleteNotificationByUser } from '../../../src/notifications/domain/useCases/DeleteNotificationByUser'
import { INotificationsRepository } from '../../../src/notifications/domain/repositories/INotificationsRepository'
import { Notification } from '../../../src/notifications/domain/models/Notification'
const mockNotifications: Notification[] = [
{
id: 1,
type: 'PUBLISHEDDS',
subjectText: 'Test notification',
messageText: 'Test message',
sentTimestamp: '2025-01-01T00:00:00Z'
},
{
id: 2,
type: 'ASSIGNROLE',
subjectText: 'Role assignment',
messageText: 'Role assigned',
sentTimestamp: '2025-01-01T00:00:00Z'
}
]
describe('execute', () => {
test('should delete notification from repository', async () => {
const notificationsRepositoryStub: INotificationsRepository = {} as INotificationsRepository
notificationsRepositoryStub.getAllNotificationsByUser = jest.fn().mockResolvedValue([])
notificationsRepositoryStub.deleteNotificationByUser = jest
.fn()
.mockResolvedValue(mockNotifications)
const sut = new DeleteNotificationByUser(notificationsRepositoryStub)
await sut.execute(123)
expect(notificationsRepositoryStub.deleteNotificationByUser).toHaveBeenCalledWith(123)
})
test('should throw error when repository throws error', async () => {
const notificationsRepositoryStub: INotificationsRepository = {} as INotificationsRepository
notificationsRepositoryStub.getAllNotificationsByUser = jest.fn().mockResolvedValue([])
notificationsRepositoryStub.deleteNotificationByUser = jest
.fn()
.mockRejectedValue(new Error('Repository error'))
const sut = new DeleteNotificationByUser(notificationsRepositoryStub)
await expect(sut.execute(123)).rejects.toThrow('Repository error')
})
})