mirror of
https://github.com/bitwarden/browser
synced 2026-02-09 05:00:10 +00:00
fixed tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// @ts-strict-ignore
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { Unassigned } from "@bitwarden/admin-console/common";
|
||||
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
|
||||
@@ -128,8 +129,8 @@ describe("createFilter", () => {
|
||||
|
||||
it("should return true when filter matches collection id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
collectionId: "collectionId",
|
||||
organizationId: "organizationId",
|
||||
collectionId: "collectionId" as CollectionId,
|
||||
organizationId: "organizationId" as OrganizationId,
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
@@ -139,8 +140,8 @@ describe("createFilter", () => {
|
||||
|
||||
it("should return false when filter does not match collection id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
collectionId: "nonMatchingCollectionId",
|
||||
organizationId: "organizationId",
|
||||
collectionId: "nonMatchingCollectionId" as CollectionId,
|
||||
organizationId: "organizationId" as OrganizationId,
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
@@ -150,7 +151,7 @@ describe("createFilter", () => {
|
||||
|
||||
it("should return false when filter does not match organization id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
organizationId: "nonMatchingOrganizationId",
|
||||
organizationId: "nonMatchingOrganizationId" as OrganizationId,
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
@@ -187,7 +188,9 @@ describe("createFilter", () => {
|
||||
});
|
||||
|
||||
it("should return true when filter matches organization id", () => {
|
||||
const filterFunction = createFilterFunction({ organizationId: "organizationId" });
|
||||
const filterFunction = createFilterFunction({
|
||||
organizationId: "organizationId" as OrganizationId,
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { CollectionView } from "@bitwarden/admin-console/common";
|
||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { CollectionId } from "@bitwarden/common/types/guid";
|
||||
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { TreeNode } from "@bitwarden/common/vault/models/domain/tree-node";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
@@ -179,8 +179,8 @@ describe("VaultFilter", () => {
|
||||
it("should return true when filter matches collection id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedCollectionNode: createCollectionFilterNode({
|
||||
id: "collectionId",
|
||||
organizationId: "organizationId",
|
||||
id: "collectionId" as CollectionId,
|
||||
organizationId: "organizationId" as OrganizationId,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -192,8 +192,8 @@ describe("VaultFilter", () => {
|
||||
it("should return false when filter does not match collection id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedCollectionNode: createCollectionFilterNode({
|
||||
id: "nonMatchingCollectionId",
|
||||
organizationId: "organizationId",
|
||||
id: "nonMatchingCollectionId" as CollectionId,
|
||||
organizationId: "organizationId" as OrganizationId,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -205,7 +205,7 @@ describe("VaultFilter", () => {
|
||||
it("should return false when filter does not match organization id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedOrganizationNode: createOrganizationFilterNode({
|
||||
id: "nonMatchingOrganizationId",
|
||||
id: "nonMatchingOrganizationId" as OrganizationId,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -216,7 +216,9 @@ describe("VaultFilter", () => {
|
||||
|
||||
it("should return false when filtering for my vault only", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedOrganizationNode: createOrganizationFilterNode({ id: "MyVault" }),
|
||||
selectedOrganizationNode: createOrganizationFilterNode({
|
||||
id: "MyVault" as OrganizationId,
|
||||
}),
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
@@ -252,7 +254,9 @@ describe("VaultFilter", () => {
|
||||
|
||||
it("should return true when filter matches organization id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedOrganizationNode: createOrganizationFilterNode({ id: "organizationId" }),
|
||||
selectedOrganizationNode: createOrganizationFilterNode({
|
||||
id: "organizationId" as OrganizationId,
|
||||
}),
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
@@ -277,7 +281,9 @@ describe("VaultFilter", () => {
|
||||
it("should return true when filtering for my vault only", () => {
|
||||
const cipher = createCipher({ organizationId: null });
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedOrganizationNode: createOrganizationFilterNode({ id: "MyVault" }),
|
||||
selectedOrganizationNode: createOrganizationFilterNode({
|
||||
id: "MyVault" as OrganizationId,
|
||||
}),
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
@@ -316,7 +322,7 @@ function createCollectionFilterNode(
|
||||
const collection = new CollectionView({
|
||||
name: options.name ?? "Test Name",
|
||||
id: options.id ?? null,
|
||||
organizationId: options.organizationId ?? "Org Id",
|
||||
organizationId: options.organizationId ?? ("Org Id" as OrganizationId),
|
||||
}) as CollectionFilter;
|
||||
return new TreeNode<CollectionFilter>(collection, {} as TreeNode<CollectionFilter>);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import { COLLAPSED_GROUPINGS } from "@bitwarden/common/vault/services/key-state/
|
||||
import { VaultFilterService } from "./vault-filter.service";
|
||||
|
||||
jest.mock("@bitwarden/angular/vault/vault-filter/services/vault-filter.service", () => ({
|
||||
sortDefaultCollections: jest.fn(() => []),
|
||||
sortDefaultCollections: jest.fn((): CollectionView[] => []),
|
||||
}));
|
||||
|
||||
describe("vault filter service", () => {
|
||||
@@ -128,7 +128,10 @@ describe("vault filter service", () => {
|
||||
|
||||
describe("organizations", () => {
|
||||
beforeEach(() => {
|
||||
const storedOrgs = [createOrganization("1", "org1"), createOrganization("2", "org2")];
|
||||
const storedOrgs = [
|
||||
createOrganization("1" as OrganizationId, "org1"),
|
||||
createOrganization("2" as OrganizationId, "org2"),
|
||||
];
|
||||
organizations.next(storedOrgs);
|
||||
organizationDataOwnershipPolicy.next(false);
|
||||
singleOrgPolicy.next(false);
|
||||
@@ -176,7 +179,9 @@ describe("vault filter service", () => {
|
||||
describe("filtered folders with organization", () => {
|
||||
beforeEach(() => {
|
||||
// Org must be updated before folderService else the subscription uses the null org default value
|
||||
vaultFilterService.setOrganizationFilter(createOrganization("org test id", "Test Org"));
|
||||
vaultFilterService.setOrganizationFilter(
|
||||
createOrganization("org test id" as OrganizationId, "Test Org"),
|
||||
);
|
||||
});
|
||||
it("returns folders filtered by current organization", async () => {
|
||||
const storedCiphers = [
|
||||
@@ -226,7 +231,9 @@ describe("vault filter service", () => {
|
||||
describe("collections", () => {
|
||||
describe("filtered collections", () => {
|
||||
it("returns collections filtered by current organization", async () => {
|
||||
vaultFilterService.setOrganizationFilter(createOrganization("org test id", "Test Org"));
|
||||
vaultFilterService.setOrganizationFilter(
|
||||
createOrganization("org test id" as OrganizationId, "Test Org"),
|
||||
);
|
||||
|
||||
const storedCollections = [
|
||||
createCollectionView("1", "collection 1", "org test id"),
|
||||
@@ -317,8 +324,8 @@ describe("vault filter service", () => {
|
||||
|
||||
it("calls sortDefaultCollections with the correct args", async () => {
|
||||
const storedOrgs = [
|
||||
createOrganization("id-defaultOrg1", "org1"),
|
||||
createOrganization("id-defaultOrg2", "org2"),
|
||||
createOrganization("id-defaultOrg1" as OrganizationId, "org1"),
|
||||
createOrganization("id-defaultOrg2" as OrganizationId, "org2"),
|
||||
];
|
||||
organizations.next(storedOrgs);
|
||||
|
||||
@@ -354,7 +361,7 @@ describe("vault filter service", () => {
|
||||
});
|
||||
});
|
||||
|
||||
function createOrganization(id: string, name: string) {
|
||||
function createOrganization(id: OrganizationId, name: string) {
|
||||
const org = new Organization();
|
||||
org.id = id;
|
||||
org.name = name;
|
||||
|
||||
Reference in New Issue
Block a user