1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 11:13:46 +00:00
Files
browser/libs/importer/src/services/import.service.spec.ts
Matt Gibson 78248db590 Platform/pm 19/platform team file moves (#5460)
* Rename service-factory folder

* Move cryptographic service factories

* Move crypto models

* Move crypto services

* Move domain base class

* Platform code owners

* Move desktop log services

* Move log files

* Establish component library ownership

* Move background listeners

* Move background background

* Move localization to Platform

* Move browser alarms to Platform

* Move browser state to Platform

* Move CLI state to Platform

* Move Desktop native concerns to Platform

* Move flag and misc to Platform

* Lint fixes

* Move electron state to platform

* Move web state to Platform

* Move lib state to Platform

* Fix broken tests

* Rename interface to idiomatic TS

* `npm run prettier` 🤖

* Resolve review feedback

* Set platform as owners of web core and shared

* Expand moved services

* Fix test types

---------

Co-authored-by: Hinton <hinton@users.noreply.github.com>
2023-06-06 15:34:53 -05:00

76 lines
2.8 KiB
TypeScript

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<CipherService>;
let folderService: MockProxy<FolderService>;
let importApiService: MockProxy<ImportApiServiceAbstraction>;
let i18nService: MockProxy<I18nService>;
let collectionService: MockProxy<CollectionService>;
let cryptoService: MockProxy<CryptoService>;
beforeEach(() => {
cipherService = mock<CipherService>();
folderService = mock<FolderService>();
importApiService = mock<ImportApiServiceAbstraction>();
i18nService = mock<I18nService>();
collectionService = mock<CollectionService>();
cryptoService = mock<CryptoService>();
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);
});
});
});
});