1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-04 09:01:01 +01:00
bitwarden-browser/libs/common/spec/models/domain/loginUri.spec.ts

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

80 lines
1.9 KiB
TypeScript
Raw Normal View History

import { Jsonify } from "type-fest";
2022-06-14 17:10:53 +02:00
import { UriMatchType } from "@bitwarden/common/enums/uriMatchType";
import { LoginUriData } from "@bitwarden/common/models/data/loginUriData";
import { EncString } from "@bitwarden/common/models/domain/encString";
2022-06-14 17:10:53 +02:00
import { LoginUri } from "@bitwarden/common/models/domain/loginUri";
2022-04-16 17:18:12 +02:00
import { mockEnc, mockFromJson } from "../../utils";
2022-04-16 17:18:12 +02:00
describe("LoginUri", () => {
let data: LoginUriData;
beforeEach(() => {
data = {
uri: "encUri",
match: UriMatchType.Domain,
};
});
it("Convert from empty", () => {
const data = new LoginUriData();
const loginUri = new LoginUri(data);
expect(loginUri).toEqual({
match: null,
uri: null,
});
});
it("Convert", () => {
const loginUri = new LoginUri(data);
expect(loginUri).toEqual({
match: 0,
uri: { encryptedString: "encUri", encryptionType: 0 },
});
});
it("toLoginUriData", () => {
const loginUri = new LoginUri(data);
expect(loginUri.toLoginUriData()).toEqual(data);
});
it("Decrypt", async () => {
const loginUri = new LoginUri();
loginUri.match = UriMatchType.Exact;
loginUri.uri = mockEnc("uri");
const view = await loginUri.decrypt(null);
expect(view).toEqual({
_canLaunch: null,
_domain: null,
_host: null,
_hostname: null,
_uri: "uri",
match: 3,
});
});
describe("fromJSON", () => {
it("initializes nested objects", () => {
jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson);
const actual = LoginUri.fromJSON({
uri: "myUri",
} as Jsonify<LoginUri>);
expect(actual).toEqual({
uri: "myUri_fromJSON",
});
expect(actual).toBeInstanceOf(LoginUri);
});
it("returns null if object is null", () => {
expect(LoginUri.fromJSON(null)).toBeNull();
});
});
2022-04-16 17:18:12 +02:00
});