diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 5bed8780c10a..cc5eca7e202c 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1859,6 +1859,9 @@ function filterAndOrderOptions(options: Options, searchInputValue: string, confi let {recentReports: filteredReports, personalDetails: filteredPersonalDetails} = filterResult; + // on staging server, in specific cases (see issue) BE returns duplicated personalDetails entries + filteredPersonalDetails = filteredPersonalDetails.filter((detail, index, array) => array.findIndex((i) => i.login === detail.login) === index); + if (typeof config?.maxRecentReportsToShow === 'number') { filteredReports = orderReportOptionsWithSearch(filteredReports, searchInputValue, config); filteredReports = filteredReports.slice(0, config.maxRecentReportsToShow); diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 8916b7c3bac8..39406e6a0995 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -987,6 +987,21 @@ describe('OptionsListUtils', () => { expect(filteredResults.recentReports.at(0)?.text).toBe('The Flash'); }); }); + + it('should filter out duplicated entries by login', () => { + const login = 'brucebanner@expensify.com'; + + // Duplicate personalDetails entries and reassign to OPTIONS + OPTIONS.personalDetails = OPTIONS.personalDetails.flatMap((obj) => [obj, {...obj}]); + + const options = OptionsListUtils.getSearchOptions(OPTIONS, [CONST.BETAS.ALL]); + const filteredOptions = OptionsListUtils.filterAndOrderOptions(options, ''); + const matchingEntries = filteredOptions.personalDetails.filter((detail) => detail.login === login); + + // There should be 2 unique login entries + expect(filteredOptions.personalDetails.length).toBe(2); + expect(matchingEntries.length).toBe(1); + }); }); describe('canCreateOptimisticPersonalDetailOption', () => {