diff --git a/src/index_controller/updates.rs b/src/index_controller/updates.rs index b8f1e31f4..b15593b58 100644 --- a/src/index_controller/updates.rs +++ b/src/index_controller/updates.rs @@ -42,6 +42,7 @@ impl Pending { } #[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct Processed { pub success: N, pub processed_at: DateTime, @@ -56,6 +57,7 @@ impl Processed { } #[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct Processing { #[serde(flatten)] pub from: Pending, @@ -89,6 +91,7 @@ impl Processing { } #[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct Aborted { #[serde(flatten)] from: Pending, @@ -102,6 +105,7 @@ impl Aborted { } #[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct Failed { #[serde(flatten)] from: Processing, diff --git a/tests/common/index.rs b/tests/common/index.rs index 0b80f3fde..182f9e238 100644 --- a/tests/common/index.rs +++ b/tests/common/index.rs @@ -1,5 +1,8 @@ +use std::time::Duration; + use actix_web::http::StatusCode; use serde_json::{json, Value}; +use tokio::time::delay_for; use super::service::Service; @@ -14,10 +17,7 @@ impl Index<'_> { self.service.get(url).await } - pub async fn create<'a>( - &'a self, - primary_key: Option<&str>, - ) -> (Value, StatusCode) { + pub async fn create<'a>(&'a self, primary_key: Option<&str>) -> (Value, StatusCode) { let body = json!({ "uid": self.uid, "primaryKey": primary_key, @@ -38,4 +38,43 @@ impl Index<'_> { let url = format!("/indexes/{}", self.uid); self.service.delete(url).await } + + pub async fn add_documents( + &self, + documents: Value, + primary_key: Option<&str>, + ) -> (Value, StatusCode) { + let url = match primary_key { + Some(key) => format!("/indexes/{}/documents?primaryKey={}", self.uid, key), + None => format!("/indexes/{}/documents", self.uid), + }; + self.service.post(url, documents).await + } + + pub async fn wait_update_id(&self, update_id: u64) { + // try 10 times to get status, or panic to not wait forever + let url = format!("/indexes/{}/updates/{}", self.uid, update_id); + for _ in 0..10 { + let (response, status_code) = self.service.get(&url).await; + assert_eq!(status_code, 200); + + if response["status"] == "processed" || response["status"] == "failed" { + return; + } + + delay_for(Duration::from_secs(1)).await; + } + panic!("Timeout waiting for update id"); + } + + pub async fn get_update(&self, udpate_id: usize) -> (Value, StatusCode) { + let url = format!("/indexes/{}/updates/{}", self.uid, udpate_id); + self.service.get(url).await + } + + #[allow(dead_code)] + pub async fn list_updates(&self) -> (Value, StatusCode) { + let url = format!("/indexes/{}/updates", self.uid); + self.service.get(url).await + } } diff --git a/tests/common/service.rs b/tests/common/service.rs index b00552562..8d19c4a49 100644 --- a/tests/common/service.rs +++ b/tests/common/service.rs @@ -64,5 +64,6 @@ impl Service { let response = serde_json::from_slice(&body).unwrap_or_default(); (response, status_code) } + } diff --git a/tests/integration.rs b/tests/integration.rs index 9d9ba64e3..34fbde4b6 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,6 +1,8 @@ mod common; -mod search; mod index; +mod search; +mod settings; +mod documents; // Tests are isolated by features in different modules to allow better readability, test // targetability, and improved incremental compilation times.