|
@@ -4,13 +4,21 @@ import { NotificationPayload, NotificationType, Result, Uuid } from '@standardno
|
|
import { NotificationRepositoryInterface } from '../../../Notifications/NotificationRepositoryInterface'
|
|
import { NotificationRepositoryInterface } from '../../../Notifications/NotificationRepositoryInterface'
|
|
import { Notification } from '../../../Notifications/Notification'
|
|
import { Notification } from '../../../Notifications/Notification'
|
|
import { AddNotificationForUser } from './AddNotificationForUser'
|
|
import { AddNotificationForUser } from './AddNotificationForUser'
|
|
|
|
+import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
|
|
|
+import { SendEventToClient } from '../../Syncing/SendEventToClient/SendEventToClient'
|
|
|
|
+import { NotificationAddedForUserEvent } from '@standardnotes/domain-events'
|
|
|
|
+import { Logger } from 'winston'
|
|
|
|
|
|
describe('AddNotificationForUser', () => {
|
|
describe('AddNotificationForUser', () => {
|
|
let notificationRepository: NotificationRepositoryInterface
|
|
let notificationRepository: NotificationRepositoryInterface
|
|
let timer: TimerInterface
|
|
let timer: TimerInterface
|
|
let payload: NotificationPayload
|
|
let payload: NotificationPayload
|
|
|
|
+ let domainEventFactory: DomainEventFactoryInterface
|
|
|
|
+ let sendEventToClientUseCase: SendEventToClient
|
|
|
|
+ let logger: Logger
|
|
|
|
|
|
- const createUseCase = () => new AddNotificationForUser(notificationRepository, timer)
|
|
|
|
|
|
+ const createUseCase = () =>
|
|
|
|
+ new AddNotificationForUser(notificationRepository, timer, domainEventFactory, sendEventToClientUseCase, logger)
|
|
|
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
notificationRepository = {} as jest.Mocked<NotificationRepositoryInterface>
|
|
notificationRepository = {} as jest.Mocked<NotificationRepositoryInterface>
|
|
@@ -24,6 +32,17 @@ describe('AddNotificationForUser', () => {
|
|
type: NotificationType.create(NotificationType.TYPES.RemovedFromSharedVault).getValue(),
|
|
type: NotificationType.create(NotificationType.TYPES.RemovedFromSharedVault).getValue(),
|
|
version: '1.0',
|
|
version: '1.0',
|
|
}).getValue()
|
|
}).getValue()
|
|
|
|
+
|
|
|
|
+ domainEventFactory = {} as jest.Mocked<DomainEventFactoryInterface>
|
|
|
|
+ domainEventFactory.createNotificationAddedForUserEvent = jest.fn().mockReturnValue({
|
|
|
|
+ type: 'NOTIFICATION_ADDED_FOR_USER',
|
|
|
|
+ } as jest.Mocked<NotificationAddedForUserEvent>)
|
|
|
|
+
|
|
|
|
+ sendEventToClientUseCase = {} as jest.Mocked<SendEventToClient>
|
|
|
|
+ sendEventToClientUseCase.execute = jest.fn().mockReturnValue(Result.ok())
|
|
|
|
+
|
|
|
|
+ logger = {} as jest.Mocked<Logger>
|
|
|
|
+ logger.error = jest.fn()
|
|
})
|
|
})
|
|
|
|
|
|
it('should save notification', async () => {
|
|
it('should save notification', async () => {
|
|
@@ -84,4 +103,20 @@ describe('AddNotificationForUser', () => {
|
|
|
|
|
|
mock.mockRestore()
|
|
mock.mockRestore()
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ it('should log error if event could not be sent to client', async () => {
|
|
|
|
+ sendEventToClientUseCase.execute = jest.fn().mockReturnValue(Result.fail('Oops'))
|
|
|
|
+
|
|
|
|
+ const useCase = createUseCase()
|
|
|
|
+
|
|
|
|
+ const result = await useCase.execute({
|
|
|
|
+ userUuid: '0e8c3c7e-3f1a-4f7a-9b5a-5b2b0a7d4b1e',
|
|
|
|
+ type: NotificationType.TYPES.RemovedFromSharedVault,
|
|
|
|
+ payload,
|
|
|
|
+ version: '1.0',
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ expect(result.isFailed()).toBeFalsy()
|
|
|
|
+ expect(logger.error).toHaveBeenCalled()
|
|
|
|
+ })
|
|
})
|
|
})
|