Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const SECOND_ITEM_ID = MOVIES[1].id

beforeAll(async () => {
await meilisearchClient.deleteIndex(INDEX_NAME)
const task = await meilisearchClient.index(INDEX_NAME).addDocuments(MOVIES)
await meilisearchClient.waitForTask(task.taskUid)
await meilisearchClient.index(INDEX_NAME).addDocuments(MOVIES).waitTask()
})

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import {

describe('Instant Meilisearch Browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()

const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('attributesToRetrieve on no attributes', async () => {
Expand Down
18 changes: 8 additions & 10 deletions packages/instant-meilisearch/__tests__/custom-http-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ import { meilisearchClient, dataset } from './assets/utils.js'

describe('Custom HTTP client tests', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()

const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('a custom HTTP client', async () => {
const httpClient = vi.fn(async (url: string, init?: RequestInit) => {
const result = await fetch(url, init)
return await result.json()
})
const httpClient = vi.fn(
async (url: RequestInfo | URL, init?: RequestInit) => {
const result = await fetch(url, init)
return await result.json()
}
)

const { searchClient } = instantMeiliSearch(
'http://localhost:7700',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ describe('Keep zero facets tests', () => {
})

await moviesIndex.addDocuments(movies)
const response = await gamesIndex.addDocuments(games)

await meilisearchClient.waitForTask(response.taskUid)
await gamesIndex.addDocuments(games).waitTask()
})

test('searching on one index with facet filtering', async () => {
Expand Down
9 changes: 3 additions & 6 deletions packages/instant-meilisearch/__tests__/facet-stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import { searchClient, dataset, meilisearchClient } from './assets/utils.js'

describe('Facet stats tests', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.updateFilterableAttributes(['genres', 'release_date', 'id'])
const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('Facet stats on an empty facets array', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import { searchClient, dataset, meilisearchClient } from './assets/utils.js'

describe('Instant Meilisearch Browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.updateFilterableAttributes(['genres'])
const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('empty array on facetDistribution', async () => {
Expand Down
9 changes: 3 additions & 6 deletions packages/instant-meilisearch/__tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {

describe('Instant Meilisearch Browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.updateFilterableAttributes([
Expand All @@ -18,10 +17,8 @@ describe('Instant Meilisearch Browser test', () => {
'numberField',
'crazy_\\_"field"',
])
const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('one string facet on filter without a query', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import { instantMeiliSearch } from '../src/index.js'

describe('Default facet distribution', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.index('movies').updateSettings({
filterableAttributes: ['genres', 'release_date'],
sortableAttributes: ['release_date'],
})
const documentsTask = await meilisearchClient
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.updateSettings({
filterableAttributes: ['genres', 'release_date'],
sortableAttributes: ['release_date'],
})
.waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

// Without facets
Expand Down
12 changes: 6 additions & 6 deletions packages/instant-meilisearch/__tests__/geosearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import {

describe('Instant Meilisearch Browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('geotest')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('geotest').waitTask()
await meilisearchClient
.index('geotest')
.updateFilterableAttributes(['_geo'])
await meilisearchClient.index('geotest').updateSortableAttributes(['_geo'])
const documentsTask = await meilisearchClient
.waitTask()
await meilisearchClient
.index('geotest')
.addDocuments(geoDataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.updateSortableAttributes(['_geo'])
.waitTask()
await meilisearchClient.index('geotest').addDocuments(geoDataset).waitTask()
})

test('aroundRadius and aroundLatLng in geo search', async () => {
Expand Down
9 changes: 3 additions & 6 deletions packages/instant-meilisearch/__tests__/highlight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ import {

describe('Highlight Browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.updateFilterableAttributes(['genres'])
const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('one attributesToHighlight on wrong attribute placeholder', async () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/instant-meilisearch/__tests__/instantiation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ describe('InstantMeiliSearch instantiation', () => {

test('instantiation with custom request config with correct type', () => {
const searchClient = instantMeiliSearch('http://localhost:7700', '', {
requestConfig: {},
requestInit: {},
})

expect(searchClient).toBeTruthy()
})

test('instantiation with custom request config set to undefined', () => {
const searchClient = instantMeiliSearch('http://localhost:7700', '', {
requestConfig: undefined,
requestInit: undefined,
})

expect(searchClient).toBeTruthy()
Expand All @@ -62,9 +62,9 @@ describe('InstantMeiliSearch instantiation', () => {
expect(() => {
instantMeiliSearch('http://localhost:7700', '', {
// @ts-expect-error
requestConfig: '',
requestInit: '',
})
}).toThrow('Provided requestConfig should be an object')
}).toThrow('Provided requestInit should be an object')
})

test('instantiation with custom HTTP client with correct type', () => {
Expand Down
22 changes: 12 additions & 10 deletions packages/instant-meilisearch/__tests__/multi-index-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ describe('Multi-index search test', () => {
await moviesIndex.delete()
await gamesIndex.delete()

await moviesIndex.updateSettings({
filterableAttributes: ['genres', 'color', 'platforms'],
})
await gamesIndex.updateSettings({
filterableAttributes: ['genres', 'color', 'platforms'],
})

await moviesIndex.addDocuments(movies)
const response = await gamesIndex.addDocuments(games)
await moviesIndex
.updateSettings({
filterableAttributes: ['genres', 'color', 'platforms'],
})
.waitTask()
await gamesIndex
.updateSettings({
filterableAttributes: ['genres', 'color', 'platforms'],
})
.waitTask()

await meilisearchClient.waitForTask(response.taskUid)
await moviesIndex.addDocuments(movies).waitTask()
await gamesIndex.addDocuments(games).waitTask()
})

test('searching on two indexes', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import { dataset, meilisearchClient, type Movies } from './assets/utils.js'

describe('InstantMeiliSearch overridden parameters', () => {
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)
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('instantiating with, and changing overridden Meilisearch parameters', async () => {
Expand Down
9 changes: 3 additions & 6 deletions packages/instant-meilisearch/__tests__/pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ import {

describe('Pagination browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.updateFilterableAttributes(['genres'])
const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('1 hitsPerPage', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import { dataset, type Movies, meilisearchClient } from './assets/utils.js'

describe('Pagination browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.updateFilterableAttributes(['genres'])
const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('placeholdersearch set to true', async () => {
Expand Down
9 changes: 3 additions & 6 deletions packages/instant-meilisearch/__tests__/snippets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ import {

describe('Snippet Browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.updateFilterableAttributes(['genres'])
const documentsTask = await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.waitTask()
await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('Test one attributesToSnippet on placeholder without a snippetEllipsisText', async () => {
Expand Down
17 changes: 8 additions & 9 deletions packages/instant-meilisearch/__tests__/sort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import { splitSortString } from '../src/contexts/sort-context.js'

describe('Sort browser test', () => {
beforeAll(async () => {
const deleteTask = await meilisearchClient.deleteIndex('movies')
await meilisearchClient.waitForTask(deleteTask.taskUid)
await meilisearchClient.index('movies').updateSettings({
sortableAttributes: ['release_date', 'title'],
})

const documentsTask = await meilisearchClient
await meilisearchClient.deleteIndex('movies').waitTask()
await meilisearchClient
.index('movies')
.addDocuments(dataset)
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
.updateSettings({
sortableAttributes: ['release_date', 'title'],
})
.waitTask()

await meilisearchClient.index('movies').addDocuments(dataset).waitTask()
})

test('sort-by one field', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/instant-meilisearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"templates"
],
"dependencies": {
"meilisearch": "^0.49.0"
"meilisearch": "0.50"
},
"devDependencies": {
"cssnano": "^4.1.10",
Expand Down
8 changes: 4 additions & 4 deletions packages/instant-meilisearch/src/client/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function validateInstantMeiliSearchParams(
apiKey: string | (() => string),
instantMeiliSearchOptions: InstantMeiliSearchOptions
) {
const { requestConfig, httpClient } = instantMeiliSearchOptions
const { requestInit, httpClient } = instantMeiliSearchOptions
// Validate host url
if (typeof hostUrl !== 'string') {
throw new TypeError(
Expand All @@ -76,9 +76,9 @@ export function validateInstantMeiliSearchParams(
)
}

// Validate requestConfig
if (requestConfig !== undefined && !isPureObject(requestConfig)) {
throw new TypeError('Provided requestConfig should be an object')
// Validate requestInit
if (requestInit !== undefined && !isPureObject(requestInit)) {
throw new TypeError('Provided requestInit should be an object')
}

// Validate custom HTTP client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function instantMeiliSearch(
meilisearchConfig.httpClient = instantMeiliSearchOptions.httpClient
}

if (instantMeiliSearchOptions.requestConfig !== undefined) {
meilisearchConfig.requestConfig = instantMeiliSearchOptions.requestConfig
if (instantMeiliSearchOptions.requestInit !== undefined) {
meilisearchConfig.requestInit = instantMeiliSearchOptions.requestInit
}

const meilisearchClient = new MeiliSearch(meilisearchConfig)
Expand Down
Loading