1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-11 10:10:25 +01:00
bitwarden-browser/spec/common/importers/bitwardenJsonImporter.spec.ts
Matt Gibson 1fb3d54014
Feature/password protected export (#689)
* Simplify password protected file format

* no items to import is not an error

* Await inner importer

* Add export format type

* Error if import file is password protected

* Update tests

* Test password protected with normat json importer

* Simplify imports

* Ignore code coverage directory

* Expand importer options  without changing display options

* Import password require import error handling

* Use interface

* Fix curlies

* linter fixes

* Add null of empty util

* Lint fixes

* run prettier

* Move import options to separate enum file

* Fix imports
2022-02-23 13:02:07 +10:00

32 lines
1.2 KiB
TypeScript

import { Substitute, SubstituteOf } from "@fluffy-spoon/substitute";
import { CryptoService } from "jslib-common/abstractions/crypto.service";
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { BitwardenJsonImporter } from "jslib-common/importers/bitwardenJsonImporter";
import { data as passwordProtectedData } from "./testData/bitwardenJson/passwordProtected.json";
describe("bitwarden json importer", () => {
let sut: BitwardenJsonImporter;
let cryptoService: SubstituteOf<CryptoService>;
let i18nService: SubstituteOf<I18nService>;
beforeEach(() => {
cryptoService = Substitute.for<CryptoService>();
i18nService = Substitute.for<I18nService>();
sut = new BitwardenJsonImporter(cryptoService, i18nService);
});
it("should fail if password is needed", async () => {
expect((await sut.parse(passwordProtectedData)).success).toBe(false);
});
it("should return password needed error message", async () => {
const expected = "Password required error message";
i18nService.t("importPasswordRequired").returns(expected);
expect((await sut.parse(passwordProtectedData)).errorMessage).toEqual(expected);
});
});