implements the reverse query parameter for the batches

This commit is contained in:
Tamo 2024-11-20 13:29:52 +01:00
parent 8ad68dd708
commit a7ac590e9e
No known key found for this signature in database
GPG key ID: 20CD8020AFA88D69
3 changed files with 119 additions and 22 deletions

View file

@ -114,6 +114,33 @@ async fn batch_bad_from() {
"#);
}
#[actix_rt::test]
async fn bask_bad_reverse() {
let server = Server::new_shared();
let (response, code) = server.batches_filter("reverse=doggo").await;
snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###"
{
"message": "Invalid value in parameter `reverse`: could not parse `doggo` as a boolean, expected either `true` or `false`",
"code": "invalid_task_reverse",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_task_reverse"
}
"###);
let (response, code) = server.batches_filter("reverse=*").await;
snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###"
{
"message": "Invalid value in parameter `reverse`: could not parse `*` as a boolean, expected either `true` or `false`",
"code": "invalid_task_reverse",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_task_reverse"
}
"###);
}
#[actix_rt::test]
async fn batch_bad_after_enqueued_at() {
let server = Server::new_shared();

View file

@ -49,6 +49,44 @@ async fn list_batches() {
assert_eq!(response["results"].as_array().unwrap().len(), 2);
}
#[actix_rt::test]
async fn list_batches_pagination_and_reverse() {
let server = Server::new().await;
// First of all we want to create a lot of batches very quickly. The fastest way is to delete a lot of unexisting indexes
let mut last_batch = None;
for i in 0..10 {
let index = server.index(format!("test-{i}"));
last_batch = Some(index.create(None).await.0.uid());
}
server.wait_task(last_batch.unwrap()).await;
let (response, code) = server.batches_filter("limit=3").await;
assert_eq!(code, 200);
let results = response["results"].as_array().unwrap();
let batch_ids: Vec<_> = results.iter().map(|ret| ret["uid"].as_u64().unwrap()).collect();
snapshot!(format!("{batch_ids:?}"), @"[9, 8, 7]");
let (response, code) = server.batches_filter("limit=3&from=1").await;
assert_eq!(code, 200);
let results = response["results"].as_array().unwrap();
let batch_ids: Vec<_> = results.iter().map(|ret| ret["uid"].as_u64().unwrap()).collect();
snapshot!(format!("{batch_ids:?}"), @"[1, 0]");
// In reversed order
let (response, code) = server.batches_filter("limit=3&reverse=true").await;
assert_eq!(code, 200);
let results = response["results"].as_array().unwrap();
let batch_ids: Vec<_> = results.iter().map(|ret| ret["uid"].as_u64().unwrap()).collect();
snapshot!(format!("{batch_ids:?}"), @"[0, 1, 2]");
let (response, code) = server.batches_filter("limit=3&from=8&reverse=true").await;
assert_eq!(code, 200);
let results = response["results"].as_array().unwrap();
let batch_ids: Vec<_> = results.iter().map(|ret| ret["uid"].as_u64().unwrap()).collect();
snapshot!(format!("{batch_ids:?}"), @"[8, 9]");
}
#[actix_rt::test]
async fn list_batches_with_star_filters() {
let server = Server::new().await;