Skip to content

Commit

Permalink
Merge #1594
Browse files Browse the repository at this point in the history
1594: Changes related to the next Meilisearch release (v1.5.0) r=brunoocasali a=meili-bot

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

This PR:
- gathers the changes related to the next Meilisearch release (v1.5.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 v1.5.0 is out.

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

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


Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
Co-authored-by: meili-bors[bot] <89034592+meili-bors[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 20, 2023
2 parents f5b0f1f + 2140aa3 commit 30ca527
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ faceted_search_1: |-
client.index('books').search('classic', { facets: ['genres', 'rating', 'language'] })
post_dump_1: |-
client.createDump()
create_snapshot_1: |-
client.createSnapshot()
phrase_search_1: |-
client.index('movies')
.search('"african american" horror')
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,13 @@ client.getVersion(): Promise<Version>
client.createDump(): Promise<EnqueuedTask>
```

### Snapshots <!-- omit in toc -->

#### [Trigger a snapshot on-demand process](https://www.meilisearch.com/docs/reference/api/snapshots#create-a-snapshot)

```ts
client.createSnapshot(): Promise<EnqueuedTask>
```
---

Meilisearch provides and maintains many SDKs and integration tools like this one. We want to provide everyone with an **amazing search experience for any kind of project**. For a full overview of everything we create and maintain, take a look at the [integration-guides](https://github.com/meilisearch/integration-guides) repository.
16 changes: 16 additions & 0 deletions src/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,22 @@ class Client {
return new EnqueuedTask(task)
}

///
/// SNAPSHOTS
///

/**
* Creates a snapshot
*
* @returns Promise returning object of the enqueued task
*/
async createSnapshot(): Promise<EnqueuedTask> {
const url = `snapshots`
const task = await this.httpRequest.post<undefined, EnqueuedTaskObject>(url)

return new EnqueuedTask(task)
}

///
/// TOKENS
///
Expand Down
70 changes: 70 additions & 0 deletions tests/snapshots.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { ErrorStatusCode } from '../src/types'
import {
clearAllIndexes,
config,
MeiliSearch,
BAD_HOST,
getClient,
} from './utils/meilisearch-test-utils'

beforeEach(async () => {
await clearAllIndexes(config)
})

describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
'Test on snapshot',
({ permission }) => {
test(`${permission} key: create a new snapshot`, async () => {
const client = await getClient(permission)
const { taskUid } = await client.createSnapshot()

await client.waitForTask(taskUid)
})
}
)

describe.each([{ permission: 'Search' }])(
'Test on snapshot with search api key should not have access',
({ permission }) => {
test(`${permission} key: try to create snapshot with search key and be denied`, async () => {
const client = await getClient(permission)
await expect(client.createSnapshot()).rejects.toHaveProperty(
'code',
ErrorStatusCode.INVALID_API_KEY
)
})
}
)

describe.each([{ permission: 'No' }])(
'Test on snapshot without api key should not have access',
({ permission }) => {
test(`${permission} key: try to create snapshot with no key and be denied`, async () => {
const client = await getClient(permission)
await expect(client.createSnapshot()).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
}
)

describe.each([
{ host: BAD_HOST, trailing: false },
{ host: `${BAD_HOST}/api`, trailing: false },
{ host: `${BAD_HOST}/trailing/`, trailing: true },
])('Tests on url construction', ({ host, trailing }) => {
test(`Test createSnapshot route`, async () => {
const route = `snapshots`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host

await expect(client.createSnapshot()).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
})

0 comments on commit 30ca527

Please sign in to comment.