Skip to content

Commit

Permalink
Merge #1323
Browse files Browse the repository at this point in the history
1323: Changes related to the next Meilisearch release (v0.29.0) r=bidoubiwa a=meili-bot

Related to this issue: meilisearch/integration-guides#211

This PR:
- gathers the changes related to the next Meilisearch release (v0.29.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases).
- might eventually contain test failures until the Meilisearch v0.29.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.29.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._


Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 3, 2022
2 parents ba2bd71 + 7ad3946 commit 3c8f8d4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ controller.abort()

## 🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).
This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0).

## 💡 Learn more

Expand Down
6 changes: 6 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export type IndexesResults<T> = ResourceResults<T> & {}
* SEARCH PARAMETERS
*/

export const enum MatchingStrategies {
ALL = 'all',
LAST = 'last',
}

export type Filter = string | Array<string | string[]>

export type Query = {
Expand Down Expand Up @@ -77,6 +82,7 @@ export type SearchParams = Query &
facets?: string[]
attributesToRetrieve?: string[]
showMatchesPosition?: boolean
matchingStrategy?: MatchingStrategies
}

// Search parameters for searches made with the GET method
Expand Down
28 changes: 28 additions & 0 deletions tests/keys.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import MeiliSearch from '../src/browser'
import { ErrorStatusCode } from '../src/types'
import {
clearAllIndexes,
config,
getClient,
getKey,
HOST,
} from './utils/meilisearch-test-utils'

beforeEach(async () => {
Expand Down Expand Up @@ -116,6 +118,32 @@ describe.each([{ permission: 'Master' }, { permission: 'Private' }])(
expect(key).toHaveProperty('expiresAt', null)
})

test(`${permission} key: create key with actions using wildcards to provide rights`, async () => {
const client = await getClient(permission)
const uid = '3db051e0-423d-4b5c-a63a-f82a7043dce6'

const key = await client.createKey({
uid,
description: 'Indexing Products API key',
actions: ['indexes.*', 'tasks.*', 'documents.*'],
indexes: ['wildcard_keys_permission'],
expiresAt: null,
})

const newClient = new MeiliSearch({ host: HOST, apiKey: key.key })
await newClient.createIndex('wildcard_keys_permission') // test index creation
const taskInfo = await newClient
.index('wildcard_keys_permission')
.addDocuments([{ id: 1 }]) // test document addition
const task = await newClient.waitForTask(taskInfo.taskUid) // test fetching of tasks

expect(key).toBeDefined()
expect(task.status).toBe('succeeded')
expect(key).toHaveProperty('description', 'Indexing Products API key')
expect(key).toHaveProperty('uid', uid)
expect(key).toHaveProperty('expiresAt', null)
})

test(`${permission} key: create key with an expiresAt`, async () => {
const client = await getClient(permission)

Expand Down
32 changes: 30 additions & 2 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AbortController from 'abort-controller'
import { ErrorStatusCode, EnqueuedTask } from '../src/types'
import { ErrorStatusCode, EnqueuedTask, MatchingStrategies } from '../src/types'
import {
clearAllIndexes,
config,
Expand Down Expand Up @@ -95,6 +95,32 @@ describe.each([
expect(response.hits.length).toEqual(2)
})

test(`${permission} key: Basic phrase search with matchingStrategy at ALL`, async () => {
const client = await getClient(permission)
const response = await client
.index(index.uid)
.search('"french book" about', {
matchingStrategy: MatchingStrategies.ALL,
})

expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response.hits.length).toEqual(1)
})

test(`${permission} key: Basic phrase search with matchingStrategy at LAST`, async () => {
const client = await getClient(permission)
const response = await client
.index(index.uid)
.search('french book', { matchingStrategy: MatchingStrategies.LAST })

expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response.hits.length).toEqual(2)
})

test(`${permission} key: Search with query in searchParams overwriting query`, async () => {
const client = await getClient(permission)
const response = await client
Expand All @@ -121,7 +147,8 @@ describe.each([
expect(response.hits.length).toEqual(2)
})

test(`${permission} key: Basic phrase search`, async () => {
// TODO: remove skip when bug is fixed by core
test.skip(`${permission} key: Basic phrase search`, async () => {
const client = await getClient(permission)
const response = await client
.index(index.uid)
Expand All @@ -131,6 +158,7 @@ describe.each([
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', '"french book" about')

expect(response.hits.length).toEqual(2)
})

Expand Down

0 comments on commit 3c8f8d4

Please sign in to comment.