-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathGetAllNotificationsByUser.test.ts
More file actions
44 lines (38 loc) · 1.57 KB
/
Copy pathGetAllNotificationsByUser.test.ts
File metadata and controls
44 lines (38 loc) · 1.57 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
import { GetAllNotificationsByUser } from '../../../src/notifications/domain/useCases/GetAllNotificationsByUser'
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 return notifications from repository', async () => {
const notificationsRepositoryStub: INotificationsRepository = {} as INotificationsRepository
notificationsRepositoryStub.getAllNotificationsByUser = jest
.fn()
.mockResolvedValue(mockNotifications)
const sut = new GetAllNotificationsByUser(notificationsRepositoryStub)
const result = await sut.execute()
expect(result).toEqual(mockNotifications)
})
test('should throw error when repository throws error', async () => {
const notificationsRepositoryStub: INotificationsRepository = {} as INotificationsRepository
notificationsRepositoryStub.getAllNotificationsByUser = jest
.fn()
.mockRejectedValue(new Error('Repository error'))
const sut = new GetAllNotificationsByUser(notificationsRepositoryStub)
await expect(sut.execute()).rejects.toThrow('Repository error')
})
})