RemoveNotificationsForUser.spec.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {
  2. NotificationPayload,
  3. NotificationPayloadIdentifierType,
  4. NotificationType,
  5. Timestamps,
  6. Uuid,
  7. } from '@standardnotes/domain-core'
  8. import { NotificationRepositoryInterface } from '../../../Notifications/NotificationRepositoryInterface'
  9. import { RemoveNotificationsForUser } from './RemoveNotificationsForUser'
  10. import { Notification } from '../../../Notifications/Notification'
  11. describe('RemoveNotificationsForUser', () => {
  12. let notificationRepository: NotificationRepositoryInterface
  13. let notification: Notification
  14. const createUseCase = () => new RemoveNotificationsForUser(notificationRepository)
  15. beforeEach(() => {
  16. notification = Notification.create({
  17. userUuid: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
  18. type: NotificationType.create(NotificationType.TYPES.SharedVaultItemRemoved).getValue(),
  19. payload: NotificationPayload.create({
  20. primaryIdentifier: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
  21. primaryIndentifierType: NotificationPayloadIdentifierType.create(
  22. NotificationPayloadIdentifierType.TYPES.SharedVaultUuid,
  23. ).getValue(),
  24. secondaryIdentifier: Uuid.create('00000000-0000-0000-0000-000000000000').getValue(),
  25. secondaryIdentifierType: NotificationPayloadIdentifierType.create(
  26. NotificationPayloadIdentifierType.TYPES.ItemUuid,
  27. ).getValue(),
  28. type: NotificationType.create(NotificationType.TYPES.SharedVaultItemRemoved).getValue(),
  29. version: '1.0',
  30. }).getValue(),
  31. timestamps: Timestamps.create(123, 123).getValue(),
  32. }).getValue()
  33. notificationRepository = {} as jest.Mocked<NotificationRepositoryInterface>
  34. notificationRepository.findByUserUuidAndType = jest.fn().mockResolvedValue([notification])
  35. notificationRepository.remove = jest.fn()
  36. })
  37. it('should remove notifications for user', async () => {
  38. const useCase = createUseCase()
  39. const result = await useCase.execute({
  40. userUuid: '00000000-0000-0000-0000-000000000000',
  41. type: NotificationType.TYPES.SharedVaultItemRemoved,
  42. })
  43. expect(result.isFailed()).toBeFalsy()
  44. expect(notificationRepository.remove).toHaveBeenCalledWith(notification)
  45. })
  46. it('should fail if user uuid is invalid', async () => {
  47. const useCase = createUseCase()
  48. const result = await useCase.execute({
  49. userUuid: 'invalid',
  50. type: NotificationType.TYPES.SharedVaultItemRemoved,
  51. })
  52. expect(result.isFailed()).toBeTruthy()
  53. })
  54. it('should fail if notification type is invalid', async () => {
  55. const useCase = createUseCase()
  56. const result = await useCase.execute({
  57. userUuid: '00000000-0000-0000-0000-000000000000',
  58. type: 'invalid',
  59. })
  60. expect(result.isFailed()).toBeTruthy()
  61. })
  62. })