1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-30 08:10:34 +01:00
bitwarden-browser/libs/common/spec/services/import.service.spec.ts

73 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-02-22 15:39:11 +01:00
import Substitute, { SubstituteOf } from "@fluffy-spoon/substitute";
2022-06-14 17:10:53 +02:00
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
2022-06-14 17:10:53 +02:00
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { BitwardenPasswordProtectedImporter } from "@bitwarden/common/importers/bitwardenPasswordProtectedImporter";
import { Importer } from "@bitwarden/common/importers/importer";
import { Utils } from "@bitwarden/common/misc/utils";
import { ImportService } from "@bitwarden/common/services/import.service";
describe("ImportService", () => {
let importService: ImportService;
let cipherService: SubstituteOf<CipherService>;
let folderService: SubstituteOf<FolderService>;
let apiService: SubstituteOf<ApiService>;
let i18nService: SubstituteOf<I18nService>;
let collectionService: SubstituteOf<CollectionService>;
let platformUtilsService: SubstituteOf<PlatformUtilsService>;
let cryptoService: SubstituteOf<CryptoService>;
beforeEach(() => {
cipherService = Substitute.for<CipherService>();
folderService = Substitute.for<FolderService>();
apiService = Substitute.for<ApiService>();
i18nService = Substitute.for<I18nService>();
collectionService = Substitute.for<CollectionService>();
platformUtilsService = Substitute.for<PlatformUtilsService>();
cryptoService = Substitute.for<CryptoService>();
importService = new ImportService(
cipherService,
folderService,
apiService,
i18nService,
collectionService,
platformUtilsService,
cryptoService
);
});
describe("getImporterInstance", () => {
describe("Get bitPasswordProtected importer", () => {
let importer: Importer;
const organizationId = Utils.newGuid();
const password = Utils.newGuid();
beforeEach(() => {
importer = importService.getImporter(
"bitwardenpasswordprotected",
organizationId,
password
);
});
it("returns an instance of BitwardenPasswordProtectedImporter", () => {
expect(importer).toBeInstanceOf(BitwardenPasswordProtectedImporter);
});
it("has the appropriate organization Id", () => {
expect(importer.organizationId).toEqual(organizationId);
});
it("has the appropriate password", () => {
expect(Object.entries(importer)).toEqual(expect.arrayContaining([["password", password]]));
});
});
});
});