tests: vault locking (#2394)

This commit is contained in:
Mo
2023-08-07 15:27:06 -05:00
committed by GitHub
parent a9edf671b1
commit 3b531ce8bb
23 changed files with 268 additions and 82 deletions

View File

@@ -1,16 +1,16 @@
import { GetVaultItems } from './../../Vault/UseCase/GetVaultItems'
import { SharedVaultListingInterface, VaultListingInterface, VaultListingMutator } from '@standardnotes/models'
import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses'
import { SharedVaultServerInterface } from '@standardnotes/api'
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
import { MoveItemsToVault } from '../../Vault/UseCase/MoveItemsToVault'
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
export class ConvertToSharedVault {
constructor(
private items: ItemManagerInterface,
private mutator: MutatorClientInterface,
private sharedVaultServer: SharedVaultServerInterface,
private moveItemsToVault: MoveItemsToVault,
private _moveItemsToVault: MoveItemsToVault,
private _getVaultItems: GetVaultItems,
) {}
async execute(dto: { vault: VaultListingInterface }): Promise<SharedVaultListingInterface | ClientDisplayableError> {
@@ -35,9 +35,9 @@ export class ConvertToSharedVault {
},
)
const vaultItems = this.items.itemsBelongingToKeySystem(sharedVaultListing.systemIdentifier)
const vaultItems = this._getVaultItems.execute(sharedVaultListing).getValue()
await this.moveItemsToVault.execute({ vault: sharedVaultListing, items: vaultItems })
await this._moveItemsToVault.execute({ vault: sharedVaultListing, items: vaultItems })
return sharedVaultListing as SharedVaultListingInterface
}

View File

@@ -1,3 +1,4 @@
import { GetVaultItems } from './../../Vault/UseCase/GetVaultItems'
import {
KeySystemRootKeyStorageMode,
SharedVaultListingInterface,
@@ -6,18 +7,17 @@ import {
} from '@standardnotes/models'
import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses'
import { SharedVaultServerInterface } from '@standardnotes/api'
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
import { CreateVault } from '../../Vault/UseCase/CreateVault'
import { MoveItemsToVault } from '../../Vault/UseCase/MoveItemsToVault'
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
export class CreateSharedVault {
constructor(
private items: ItemManagerInterface,
private mutator: MutatorClientInterface,
private sharedVaultServer: SharedVaultServerInterface,
private createVault: CreateVault,
private moveItemsToVault: MoveItemsToVault,
private _createVault: CreateVault,
private _moveItemsToVault: MoveItemsToVault,
private _getVaultItems: GetVaultItems,
) {}
async execute(dto: {
@@ -26,7 +26,7 @@ export class CreateSharedVault {
userInputtedPassword: string | undefined
storagePreference: KeySystemRootKeyStorageMode
}): Promise<SharedVaultListingInterface | ClientDisplayableError> {
const privateVault = await this.createVault.execute({
const privateVault = await this._createVault.execute({
vaultName: dto.vaultName,
vaultDescription: dto.vaultDescription,
userInputtedPassword: dto.userInputtedPassword,
@@ -50,9 +50,9 @@ export class CreateSharedVault {
},
)
const vaultItems = this.items.itemsBelongingToKeySystem(sharedVaultListing.systemIdentifier)
const vaultItems = this._getVaultItems.execute(sharedVaultListing).getValue()
await this.moveItemsToVault.execute({ vault: sharedVaultListing, items: vaultItems })
await this._moveItemsToVault.execute({ vault: sharedVaultListing, items: vaultItems })
return sharedVaultListing as SharedVaultListingInterface
}

View File

@@ -13,11 +13,7 @@ export class GetOwnedSharedVaults implements SyncUseCaseInterface<SharedVaultLis
const sharedVaults = this._getSharedVaults.execute().getValue()
const ownedVaults = sharedVaults.filter((vault) => {
return this._isVaultOwnwer
.execute({
sharedVault: vault,
})
.getValue()
return this._isVaultOwnwer.execute(vault).getValue()
})
return Result.ok(ownedVaults)

View File

@@ -28,7 +28,7 @@ export class SendVaultDataChangedMessage implements UseCaseInterface<void> {
) {}
async execute(params: { vault: SharedVaultListingInterface }): Promise<Result<void>> {
const isOwner = this._isVaultOwner.execute({ sharedVault: params.vault }).getValue()
const isOwner = this._isVaultOwner.execute(params.vault).getValue()
if (!isOwner) {
return Result.ok()
}