Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1081: Provide the possibility to give your own httpClient and request configs r=bidoubiwa a=bidoubiwa Fixes: #1060 Fixes: #928 Co-authored-by: Charlotte Vermandel <charlottevermandel@gmail.com>
- Loading branch information
Showing
8 changed files
with
208 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@meilisearch/instant-meilisearch": patch | ||
--- | ||
|
||
Add the possibility to provide a custom HTTP request and custom requests configurations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/instant-meilisearch/__tests__/custom-http-client.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { instantMeiliSearch } from '../src' | ||
import { meilisearchClient, dataset } from './assets/utils' | ||
|
||
describe('Custom HTTP client tests', () => { | ||
beforeAll(async () => { | ||
const deleteTask = await meilisearchClient.deleteIndex('movies') | ||
await meilisearchClient.waitForTask(deleteTask.taskUid) | ||
|
||
const documentsTask = await meilisearchClient | ||
.index('movies') | ||
.addDocuments(dataset) | ||
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid) | ||
}) | ||
|
||
test('a custom HTTP client', async () => { | ||
const httpClient = jest.fn(async (url: string, init?: RequestInit) => { | ||
const result = await fetch(url, init) | ||
return await result.json() | ||
}) | ||
|
||
const searchClient = instantMeiliSearch( | ||
'http://localhost:7700', | ||
'masterKey', | ||
{ | ||
httpClient, | ||
} | ||
) | ||
|
||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
attributesToRetrieve: [], | ||
query: 'ariel', | ||
}, | ||
}, | ||
]) | ||
expect(httpClient).toHaveBeenCalledTimes(2) | ||
expect(response.results[0].hits.length).toEqual(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters