Skip to content

Commit 7ad3946

Browse files
authored
Add tests on keys action for v0.29.1 (#1325)
* Update search params for v0.29.0 * Add tests on keys action for v0.29.1 * Remove skipped test
1 parent aaec2d9 commit 7ad3946

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/keys.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import MeiliSearch from '../src/browser'
12
import { ErrorStatusCode } from '../src/types'
23
import {
34
clearAllIndexes,
45
config,
56
getClient,
67
getKey,
8+
HOST,
79
} from './utils/meilisearch-test-utils'
810

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

121+
test(`${permission} key: create key with actions using wildcards to provide rights`, async () => {
122+
const client = await getClient(permission)
123+
const uid = '3db051e0-423d-4b5c-a63a-f82a7043dce6'
124+
125+
const key = await client.createKey({
126+
uid,
127+
description: 'Indexing Products API key',
128+
actions: ['indexes.*', 'tasks.*', 'documents.*'],
129+
indexes: ['wildcard_keys_permission'],
130+
expiresAt: null,
131+
})
132+
133+
const newClient = new MeiliSearch({ host: HOST, apiKey: key.key })
134+
await newClient.createIndex('wildcard_keys_permission') // test index creation
135+
const taskInfo = await newClient
136+
.index('wildcard_keys_permission')
137+
.addDocuments([{ id: 1 }]) // test document addition
138+
const task = await newClient.waitForTask(taskInfo.taskUid) // test fetching of tasks
139+
140+
expect(key).toBeDefined()
141+
expect(task.status).toBe('succeeded')
142+
expect(key).toHaveProperty('description', 'Indexing Products API key')
143+
expect(key).toHaveProperty('uid', uid)
144+
expect(key).toHaveProperty('expiresAt', null)
145+
})
146+
119147
test(`${permission} key: create key with an expiresAt`, async () => {
120148
const client = await getClient(permission)
121149

0 commit comments

Comments
 (0)