-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get/update/reset methods for prefixSearch settings
- Loading branch information
Showing
3 changed files
with
227 additions
and
1 deletion.
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
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,9 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Test on prefix search settings > Admin key: Get prefixSearch settings on empty index 1`] = `"indexingTime"`; | ||
|
||
exports[`Test on prefix search settings > Admin key: Reset prefixSearch settings on an empty index 1`] = `"indexingTime"`; | ||
|
||
exports[`Test on prefix search settings > Master key: Get prefixSearch settings on empty index 1`] = `"indexingTime"`; | ||
|
||
exports[`Test on prefix search settings > Master key: Reset prefixSearch settings on an empty index 1`] = `"indexingTime"`; |
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,174 @@ | ||
import { afterAll, expect, test, describe, beforeEach } from "vitest"; | ||
import { ErrorStatusCode } from "../src/types"; | ||
import { | ||
clearAllIndexes, | ||
config, | ||
BAD_HOST, | ||
MeiliSearch, | ||
getClient, | ||
dataset, | ||
} from "./utils/meilisearch-test-utils"; | ||
|
||
const index = { | ||
uid: "movies_test", | ||
}; | ||
|
||
afterAll(() => { | ||
return clearAllIndexes(config); | ||
}); | ||
|
||
describe.each([{ permission: "Master" }, { permission: "Admin" }])( | ||
"Test on prefix search settings", | ||
({ permission }) => { | ||
beforeEach(async () => { | ||
await clearAllIndexes(config); | ||
const client = await getClient("Master"); | ||
const { taskUid } = await client.index(index.uid).addDocuments(dataset); | ||
await client.waitForTask(taskUid); | ||
}); | ||
|
||
test(`${permission} key: Get prefixSearch settings on empty index`, async () => { | ||
const client = await getClient(permission); | ||
|
||
const response = await client.index(index.uid).getPrefixSearch(); | ||
expect(response).toMatchSnapshot(); | ||
}); | ||
|
||
test(`${permission} key: Set prefixSearch settings with dedicated endpoint on empty index`, async () => { | ||
const client = await getClient(permission); | ||
|
||
const { taskUid } = await client.index(index.uid).updatePrefixSearch('disabled'); | ||
await client.index(index.uid).waitForTask(taskUid); | ||
|
||
const updatedSettings = await client.index(index.uid).getPrefixSearch(); | ||
expect(updatedSettings).toBe('disabled'); | ||
}); | ||
|
||
test(`${permission} key: Reset prefixSearch settings on an empty index`, async () => { | ||
const client = await getClient(permission); | ||
|
||
const { taskUid } = await client.index(index.uid).resetPrefixSearch(); | ||
await client.index(index.uid).waitForTask(taskUid); | ||
|
||
const response = await client.index(index.uid).getPrefixSearch(); | ||
expect(response).toMatchSnapshot(); | ||
}); | ||
}, | ||
); | ||
|
||
describe.each([{ permission: "Search" }])( | ||
"Test on prefix search settings", | ||
({ permission }) => { | ||
beforeEach(async () => { | ||
await clearAllIndexes(config); | ||
const client = await getClient("Master"); | ||
const { taskUid } = await client.createIndex(index.uid); | ||
await client.waitForTask(taskUid); | ||
}); | ||
|
||
test(`${permission} key: try to get prefix search settings and be denied`, async () => { | ||
const client = await getClient(permission); | ||
await expect( | ||
client.index(index.uid).getPrefixSearch(), | ||
).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); | ||
}); | ||
|
||
test(`${permission} key: try to update prefix search settings and be denied`, async () => { | ||
const client = await getClient(permission); | ||
await expect( | ||
client.index(index.uid).updatePrefixSearch('disabled'), | ||
).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); | ||
}); | ||
|
||
test(`${permission} key: try to reset prefix search settings and be denied`, async () => { | ||
const client = await getClient(permission); | ||
await expect( | ||
client.index(index.uid).resetPrefixSearch(), | ||
).rejects.toHaveProperty("cause.code", ErrorStatusCode.INVALID_API_KEY); | ||
}); | ||
}, | ||
); | ||
|
||
describe.each([{ permission: "No" }])( | ||
"Test on prefix search settings", | ||
({ permission }) => { | ||
beforeEach(async () => { | ||
await clearAllIndexes(config); | ||
const client = await getClient("Master"); | ||
const { taskUid } = await client.createIndex(index.uid); | ||
await client.waitForTask(taskUid); | ||
}); | ||
|
||
test(`${permission} key: try to get prefix search settings and be denied`, async () => { | ||
const client = await getClient(permission); | ||
await expect( | ||
client.index(index.uid).getPrefixSearch(), | ||
).rejects.toHaveProperty( | ||
"cause.code", | ||
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, | ||
); | ||
}); | ||
|
||
test(`${permission} key: try to update prefix search settings and be denied`, async () => { | ||
const client = await getClient(permission); | ||
await expect( | ||
client.index(index.uid).updatePrefixSearch('disabled'), | ||
).rejects.toHaveProperty( | ||
"cause.code", | ||
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER, | ||
); | ||
}); | ||
|
||
test(`${permission} key: try to reset prefix search settings and be denied`, async () => { | ||
const client = await getClient(permission); | ||
await expect( | ||
client.index(index.uid).resetPrefixSearch(), | ||
).rejects.toHaveProperty( | ||
"cause.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(`getPrefixSearch route`, async () => { | ||
const route = `indexes/${index.uid}/settings/prefix-search`; | ||
const client = new MeiliSearch({ host }); | ||
const strippedHost = trailing ? host.slice(0, -1) : host; | ||
await expect( | ||
client.index(index.uid).getPrefixSearch(), | ||
).rejects.toHaveProperty( | ||
"message", | ||
`Request to ${strippedHost}/${route} has failed`, | ||
); | ||
}); | ||
|
||
test(`updatePrefixSearch route`, async () => { | ||
const route = `indexes/${index.uid}/settings/prefix-search`; | ||
const client = new MeiliSearch({ host }); | ||
const strippedHost = trailing ? host.slice(0, -1) : host; | ||
await expect( | ||
client.index(index.uid).updatePrefixSearch('disabled'), | ||
).rejects.toHaveProperty( | ||
"message", | ||
`Request to ${strippedHost}/${route} has failed`, | ||
); | ||
}); | ||
|
||
test(`resetPrefixSearch route`, async () => { | ||
const route = `indexes/${index.uid}/settings/prefix-search`; | ||
const client = new MeiliSearch({ host }); | ||
const strippedHost = trailing ? host.slice(0, -1) : host; | ||
await expect( | ||
client.index(index.uid).resetPrefixSearch(), | ||
).rejects.toHaveProperty( | ||
"message", | ||
`Request to ${strippedHost}/${route} has failed`, | ||
); | ||
}); | ||
}); |