diff --git a/crates/meilisearch/tests/common/mod.rs b/crates/meilisearch/tests/common/mod.rs index 3aae2fe80..44385752e 100644 --- a/crates/meilisearch/tests/common/mod.rs +++ b/crates/meilisearch/tests/common/mod.rs @@ -52,6 +52,25 @@ impl Value { } self } + + /// Return `true` if the `status` field is set to `failed`. + /// Panic if the `status` field doesn't exists. + #[track_caller] + pub fn is_fail(&self) -> bool { + if !self["status"].is_string() { + panic!("Called `is_fail` on {}", serde_json::to_string_pretty(&self.0).unwrap()); + } + self["status"] == serde_json::Value::String(String::from("failed")) + } + + // Panic if the json doesn't contain the `status` field set to "succeeded" + #[track_caller] + pub fn failed(&self) -> &Self { + if !self.is_fail() { + panic!("Called failed on {}", serde_json::to_string_pretty(&self.0).unwrap()); + } + self + } } impl From for Value { diff --git a/crates/meilisearch/tests/snapshot/mod.rs b/crates/meilisearch/tests/snapshot/mod.rs index 976551190..0d569fc7c 100644 --- a/crates/meilisearch/tests/snapshot/mod.rs +++ b/crates/meilisearch/tests/snapshot/mod.rs @@ -129,11 +129,11 @@ async fn perform_on_demand_snapshot() { index.load_test_set().await; - server.index("doggo").create(Some("bone")).await; - index.wait_task(2).await; + let (task, _) = server.index("doggo").create(Some("bone")).await; + index.wait_task(task.uid()).await.succeeded(); - server.index("doggo").create(Some("bone")).await; - index.wait_task(2).await; + let (task, _) = server.index("doggo").create(Some("bone")).await; + index.wait_task(task.uid()).await.failed(); let (task, code) = server.create_snapshot().await; snapshot!(code, @"202 Accepted");