From 6cb1d0a8f5b36527df47026dd49aa34e82da6a69 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Wed, 18 Nov 2020 16:08:03 +0100 Subject: [PATCH] fix(findAnswers): expose in lite version (#1227) * fix(findAnswers): expose in lite version * test: add browser-lite to integration test for answers --- .../algoliasearch/src/builds/browserLite.ts | 10 ++- specs/answers.spec.ts | 80 ++++++++++--------- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/packages/algoliasearch/src/builds/browserLite.ts b/packages/algoliasearch/src/builds/browserLite.ts index 699abe764..07249adee 100644 --- a/packages/algoliasearch/src/builds/browserLite.ts +++ b/packages/algoliasearch/src/builds/browserLite.ts @@ -4,6 +4,9 @@ import { createInMemoryCache } from '@algolia/cache-in-memory'; import { AuthMode, version } from '@algolia/client-common'; import { createSearchClient, + findAnswers, + FindAnswersOptions, + FindAnswersResponse, initIndex, multipleQueries, MultipleQueriesOptions, @@ -66,7 +69,7 @@ export default function algoliasearch( multipleSearchForFacetValues, initIndex: base => (indexName: string): SearchIndex => { return initIndex(base)(indexName, { - methods: { search, searchForFacetValues }, + methods: { search, searchForFacetValues, findAnswers }, }); }, }, @@ -86,6 +89,11 @@ export type SearchIndex = BaseSearchIndex & { facetQuery: string, requestOptions?: RequestOptions & SearchOptions ) => Readonly>; + readonly findAnswers: ( + query: string, + queryLanguages: readonly string[], + requestOptions?: RequestOptions & FindAnswersOptions + ) => Readonly>; }; export type SearchClient = BaseSearchClient & { diff --git a/specs/answers.spec.ts b/specs/answers.spec.ts index bb52c82bd..ea12d838c 100644 --- a/specs/answers.spec.ts +++ b/specs/answers.spec.ts @@ -18,53 +18,55 @@ const credentials = { // apiKey: `${process.env.ALGOLIA_SEARCH_KEY_1}` }; -describe("answers features - algoliasearch.com", () => { - beforeEach(async () => browser.url("algoliasearch.com")); +["algoliasearch-lite.com", "algoliasearch.com"].forEach(preset => { + describe(`answers features - ${preset}`, () => { + beforeEach(async () => browser.url(preset)); - it("searchIndex::findAnswers", async () => { - const results: any = await browser.executeAsync(function( - credentials, - done - ) { - const client = algoliasearch(credentials.appId, credentials.apiKey); + it("searchIndex::findAnswers", async () => { + const results: any = await browser.executeAsync(function( + credentials, + done + ) { + const client = algoliasearch(credentials.appId, credentials.apiKey); - // TODO: remove this customization once the engine accepts url encoded query params - client.transporter.userAgent.value = "answers-test"; + // TODO: remove this customization once the engine accepts url encoded query params + client.transporter.userAgent.value = "answers-test"; - const index = client.initIndex("ted"); + const index = client.initIndex("ted"); - Promise.all([ - index.findAnswers("sir ken robinson", ["en"]), - index.findAnswers("what", ["en"]), - index.findAnswers("sarah jones", ["en"], { - nbHits: 2, - attributesForPrediction: ["main_speaker"], - params: { - highlightPreTag: "_pre_", - highlightPostTag: "_post_" - } - }) - ]).then(function(responses) { - done({ - kenRobinson: responses[0], - what: responses[1], - sarah: responses[2] + Promise.all([ + index.findAnswers("sir ken robinson", ["en"]), + index.findAnswers("what", ["en"]), + index.findAnswers("sarah jones", ["en"], { + nbHits: 2, + attributesForPrediction: ["main_speaker"], + params: { + highlightPreTag: "_pre_", + highlightPostTag: "_post_" + } + }) + ]).then(function(responses) { + done({ + kenRobinson: responses[0], + what: responses[1], + sarah: responses[2] + }); }); - }); - }, - credentials); + }, + credentials); - expect(results.kenRobinson.nbHits).toBe(10); + expect(results.kenRobinson.nbHits).toBe(10); - expect(results.what.nbHits).toBe(0); + expect(results.what.nbHits).toBe(0); - expect(results.sarah.nbHits).toBe(1); - expect(results.sarah.hits[0]._highlightResult.main_speaker.value).toBe( - "_pre_Sarah_post_ _pre_Jones_post_" - ); + expect(results.sarah.nbHits).toBe(1); + expect(results.sarah.hits[0]._highlightResult.main_speaker.value).toBe( + "_pre_Sarah_post_ _pre_Jones_post_" + ); - expect(results.sarah.hits[0]._answer.extract).toBe( - "_pre_Sarah_post_ _pre_Jones_post_" - ); + expect(results.sarah.hits[0]._answer.extract).toBe( + "_pre_Sarah_post_ _pre_Jones_post_" + ); + }); }); });