| 8 | import type { SearchClient, SearchResponses } from 'instantsearch.js'; |
| 9 | |
| 10 | export const createSearchClient = ( |
| 11 | args: Partial<SearchClient> = {} |
| 12 | ): SearchClient => ({ |
| 13 | getRecommendations: jest.fn((requests) => |
| 14 | Promise.resolve(createRecommendResponse(requests)) |
| 15 | ), |
| 16 | search: jest.fn((requests) => |
| 17 | Promise.resolve( |
| 18 | createMultiSearchResponse( |
| 19 | ...requests.map(() => createSingleSearchResponse()) |
| 20 | ) |
| 21 | ) |
| 22 | ), |
| 23 | // @ts-ignore v5 does not have this method, but it's easier to have it here. In a future version we can replace this method and its usages with search({ type: 'facet }) |
| 24 | searchForFacetValues: jest.fn(() => Promise.resolve([createSFFVResponse()])), |
| 25 | // @ts-ignore this allows us to test insights initialization without warning |
| 26 | applicationID: 'appId', |
| 27 | apiKey: 'apiKey', |
| 28 | ...args, |
| 29 | }); |
| 30 | |
| 31 | type ControlledClient = { |
| 32 | searchClient: SearchClient; |