tests: vaults (#2365)

* tests: signature tests

* tests: asymmetric

* feat: delete contact use case

* chore: lint

* chore: lint
This commit is contained in:
Mo
2023-07-24 14:28:28 -05:00
committed by GitHub
parent d6bcc808d5
commit 98c0228139
40 changed files with 649 additions and 145 deletions

View File

@@ -0,0 +1,45 @@
import { ContactBelongsToVault } from './../../SharedVaults/UseCase/ContactBelongsToVault'
import { GetOwnedSharedVaults } from './../../SharedVaults/UseCase/GetOwnedSharedVaults'
import { SyncServiceInterface } from './../../Sync/SyncServiceInterface'
import { MutatorClientInterface } from './../../Mutator/MutatorClientInterface'
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
import { TrustedContactInterface } from '@standardnotes/models'
export class DeleteContact implements UseCaseInterface<void> {
constructor(
private mutator: MutatorClientInterface,
private sync: SyncServiceInterface,
private getOwnedVaults: GetOwnedSharedVaults,
private contactBelongsToVault: ContactBelongsToVault,
) {}
async execute(dto: { contact: TrustedContactInterface; ownUserUuid: string }): Promise<Result<void>> {
if (dto.contact.isMe) {
throw new Error('Cannot delete self')
}
const vaults = this.getOwnedVaults.execute({ userUuid: dto.ownUserUuid })
if (vaults.isFailed()) {
return Result.fail('Failed to get owned vaults')
}
for (const vault of vaults.getValue()) {
const contactBelongsToVault = await this.contactBelongsToVault.execute({
contact: dto.contact,
vault: vault,
})
if (contactBelongsToVault.isFailed()) {
return Result.fail('Failed to check contact membership')
}
if (contactBelongsToVault.getValue()) {
return Result.fail('Cannot delete contact that belongs to an owned vault')
}
}
await this.mutator.setItemToBeDeleted(dto.contact)
await this.sync.sync()
return Result.ok()
}
}