-
Notifications
You must be signed in to change notification settings - Fork 95
Add faceting index settings methods #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,203 @@ | ||
import { ErrorStatusCode } from '../src/types' | ||
import { | ||
clearAllIndexes, | ||
config, | ||
BAD_HOST, | ||
MeiliSearch, | ||
getClient, | ||
dataset, | ||
} from './utils/meilisearch-test-utils' | ||
|
||
const index = { | ||
uid: 'movies_test', | ||
} | ||
|
||
jest.setTimeout(100 * 1000) | ||
|
||
afterAll(() => { | ||
return clearAllIndexes(config) | ||
}) | ||
|
||
describe.each([{ permission: 'Master' }, { permission: 'Private' }])( | ||
'Test on faceting', | ||
({ permission }) => { | ||
beforeEach(async () => { | ||
await clearAllIndexes(config) | ||
const client = await getClient('Master') | ||
const { taskUid } = await client.createIndex(index.uid) | ||
await client.waitForTask(taskUid) | ||
|
||
const { taskUid: docTask } = await client | ||
.index(index.uid) | ||
.addDocuments(dataset) | ||
await client.waitForTask(docTask) | ||
}) | ||
|
||
test(`${permission} key: Get default faceting object`, async () => { | ||
const client = await getClient(permission) | ||
|
||
const response = await client.index(index.uid).getFaceting() | ||
|
||
expect(response).toEqual({ maxValuesPerFacet: 100 }) | ||
}) | ||
|
||
test(`${permission} key: Update faceting settings`, async () => { | ||
const client = await getClient(permission) | ||
const newFaceting = { maxValuesPerFacet: 12 } | ||
const task = await client.index(index.uid).updateFaceting(newFaceting) | ||
await client.index(index.uid).waitForTask(task.taskUid) | ||
|
||
const response = await client.index(index.uid).getFaceting() | ||
Ugzuzg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
expect(response).toEqual(newFaceting) | ||
}) | ||
|
||
test(`${permission} key: Update faceting at null`, async () => { | ||
const client = await getClient(permission) | ||
const task = await client | ||
.index(index.uid) | ||
.updateFaceting({ maxValuesPerFacet: null }) | ||
await client.index(index.uid).waitForTask(task.taskUid) | ||
|
||
const response = await client.index(index.uid).getFaceting() | ||
|
||
expect(response).toEqual({ maxValuesPerFacet: 100 }) | ||
}) | ||
|
||
test(`${permission} key: Reset faceting`, async () => { | ||
const client = await getClient(permission) | ||
await client | ||
.index(index.uid) | ||
.waitForTask( | ||
( | ||
await client | ||
.index(index.uid) | ||
.updateFaceting({ maxValuesPerFacet: 12 }) | ||
).taskUid | ||
) | ||
const task = await client.index(index.uid).resetFaceting() | ||
await client.index(index.uid).waitForTask(task.taskUid) | ||
|
||
const response = await client.index(index.uid).getFaceting() | ||
|
||
expect(response).toEqual({ maxValuesPerFacet: 100 }) | ||
}) | ||
} | ||
) | ||
|
||
describe.each([{ permission: 'Public' }])( | ||
'Test on faceting', | ||
({ permission }) => { | ||
beforeEach(async () => { | ||
const client = await getClient('Master') | ||
const { taskUid } = await client.createIndex(index.uid) | ||
await client.waitForTask(taskUid) | ||
}) | ||
|
||
test(`${permission} key: try to get faceting and be denied`, async () => { | ||
const client = await getClient(permission) | ||
await expect( | ||
client.index(index.uid).getFaceting() | ||
).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY) | ||
}) | ||
|
||
test(`${permission} key: try to update faceting and be denied`, async () => { | ||
const client = await getClient(permission) | ||
await expect( | ||
client.index(index.uid).updateFaceting({ maxValuesPerFacet: 13 }) | ||
).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY) | ||
}) | ||
|
||
test(`${permission} key: try to reset faceting and be denied`, async () => { | ||
const client = await getClient(permission) | ||
await expect( | ||
client.index(index.uid).resetFaceting() | ||
).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY) | ||
}) | ||
} | ||
) | ||
|
||
describe.each([{ permission: 'No' }])('Test on faceting', ({ permission }) => { | ||
beforeAll(async () => { | ||
const client = await getClient('Master') | ||
const { taskUid } = await client.createIndex(index.uid) | ||
await client.waitForTask(taskUid) | ||
}) | ||
|
||
test(`${permission} key: try to get faceting and be denied`, async () => { | ||
const client = await getClient(permission) | ||
await expect(client.index(index.uid).getFaceting()).rejects.toHaveProperty( | ||
'code', | ||
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER | ||
) | ||
}) | ||
|
||
test(`${permission} key: try to update faceting and be denied`, async () => { | ||
const client = await getClient(permission) | ||
await expect( | ||
client.index(index.uid).updateFaceting({ maxValuesPerFacet: 13 }) | ||
).rejects.toHaveProperty( | ||
'code', | ||
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER | ||
) | ||
}) | ||
|
||
test(`${permission} key: try to reset faceting and be denied`, async () => { | ||
const client = await getClient(permission) | ||
await expect( | ||
client.index(index.uid).resetFaceting() | ||
).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 getFaceting route`, async () => { | ||
const route = `indexes/${index.uid}/settings/faceting` | ||
const client = new MeiliSearch({ host }) | ||
const strippedHost = trailing ? host.slice(0, -1) : host | ||
await expect(client.index(index.uid).getFaceting()).rejects.toHaveProperty( | ||
'message', | ||
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( | ||
'http://', | ||
'' | ||
)}` | ||
) | ||
}) | ||
|
||
test(`Test updateFaceting route`, async () => { | ||
const route = `indexes/${index.uid}/settings/faceting` | ||
const client = new MeiliSearch({ host }) | ||
const strippedHost = trailing ? host.slice(0, -1) : host | ||
await expect( | ||
client.index(index.uid).updateFaceting({ maxValuesPerFacet: null }) | ||
).rejects.toHaveProperty( | ||
'message', | ||
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( | ||
'http://', | ||
'' | ||
)}` | ||
) | ||
}) | ||
|
||
test(`Test resetFaceting route`, async () => { | ||
const route = `indexes/${index.uid}/settings/faceting` | ||
const client = new MeiliSearch({ host }) | ||
const strippedHost = trailing ? host.slice(0, -1) : host | ||
await expect( | ||
client.index(index.uid).resetFaceting() | ||
).rejects.toHaveProperty( | ||
'message', | ||
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace( | ||
'http://', | ||
'' | ||
)}` | ||
) | ||
}) | ||
}) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for noticing this error 🙏