Add a helper method for getting the latest batch

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
This commit is contained in:
Martin Tzvetanov Grigorov
2025-06-03 11:15:27 +03:00
parent 48460678df
commit 2691999bd3
2 changed files with 14 additions and 1 deletions

View File

@ -1309,7 +1309,7 @@ async fn test_summarized_dump_creation() {
let server = Server::new_shared();
let (task, _status_code) = server.create_dump().await;
server.wait_task(task.uid()).await.succeeded();
let (batch, _) = server.get_batch(task.uid() as u32).await;
let (batch, _) = server.get_latest_batch().await;
assert_json_snapshot!(batch,
{
".uid" => "[uid]",

View File

@ -429,6 +429,19 @@ impl<State> Server<State> {
self.service.get(url).await
}
// https://www.meilisearch.com/docs/reference/api/batches#get-batches states:
// "Batches are always returned in descending order of uid. This means that by default,
// the most recently created batch objects appear first."
pub async fn get_latest_batch(&self) -> (Option<Value>, StatusCode) {
let url = "/batches?limit=1&offset=0";
let (value, code) = self.service.get(url).await;
value
.get("results")
.and_then(|results| results.as_array())
.and_then(|array| array.first())
.map_or((None, code), |latest| (Some(Value(latest.clone())), code))
}
pub async fn get_features(&self) -> (Value, StatusCode) {
self.service.get("/experimental-features").await
}