Skip to content

Commit

Permalink
fix: discord group search for multiple words in same string
Browse files Browse the repository at this point in the history
  • Loading branch information
ssxdev committed Oct 20, 2024
1 parent 0399dcd commit 5af0af7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion __tests__/groups/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ describe('Discord Groups Page', () => {
});

test('Should display only specified groups when name=<group-name> with different case', async () => {
const groupNames = 'fIrSt,DSA+COdInG';
const groupNames = 'fIrSt,COdInG';
await page.goto(`${PAGE_URL}/groups?name=${groupNames}`);
await page.waitForNetworkIdle();

Expand Down
8 changes: 7 additions & 1 deletion groups/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,21 @@ function removeGroupKeywordFromDiscordRoleName(groupName) {

function getDiscordGroupIdsFromSearch(groups, multipleGroupSearch) {
if (!multipleGroupSearch) return groups.map((group) => group.id);

const GROUP_SEARCH_SEPARATOR = ',';
const searchGroups = multipleGroupSearch
.split(GROUP_SEARCH_SEPARATOR)
.map((group) => group.trim().toLowerCase());

const matchGroups = groups.filter((group) =>
searchGroups.some((searchGroup) =>
group.title.toLowerCase().startsWith(searchGroup),
group.title
.toLowerCase()
.split(' ')
.some((word) => word.startsWith(searchGroup)),
),
);

return matchGroups.map((group) => group.id);
}

Expand Down

0 comments on commit 5af0af7

Please sign in to comment.