tests: vault tests 3 (#2373)

This commit is contained in:
Mo
2023-07-27 07:35:38 -05:00
committed by GitHub
parent 1fef36d601
commit 14bae5e895
26 changed files with 350 additions and 283 deletions

View File

@@ -119,6 +119,7 @@ import {
DeleteContact,
VaultLockService,
RemoveItemsFromMemory,
ReencryptTypeAItems,
} from '@standardnotes/services'
import { ItemManager } from '../../Services/Items/ItemManager'
import { PayloadManager } from '../../Services/Payloads/PayloadManager'
@@ -202,6 +203,10 @@ export class Dependencies {
}
private registerUseCaseMakers() {
this.factory.set(TYPES.ReencryptTypeAItems, () => {
return new ReencryptTypeAItems(this.get(TYPES.ItemManager), this.get(TYPES.MutatorService))
})
this.factory.set(TYPES.ImportDataUseCase, () => {
return new ImportDataUseCase(
this.get(TYPES.ItemManager),
@@ -616,10 +621,9 @@ export class Dependencies {
return new RootKeyManager(
this.get(TYPES.DeviceInterface),
this.get(TYPES.DiskStorageService),
this.get(TYPES.ItemManager),
this.get(TYPES.MutatorService),
this.get(TYPES.EncryptionOperators),
this.options.identifier,
this.get(TYPES.ReencryptTypeAItems),
this.get(TYPES.InternalEventBus),
)
})
@@ -1086,6 +1090,7 @@ export class Dependencies {
this.get(TYPES.ChallengeService),
this.get(TYPES.ProtectionService),
this.get(TYPES.UserApiService),
this.get(TYPES.ReencryptTypeAItems),
this.get(TYPES.InternalEventBus),
)
})

View File

@@ -151,6 +151,7 @@ export const TYPES = {
DecryptBackupFile: Symbol.for('DecryptBackupFile'),
IsVaultOwner: Symbol.for('IsVaultOwner'),
RemoveItemsFromMemory: Symbol.for('RemoveItemsFromMemory'),
ReencryptTypeAItems: Symbol.for('ReencryptTypeAItems'),
// Mappers
SessionStorageMapper: Symbol.for('SessionStorageMapper'),

View File

@@ -14,7 +14,6 @@ export class Migration2_202_1 extends Migration {
this.registerStageHandler(ApplicationStage.FullSyncCompleted_13, async () => {
await this.migrateComponentDataToUserPreferences()
await this.migrateActiveComponentsToUserPreferences()
await this.deleteComponentsWhichAreNativeFeatures()
this.markDone()
})
@@ -70,29 +69,4 @@ export class Migration2_202_1 extends Migration {
await this.services.preferences.setValueDetached(PrefKey.ActiveThemes, Uuids(activeThemes))
await this.services.preferences.setValueDetached(PrefKey.ActiveComponents, Uuids(activeComponents))
}
private async deleteComponentsWhichAreNativeFeatures(): Promise<void> {
const componentsToDelete = [
...this.services.itemManager.getItems<ComponentInterface>(ContentType.TYPES.Component),
...this.services.itemManager.getItems<ComponentInterface>(ContentType.TYPES.Theme),
].filter((candidate) => {
const nativeFeature = FindNativeFeature(candidate.identifier)
if (!nativeFeature) {
return false
}
const isDeprecatedAndThusShouldNotDeleteComponentSinceUserHasItRetained = nativeFeature.deprecated
if (isDeprecatedAndThusShouldNotDeleteComponentSinceUserHasItRetained) {
return false
}
return true
})
if (componentsToDelete.length === 0) {
return
}
await this.services.mutator.setItemsToBeDeleted(componentsToDelete)
}
}

View File

@@ -286,13 +286,11 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt
/**
* Imports an array of payloads from an external source (such as a backup file)
* and marks the items as dirty.
* @returns Resulting items
*/
public async importPayloads(payloads: DecryptedPayloadInterface[], historyMap: HistoryMap): Promise<string[]> {
public async importPayloads(payloads: FullyFormedPayloadInterface[], historyMap: HistoryMap): Promise<string[]> {
const sourcedPayloads = payloads.map((p) => p.copy(undefined, PayloadSource.FileImport))
const delta = new DeltaFileImport(this.getMasterCollection(), sourcedPayloads, historyMap)
const emit = delta.result()
await this.emitDeltaEmit(emit)