2022-10-14 18:25:50 +02:00
|
|
|
import { CollectionData } from "@bitwarden/common/models/data/collection.data";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { Collection } from "@bitwarden/common/models/domain/collection";
|
2022-04-16 17:18:12 +02:00
|
|
|
|
2022-08-05 00:07:24 +02:00
|
|
|
import { mockEnc } from "../../utils";
|
2022-04-16 17:18:12 +02:00
|
|
|
|
|
|
|
describe("Collection", () => {
|
|
|
|
let data: CollectionData;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
data = {
|
|
|
|
id: "id",
|
|
|
|
organizationId: "orgId",
|
|
|
|
name: "encName",
|
|
|
|
externalId: "extId",
|
|
|
|
readOnly: true,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Convert from empty", () => {
|
|
|
|
const data = new CollectionData({} as any);
|
|
|
|
const card = new Collection(data);
|
|
|
|
|
|
|
|
expect(card).toEqual({
|
|
|
|
externalId: null,
|
|
|
|
hidePasswords: null,
|
|
|
|
id: null,
|
|
|
|
name: null,
|
|
|
|
organizationId: null,
|
|
|
|
readOnly: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Convert", () => {
|
|
|
|
const collection = new Collection(data);
|
|
|
|
|
|
|
|
expect(collection).toEqual({
|
|
|
|
id: "id",
|
|
|
|
organizationId: "orgId",
|
|
|
|
name: { encryptedString: "encName", encryptionType: 0 },
|
|
|
|
externalId: "extId",
|
|
|
|
readOnly: true,
|
|
|
|
hidePasswords: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Decrypt", async () => {
|
|
|
|
const collection = new Collection();
|
|
|
|
collection.id = "id";
|
|
|
|
collection.organizationId = "orgId";
|
|
|
|
collection.name = mockEnc("encName");
|
|
|
|
collection.externalId = "extId";
|
|
|
|
collection.readOnly = false;
|
|
|
|
collection.hidePasswords = false;
|
|
|
|
|
|
|
|
const view = await collection.decrypt();
|
|
|
|
|
|
|
|
expect(view).toEqual({
|
|
|
|
externalId: "extId",
|
|
|
|
hidePasswords: false,
|
|
|
|
id: "id",
|
|
|
|
name: "encName",
|
|
|
|
organizationId: "orgId",
|
|
|
|
readOnly: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|