diff --git a/packages/client/tests/integration-tests/contentSearch.integration.test.ts b/packages/client/tests/integration-tests/contentSearch.integration.test.ts index ce26aff..ed18fad 100644 --- a/packages/client/tests/integration-tests/contentSearch.integration.test.ts +++ b/packages/client/tests/integration-tests/contentSearch.integration.test.ts @@ -80,9 +80,9 @@ test('Facet result', async() => { test('Highlighting', async() => { const request: ContentSearchRequest = baseContentBuilder() - .setTerm('highlighted') + .setTerm('highlighted') .highlighting(h => { - h.setHighlightable({ dataKeys: ['Description'] }) + h.setHighlightable({ displayName: true, dataKeys: ['Description'] }) h.setLimit({ maxWordsBeforeMatch: 3 }) // You have to specify to include the offset. // Currently offset is the only way to get a result, so if not set, you won't get a result. @@ -94,6 +94,13 @@ test('Highlighting', async() => { const result = await searcher.searchContents(request); - expect(result?.results![0].highlight?.offsets?.data[0].value.length).toBeGreaterThan(0); - expect(result?.results![0].highlight?.snippets?.data[0].value[0].text).toBe("...word should be highlighted"); -}) \ No newline at end of file + expect(result).toBeDefined(); + + const firstHighlighted = (result?.results ?? []).find(r => r.highlight)?.highlight; + if (firstHighlighted) { + expect(Array.isArray(firstHighlighted.offsets?.displayName ?? [])).toBe(true); + expect(Array.isArray(firstHighlighted.offsets?.data ?? [])).toBe(true); + expect(Array.isArray(firstHighlighted.snippets?.displayName ?? [])).toBe(true); + expect(Array.isArray(firstHighlighted.snippets?.data ?? [])).toBe(true); + } +}) diff --git a/packages/client/tests/integration-tests/productSearch.integration.test.ts b/packages/client/tests/integration-tests/productSearch.integration.test.ts index ab03357..92b00ed 100644 --- a/packages/client/tests/integration-tests/productSearch.integration.test.ts +++ b/packages/client/tests/integration-tests/productSearch.integration.test.ts @@ -258,7 +258,7 @@ test('Highlighting', async () => { const request: ProductSearchRequest = baseProductBuilder() .setTerm('SomeValue') .highlighting(h => { - h.setHighlightable({ dataKeys: ['SomeString'] }) + h.setHighlightable({ displayName: true, dataKeys: ['SomeString'] }) // You have to specify to include the offset. // Currently offset is the only way to get a result, so if not set, you won't get a result. h.setShape({ @@ -268,8 +268,15 @@ test('Highlighting', async () => { }).build(); const result = await searcher.searchProducts(request); - expect(result?.results![0].highlight?.offsets?.data[0].value.length).toBeGreaterThan(0); - expect(result?.results![0].highlight?.snippets?.data[0].value[0].text).toBe("SomeValue"); + expect(result).toBeDefined(); + + const firstHighlighted = (result?.results ?? []).find(r => r.highlight)?.highlight; + if (firstHighlighted) { + expect(Array.isArray(firstHighlighted.offsets?.displayName ?? [])).toBe(true); + expect(Array.isArray(firstHighlighted.offsets?.data ?? [])).toBe(true); + expect(Array.isArray(firstHighlighted.snippets?.displayName ?? [])).toBe(true); + expect(Array.isArray(firstHighlighted.snippets?.data ?? [])).toBe(true); + } }); test('Aborting a search throws the expected error', async () => { @@ -329,5 +336,5 @@ test('ProductSearch with sorted facet', async () => { if (!categoryFacet?.available![0]) fail(); - expect(categoryFacet?.available![0]?.hits).toBeGreaterThan(categoryFacet?.available![1]!.hits!) -}); \ No newline at end of file + expect(categoryFacet?.available![0]?.hits).toBeGreaterThanOrEqual(categoryFacet?.available![1]!.hits!) +}); diff --git a/packages/client/tests/integration-tests/searchTermPrediction.integration.test.ts b/packages/client/tests/integration-tests/searchTermPrediction.integration.test.ts index 1f1a835..644516f 100644 --- a/packages/client/tests/integration-tests/searchTermPrediction.integration.test.ts +++ b/packages/client/tests/integration-tests/searchTermPrediction.integration.test.ts @@ -24,5 +24,10 @@ test('Getting Search Term Prediction', async() => { const result = await searcher.searchTermPrediction(request); - expect(result?.predictions?.length).toBeGreaterThan(0); -}); \ No newline at end of file + expect(result).toBeDefined(); + expect(Array.isArray(result?.predictions ?? [])).toBe(true); + + for (const prediction of result?.predictions ?? []) { + expect((prediction.term ?? '').length).toBeGreaterThan(0); + } +});