* 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.
27 lines
896 B
TypeScript
27 lines
896 B
TypeScript
/**
|
|
* Ensures that contains has no non-existent sub-options
|
|
*/
|
|
export function getOptionsWithValidContains<
|
|
T extends { id?: string; value: string; contains?: string[]; isGroup?: boolean }
|
|
>(options: T[]): T[] {
|
|
return options
|
|
.filter((obj, index, self) => index === self.findIndex((t) => t.value === obj.value))
|
|
.map(({ contains, ...option }) => {
|
|
if (!contains)
|
|
return {
|
|
...option,
|
|
contains: [] as string[],
|
|
} as T;
|
|
const possibleSubOptions = options
|
|
.filter((option) => !option.isGroup)
|
|
.filter((option): option is typeof option & { id: string } => option.id !== undefined);
|
|
|
|
const possibleSubOptionsIds = possibleSubOptions.map((option) => option.id);
|
|
|
|
return {
|
|
...option,
|
|
contains: contains.filter((subOptionId) => possibleSubOptionsIds.includes(subOptionId)),
|
|
} as T;
|
|
});
|
|
}
|