|
@@ -14,11 +14,13 @@ import { RemoveUserFromSharedVault } from './RemoveUserFromSharedVault'
|
|
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
|
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
|
import { DomainEventInterface, DomainEventPublisherInterface } from '@standardnotes/domain-events'
|
|
import { DomainEventInterface, DomainEventPublisherInterface } from '@standardnotes/domain-events'
|
|
import { AddNotificationsForUsers } from '../../Messaging/AddNotificationsForUsers/AddNotificationsForUsers'
|
|
import { AddNotificationsForUsers } from '../../Messaging/AddNotificationsForUsers/AddNotificationsForUsers'
|
|
|
|
+import { AddNotificationForUser } from '../../Messaging/AddNotificationForUser/AddNotificationForUser'
|
|
|
|
|
|
describe('RemoveUserFromSharedVault', () => {
|
|
describe('RemoveUserFromSharedVault', () => {
|
|
let sharedVaultRepository: SharedVaultRepositoryInterface
|
|
let sharedVaultRepository: SharedVaultRepositoryInterface
|
|
let sharedVaultUserRepository: SharedVaultUserRepositoryInterface
|
|
let sharedVaultUserRepository: SharedVaultUserRepositoryInterface
|
|
let addNotificationsForUsers: AddNotificationsForUsers
|
|
let addNotificationsForUsers: AddNotificationsForUsers
|
|
|
|
+ let addNotificationForUser: AddNotificationForUser
|
|
let sharedVault: SharedVault
|
|
let sharedVault: SharedVault
|
|
let sharedVaultUser: SharedVaultUser
|
|
let sharedVaultUser: SharedVaultUser
|
|
let domainEventFactory: DomainEventFactoryInterface
|
|
let domainEventFactory: DomainEventFactoryInterface
|
|
@@ -29,6 +31,7 @@ describe('RemoveUserFromSharedVault', () => {
|
|
sharedVaultUserRepository,
|
|
sharedVaultUserRepository,
|
|
sharedVaultRepository,
|
|
sharedVaultRepository,
|
|
addNotificationsForUsers,
|
|
addNotificationsForUsers,
|
|
|
|
+ addNotificationForUser,
|
|
domainEventFactory,
|
|
domainEventFactory,
|
|
domainEventPublisher,
|
|
domainEventPublisher,
|
|
)
|
|
)
|
|
@@ -56,6 +59,9 @@ describe('RemoveUserFromSharedVault', () => {
|
|
addNotificationsForUsers = {} as jest.Mocked<AddNotificationsForUsers>
|
|
addNotificationsForUsers = {} as jest.Mocked<AddNotificationsForUsers>
|
|
addNotificationsForUsers.execute = jest.fn().mockReturnValue(Result.ok())
|
|
addNotificationsForUsers.execute = jest.fn().mockReturnValue(Result.ok())
|
|
|
|
|
|
|
|
+ addNotificationForUser = {} as jest.Mocked<AddNotificationForUser>
|
|
|
|
+ addNotificationForUser.execute = jest.fn().mockReturnValue(Result.ok())
|
|
|
|
+
|
|
domainEventFactory = {} as jest.Mocked<DomainEventFactoryInterface>
|
|
domainEventFactory = {} as jest.Mocked<DomainEventFactoryInterface>
|
|
domainEventFactory.createUserRemovedFromSharedVaultEvent = jest
|
|
domainEventFactory.createUserRemovedFromSharedVaultEvent = jest
|
|
.fn()
|
|
.fn()
|
|
@@ -215,6 +221,19 @@ describe('RemoveUserFromSharedVault', () => {
|
|
expect(result.isFailed()).toBe(true)
|
|
expect(result.isFailed()).toBe(true)
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+ it('should return error if notification could not be added for the user removed', async () => {
|
|
|
|
+ addNotificationForUser.execute = jest.fn().mockResolvedValue(Result.fail('Could not add notification'))
|
|
|
|
+
|
|
|
|
+ const useCase = createUseCase()
|
|
|
|
+ const result = await useCase.execute({
|
|
|
|
+ originatorUuid: '00000000-0000-0000-0000-000000000000',
|
|
|
|
+ sharedVaultUuid: '00000000-0000-0000-0000-000000000000',
|
|
|
|
+ userUuid: '00000000-0000-0000-0000-000000000001',
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ expect(result.isFailed()).toBe(true)
|
|
|
|
+ })
|
|
|
|
+
|
|
it('should return error if notification payload could not be created', async () => {
|
|
it('should return error if notification payload could not be created', async () => {
|
|
const mock = jest.spyOn(NotificationPayload, 'create')
|
|
const mock = jest.spyOn(NotificationPayload, 'create')
|
|
mock.mockReturnValue(Result.fail('Oops'))
|
|
mock.mockReturnValue(Result.fail('Oops'))
|
|
@@ -231,4 +250,21 @@ describe('RemoveUserFromSharedVault', () => {
|
|
|
|
|
|
mock.mockRestore()
|
|
mock.mockRestore()
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ it('should return error if self notification payload could not be created', async () => {
|
|
|
|
+ const mock = jest.spyOn(NotificationPayload, 'create')
|
|
|
|
+ mock.mockReturnValueOnce(Result.ok()).mockReturnValueOnce(Result.fail('Oops'))
|
|
|
|
+
|
|
|
|
+ const useCase = createUseCase()
|
|
|
|
+ const result = await useCase.execute({
|
|
|
|
+ originatorUuid: '00000000-0000-0000-0000-000000000000',
|
|
|
|
+ sharedVaultUuid: '00000000-0000-0000-0000-000000000000',
|
|
|
|
+ userUuid: '00000000-0000-0000-0000-000000000001',
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ expect(result.isFailed()).toBe(true)
|
|
|
|
+ expect(result.getError()).toBe('Oops')
|
|
|
|
+
|
|
|
|
+ mock.mockRestore()
|
|
|
|
+ })
|
|
})
|
|
})
|