2022-10-10 17:19:01 +02:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2022-09-27 03:17:43 +02:00
|
|
|
import { Substitute, SubstituteOf } from "@fluffy-spoon/substitute";
|
2022-02-07 16:33:10 +01:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
|
|
|
|
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
2023-01-30 20:03:12 +01:00
|
|
|
import { ImportApiServiceAbstraction } from "@bitwarden/common/abstractions/import/import-api.service.abstraction";
|
2022-11-11 16:20:03 +01:00
|
|
|
import { BitwardenPasswordProtectedImporter } from "@bitwarden/common/importers/bitwarden-password-protected-importer";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { Importer } from "@bitwarden/common/importers/importer";
|
|
|
|
import { Utils } from "@bitwarden/common/misc/utils";
|
2023-01-30 20:03:12 +01:00
|
|
|
import { ImportService } from "@bitwarden/common/services/import/import.service";
|
2023-01-31 22:08:37 +01:00
|
|
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
|
|
|
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
2022-02-07 16:33:10 +01:00
|
|
|
|
|
|
|
describe("ImportService", () => {
|
|
|
|
let importService: ImportService;
|
|
|
|
let cipherService: SubstituteOf<CipherService>;
|
|
|
|
let folderService: SubstituteOf<FolderService>;
|
2023-01-30 20:03:12 +01:00
|
|
|
let importApiService: SubstituteOf<ImportApiServiceAbstraction>;
|
2022-02-07 16:33:10 +01:00
|
|
|
let i18nService: SubstituteOf<I18nService>;
|
|
|
|
let collectionService: SubstituteOf<CollectionService>;
|
|
|
|
let cryptoService: SubstituteOf<CryptoService>;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cipherService = Substitute.for<CipherService>();
|
|
|
|
folderService = Substitute.for<FolderService>();
|
2023-01-30 20:03:12 +01:00
|
|
|
importApiService = Substitute.for<ImportApiServiceAbstraction>();
|
2022-02-07 16:33:10 +01:00
|
|
|
i18nService = Substitute.for<I18nService>();
|
|
|
|
collectionService = Substitute.for<CollectionService>();
|
|
|
|
cryptoService = Substitute.for<CryptoService>();
|
|
|
|
|
|
|
|
importService = new ImportService(
|
|
|
|
cipherService,
|
|
|
|
folderService,
|
2023-01-30 20:03:12 +01:00
|
|
|
importApiService,
|
2022-02-07 16:33:10 +01:00
|
|
|
i18nService,
|
|
|
|
collectionService,
|
|
|
|
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", () => {
|
2022-03-28 16:00:42 +02:00
|
|
|
expect(Object.entries(importer)).toEqual(expect.arrayContaining([["password", password]]));
|
2022-02-07 16:33:10 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|