Skip to content

Commit

Permalink
fix(types): union SearchForFacetValuesResponse type for multipleQueri…
Browse files Browse the repository at this point in the history
…es (#1460)

* fix(types): union SearchForFacetValuesResponse type for multipleQueries
* fix(tests): account for new type in multiple-operations test
  • Loading branch information
omikader authored Jun 19, 2023
1 parent 9092414 commit 6a786f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { BatchActionEnum, StrategyEnum } from '../..';
import { TestSuite } from '../../../../client-common/src/__tests__/TestSuite';
import { MultipleBatchRequest } from '../../types';
import { MultipleBatchRequest, MultipleQueriesResponse, SearchResponse } from '../../types';

function expectSearchResponse<TObject>(
results: MultipleQueriesResponse<TObject>['results'][number]
): asserts results is SearchResponse<TObject> {
expect(results).toHaveProperty('hits');
}

const testSuite = new TestSuite('multiple_operations');

Expand Down Expand Up @@ -62,7 +68,9 @@ test(testSuite.testName, async () => {
{ strategy: StrategyEnum.None }
);

expectSearchResponse(multipleQueriesResponse1.results[0]);
expect(multipleQueriesResponse1.results[0].hits).toHaveLength(2);
expectSearchResponse(multipleQueriesResponse1.results[1]);
expect(multipleQueriesResponse1.results[1].hits).toHaveLength(2);

const multipleQueriesResponse2 = await client.search(
Expand All @@ -73,7 +81,9 @@ test(testSuite.testName, async () => {
{ strategy: StrategyEnum.StopIfEnoughMatches }
);

expectSearchResponse(multipleQueriesResponse2.results[0]);
expect(multipleQueriesResponse2.results[0].hits).toHaveLength(2);
expectSearchResponse(multipleQueriesResponse2.results[1]);
expect(multipleQueriesResponse2.results[1].hits).toHaveLength(0);

const searchForFacetValuesResponse = await client.searchForFacetValues([
Expand Down
4 changes: 2 additions & 2 deletions packages/client-search/src/types/MultipleQueriesResponse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SearchResponse } from '.';
import { SearchForFacetValuesResponse, SearchResponse } from '.';

export type MultipleQueriesResponse<TObject> = {
/**
* The list of results.
*/
results: Array<SearchResponse<TObject>>;
results: Array<SearchResponse<TObject> | SearchForFacetValuesResponse>;
};

0 comments on commit 6a786f1

Please sign in to comment.