Skip to content

Commit

Permalink
test: added extra test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm1t committed Aug 13, 2024
1 parent 1dfbfd1 commit d60e09c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/lib/productSearchFilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ describe("Product search filter", () => {
},
name: {
"nl-NL": "test",
"en-US": "my english test",
},
slug: {
"nl-NL": "test",
"en-US": "test",
},
variants: [],
searchKeywords: {},
Expand Down Expand Up @@ -226,6 +228,15 @@ describe("Product search filter", () => {
caseInsensitive: false,
}
}).isMatch).toBeFalsy();

expect(match({
wildcard: {
field: "name",
value: "*english Test*",
language: "en-US",
caseInsensitive: true,
}
}).isMatch).toBeTruthy();
});

test("by price range", async () => {
Expand Down
9 changes: 5 additions & 4 deletions src/lib/productSearchFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ export const parseSearchQuery = (searchQuery: _SearchQuery): ProductSearchFilter
}

if (isSearchFullTextExpression(searchQuery)) {
// TODO: Implement better fulltext search
// https://github.com/bevacqua/fuzzysearch
// With scoring (& therefore boosting): https://github.com/farzher/fuzzysort
// TODO: Implement better fulltext search, doesn't support all uses cases, see: https://docs.commercetools.com/api/search-query-language#fulltext
// Potential options to replace with:
// - https://github.com/bevacqua/fuzzysearch
// - With scoring (& therefore boosting): https://github.com/farzher/fuzzysort
return generateFieldMatchFunc((value: any) => value.includes(searchQuery.fullText.value), searchQuery.fullText);
}

Expand All @@ -114,7 +115,7 @@ export const parseSearchQuery = (searchQuery: _SearchQuery): ProductSearchFilter
}

if (isSearchWildCardExpression(searchQuery)) {
// TODO: Implement better wildcard search
// TODO: Implement better (actual) wildcard search
const generateWildcardMatchFunc = (value: any) => {
const wildCardValues = searchQuery.wildcard.value.split("*").filter((v: string) => !!v);

Expand Down

0 comments on commit d60e09c

Please sign in to comment.