diff --git a/tests/mocks/createAPIResponse.ts b/tests/mocks/createAPIResponse.ts index ec54ab630b..5a34ab1f34 100644 --- a/tests/mocks/createAPIResponse.ts +++ b/tests/mocks/createAPIResponse.ts @@ -3,6 +3,7 @@ import type { SearchResponses, SearchForFacetValuesResponse, RecommendResponse, + RecommendResponses, } from 'instantsearch.js'; export const defaultRenderingContent: SearchResponse['renderingContent'] = @@ -88,14 +89,6 @@ export const createSFFVResponse = ( ...args, }); -export const createRecommendResponse = ( - requests: any[] -): { results: Array> } => { - return { - results: requests.map(createSingleSearchResponse), - } as unknown as { results: Array> }; -}; - export const createSingleRecommendResponse = ( subset: Partial> = {} ): RecommendResponse => { @@ -127,3 +120,11 @@ export const createSingleRecommendResponse = ( ...rest, }; }; + +export const createRecommendResponse = ( + requests: any[] +): RecommendResponses => { + return { + results: requests.map(createSingleRecommendResponse), + }; +}; diff --git a/tests/mocks/createAlgoliaSearchClient.ts b/tests/mocks/createAlgoliaSearchClient.ts index b715349514..3dbab976a3 100644 --- a/tests/mocks/createAlgoliaSearchClient.ts +++ b/tests/mocks/createAlgoliaSearchClient.ts @@ -27,27 +27,10 @@ type OverrideKeys = TOptions extends Record ? TTarget : Omit & TOptions; -type IfAny = (0 extends 1 & TTest ? true : false) extends true - ? IfAny - : TTest; - -function ifActualFunction( - test: TTest, - fallback: TFallback -): IfAny { - if (typeof test === 'function') { - return test as IfAny; - } - if (typeof fallback === 'function') { - return fallback as IfAny; - } - throw new Error('Neither test nor fallback is a function'); -} - -const algoliasearch = ifActualFunction( - namedConstructor, - defaultConstructor -) as unknown as (appId: string, apiKey: string) => SearchClient; +const algoliasearch = (namedConstructor || defaultConstructor) as unknown as ( + appId: string, + apiKey: string +) => SearchClient; export type MockSearchClient = OverrideKeys< SearchClient,