import { mock, MockProxy } from "jest-mock-extended"; import { CollectionService } from "@bitwarden/common/admin-console/abstractions/collection.service"; import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction"; import { BitwardenPasswordProtectedImporter } from "../importers/bitwarden/bitwarden-password-protected-importer"; import { Importer } from "../importers/importer"; import { ImportApiServiceAbstraction } from "./import-api.service.abstraction"; import { ImportService } from "./import.service"; describe("ImportService", () => { let importService: ImportService; let cipherService: MockProxy; let folderService: MockProxy; let importApiService: MockProxy; let i18nService: MockProxy; let collectionService: MockProxy; let cryptoService: MockProxy; beforeEach(() => { cipherService = mock(); folderService = mock(); importApiService = mock(); i18nService = mock(); collectionService = mock(); cryptoService = mock(); importService = new ImportService( cipherService, folderService, importApiService, i18nService, collectionService, cryptoService ); }); describe("getImporterInstance", () => { describe("Get bitPasswordProtected importer", () => { let importer: Importer; const organizationId = Utils.newGuid(); const password = Utils.newGuid(); const promptForPassword_callback = async () => { return password; }; beforeEach(() => { importer = importService.getImporter( "bitwardenpasswordprotected", promptForPassword_callback, organizationId ); }); it("returns an instance of BitwardenPasswordProtectedImporter", () => { expect(importer).toBeInstanceOf(BitwardenPasswordProtectedImporter); }); it("has the promptForPassword_callback set", async () => { // Cast to any to access private property. Note: assumes instance of BitwardenPasswordProtectedImporter expect((importer as any).promptForPassword_callback).not.toBeNull(); expect(await (importer as any).promptForPassword_callback()).toEqual(password); }); it("has the appropriate organization Id", () => { expect(importer.organizationId).toEqual(organizationId); }); }); }); });