|
| 1 | +import { makeNotification } from '@test/factories/notification-factory'; |
| 2 | +import { InMemoryNotificationsRepository } from '../../../test/repositories/in-memory-notifications-repository'; |
| 3 | +import { NotificationNotFound } from './errors/notification-not-found'; |
| 4 | +import { UnreadNotification } from './unread-notification'; |
| 5 | + |
| 6 | +describe('Unread notification', () => { |
| 7 | + it('should be able to unread a notification', async () => { |
| 8 | + const notificationsRepository = new InMemoryNotificationsRepository(); |
| 9 | + const unreadNotification = new UnreadNotification(notificationsRepository); |
| 10 | + |
| 11 | + // para eu conseguir marcar uma notificação como não lida, ela precisa estar |
| 12 | + // como lida antes |
| 13 | + const notification = makeNotification({ |
| 14 | + readAt: new Date(), |
| 15 | + }); |
| 16 | + |
| 17 | + await notificationsRepository.create(notification); |
| 18 | + |
| 19 | + await unreadNotification.execute({ |
| 20 | + notificationId: notification.id, |
| 21 | + }); |
| 22 | + |
| 23 | + expect(notificationsRepository.notifications[0].readAt).toBeNull(); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should not be able to unread a non existing notification', async () => { |
| 27 | + const notificationsRepository = new InMemoryNotificationsRepository(); |
| 28 | + const unreadNotification = new UnreadNotification(notificationsRepository); |
| 29 | + |
| 30 | + expect(() => { |
| 31 | + return unreadNotification.execute({ |
| 32 | + notificationId: 'fake-notification-id', |
| 33 | + }); // por conta de ser uma Promise, o rejects quer dizer que deu erro |
| 34 | + }).rejects.toThrow(NotificationNotFound); |
| 35 | + }); |
| 36 | +}); |
0 commit comments