1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-24 04:04:24 +00:00
Files
browser/libs/common/src/vault/models/domain/collection.spec.ts
Tom 95bdea3925 [PM-4311] - Collections test fix (#10248)
* populate the collection's external id when importing

* Fixing the collections test case

---------

Co-authored-by: Andre Rosado <arosado@bitwarden.com>
2024-07-24 20:39:00 +02:00

78 lines
1.9 KiB
TypeScript

import { makeSymmetricCryptoKey, mockEnc } from "../../../../spec";
import { CollectionId, OrganizationId } from "../../../types/guid";
import { OrgKey } from "../../../types/key";
import { CollectionData } from "../data/collection.data";
import { Collection } from "./collection";
describe("Collection", () => {
let data: CollectionData;
beforeEach(() => {
data = {
id: "id" as CollectionId,
organizationId: "orgId" as OrganizationId,
name: "encName",
externalId: "extId",
readOnly: true,
manage: true,
hidePasswords: 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,
manage: null,
});
});
it("Convert", () => {
const collection = new Collection(data);
expect(collection).toEqual({
id: "id",
organizationId: "orgId",
name: { encryptedString: "encName", encryptionType: 0 },
externalId: { encryptedString: "extId", encryptionType: 0 },
readOnly: true,
manage: true,
hidePasswords: true,
});
});
it("Decrypt", async () => {
const collection = new Collection();
collection.id = "id";
collection.organizationId = "orgId" as OrganizationId;
collection.name = mockEnc("encName");
collection.externalId = "extId";
collection.readOnly = false;
collection.hidePasswords = false;
collection.manage = true;
const key = makeSymmetricCryptoKey<OrgKey>();
const view = await collection.decrypt(key);
expect(view).toEqual({
externalId: "extId",
hidePasswords: false,
id: "id",
name: "encName",
organizationId: "orgId",
readOnly: false,
manage: true,
assigned: true,
});
});
});