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.

32 lines
1011 B
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();
login.uris = [new LoginUriView()];
jest
.spyOn(LoginUriView.prototype, "toJSON")
.mockImplementation(() => ({ mock: "not null value" }));
jest.spyOn(LoginUriView, "fromJSON").mockImplementation(() => login.uris[0]);
const stringified = JSON.stringify(login);
const newLogin = LoginView.fromJSON(JSON.parse(stringified));
expect(newLogin).toEqual(login);
expect(newLogin).toBeInstanceOf(LoginView);
});
});