diff --git a/src/data/updates.rs b/src/data/updates.rs index 92d682b1d..fbb9be801 100644 --- a/src/data/updates.rs +++ b/src/data/updates.rs @@ -1,13 +1,13 @@ use std::ops::Deref; -use milli::update::{IndexDocumentsMethod, UpdateFormat}; use async_compression::tokio_02::write::GzipEncoder; use futures_util::stream::StreamExt; +use milli::update::{IndexDocumentsMethod, UpdateFormat}; use tokio::io::AsyncWriteExt; -use super::Data; -use crate::index_controller::{IndexController, Settings, IndexSettings, IndexMetadata}; use crate::index_controller::UpdateStatus; +use crate::index_controller::{IndexController, Settings, IndexSettings, IndexMetadata}; +use super::Data; impl Data { pub async fn add_documents( diff --git a/tests/common/index.rs b/tests/common/index.rs index 69b383b4a..5f297bbb5 100644 --- a/tests/common/index.rs +++ b/tests/common/index.rs @@ -24,4 +24,13 @@ impl Index<'_> { }); self.service.post("/indexes", body).await } + + pub async fn update(&self, primary_key: Option<&str>) -> (Value, StatusCode) { + let body = json!({ + "primaryKey": primary_key, + }); + let url = format!("/indexes/{}", self.uid); + + self.service.put(url, body).await + } } diff --git a/tests/common/server.rs b/tests/common/server.rs index 5982af973..23aba5010 100644 --- a/tests/common/server.rs +++ b/tests/common/server.rs @@ -165,23 +165,6 @@ impl Server { //(response, status_code) //} - //pub async fn put_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) { - //eprintln!("put_request: {}", url); - - //let mut app = - //test::init_service(meilisearch_http::create_app(&self.data, true).wrap(NormalizePath)).await; - - //let req = test::TestRequest::put() - //.uri(url) - //.set_json(&body) - //.to_request(); - //let res = test::call_service(&mut app, req).await; - //let status_code = res.status(); - - //let body = test::read_body(res).await; - //let response = serde_json::from_slice(&body).unwrap_or_default(); - //(response, status_code) - //} //pub async fn put_request_async(&mut self, url: &str, body: Value) -> (Value, StatusCode) { //eprintln!("put_request_async: {}", url); diff --git a/tests/common/service.rs b/tests/common/service.rs index 21442cf64..0ff1320df 100644 --- a/tests/common/service.rs +++ b/tests/common/service.rs @@ -35,5 +35,21 @@ impl Service { let response = serde_json::from_slice(&body).unwrap_or_default(); (response, status_code) } + + pub async fn put(&self, url: impl AsRef, body: Value) -> (Value, StatusCode) { + let mut app = + test::init_service(meilisearch_http::create_app(&self.0, true).wrap(NormalizePath)).await; + + let req = test::TestRequest::put() + .uri(url.as_ref()) + .set_json(&body) + .to_request(); + let res = test::call_service(&mut app, req).await; + let status_code = res.status(); + + let body = test::read_body(res).await; + let response = serde_json::from_slice(&body).unwrap_or_default(); + (response, status_code) + } } diff --git a/tests/index/mod.rs b/tests/index/mod.rs index cd3203e6b..2aefd99c2 100644 --- a/tests/index/mod.rs +++ b/tests/index/mod.rs @@ -1,2 +1,3 @@ mod create_index; mod get_index; +mod update_index;