bitwarden-estensione-browser/libs/common/spec/models/view/loginView.spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-06-28 02:25:29 +02:00
import { LoginUriView } from "@bitwarden/common/models/view/loginUriView";
import { LoginView } from "@bitwarden/common/models/view/loginView";
jest.mock("@bitwarden/common/models/view/loginUriView");
describe("LoginView", () => {
beforeEach(() => {
(LoginUriView as any).mockClear();
});
it("serializes and deserializes", () => {
const login = new LoginView();
login.username = "myUsername";
login.password = "myPassword";
login.totp = "totpSeed";
login.autofillOnPageLoad = true;
login.passwordRevisionDate = new Date();
2022-06-28 03:46:29 +02:00
login.uris = ["uri1", "uri2", "uri3"] as any;
2022-06-28 02:25:29 +02:00
2022-06-28 03:46:29 +02:00
const mockFromJson = (key: string) => (key + "fromJSON") as any;
jest.spyOn(LoginUriView, "fromJSON").mockImplementation(mockFromJson);
2022-06-28 02:25:29 +02:00
const stringified = JSON.stringify(login);
const newLogin = LoginView.fromJSON(JSON.parse(stringified));
2022-06-28 03:46:29 +02:00
expect(newLogin).toEqual({
...login,
uris: ["uri1fromJSON", "uri2fromJSON", "uri3fromJSON"],
});
2022-06-28 02:25:29 +02:00
expect(newLogin).toBeInstanceOf(LoginView);
});
});