Files
calendar/packages/trpc/server/routers/viewer/attributes/utils.test.ts
T
Hariom BalharaandGitHub 727f7df2c2 fix: Enhance SCIM payload handling and attribute creation (#18427)
* feat: Enhance SCIM user attribute handling and sync process

- Introduced a new PR_TODO.md file to track ongoing tasks and fixes.
- Updated `getAttributesFromScimPayload` to accept a directoryId and ignore core user attributes during syncing.
- Modified `handleUserEvents` to pass directoryId when syncing custom attributes.
- Improved attribute creation logic to handle unique options and added support for optional isGroup property in attribute options.
- Added utility function `getOptionsWithValidContains` to ensure valid sub-options in attribute options.
- Updated tests to reflect changes in attribute handling and ensure proper functionality.

This commit addresses issues with user attribute syncing and enhances the overall attribute management process.

* test: Add unit tests for getOptionsWithValidContains utility function

- Introduced a new test file for the getOptionsWithValidContains function.
- Added tests to verify the removal of duplicate options, initialization of empty contains arrays, filtering of non-existent sub-options, and handling of empty options arrays.
- Ensured comprehensive coverage of the utility's functionality to enhance reliability and maintainability.
2025-01-03 13:36:21 +05:30

56 lines
1.6 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { getOptionsWithValidContains } from "./utils";
type Option = {
id?: string;
value: string;
contains?: string[];
isGroup?: boolean;
};
describe("getOptionsWithValidContains", () => {
it("should remove duplicate options based on value", () => {
const options: Option[] = [
{ id: "1", value: "option1" },
{ id: "2", value: "option1" }, // Duplicate value
{ id: "3", value: "option2" },
];
const result = getOptionsWithValidContains(options);
expect(result).toHaveLength(2);
expect(result[0].value).toBe("option1");
expect(result[1].value).toBe("option2");
});
it("should initialize empty contains array if not provided", () => {
const options: Option[] = [
{ id: "1", value: "option1" },
{ id: "2", value: "option2" },
];
const result = getOptionsWithValidContains(options);
expect(result[0].contains).toEqual([]);
expect(result[1].contains).toEqual([]);
});
it("should filter out non-existent sub-options from contains array", () => {
const options: Option[] = [
{ id: "1", value: "option1", contains: ["2", "3", "nonexistent"] },
{ id: "2", value: "option2" },
{ id: "3", value: "option3" },
];
const result = getOptionsWithValidContains(options);
expect(result[0].contains).toEqual(["2", "3"]);
expect(result[1].contains).toEqual([]);
expect(result[2].contains).toEqual([]);
});
it("should handle empty options array", () => {
const options: Option[] = [];
const result = getOptionsWithValidContains(options);
expect(result).toEqual([]);
});
});