Improve Integration tests in Update_index.rs file

This commit is contained in:
Santhosh Reddy Vootukuri (SUNNY) (from Dev Box) 2024-08-10 09:13:30 -07:00
parent 321639364f
commit ebd3236c60

View File

@ -7,15 +7,15 @@ use crate::json;
#[actix_rt::test] #[actix_rt::test]
async fn update_primary_key() { async fn update_primary_key() {
let server = Server::new().await; let server = Server::new_shared().await;
let index = server.index("test"); let index = server.unique_index();
let (_, code) = index.create(None).await; let (task, code) = index.create(None).await;
assert_eq!(code, 202); assert_eq!(code, 202);
index.update(Some("primary")).await; index.update(Some("primary")).await;
let response = index.wait_task(1).await; let response = index.wait_task(task.uid()).await.succeeded();
assert_eq!(response["status"], "succeeded"); assert_eq!(response["status"], "succeeded");
@ -39,44 +39,44 @@ async fn update_primary_key() {
#[actix_rt::test] #[actix_rt::test]
async fn create_and_update_with_different_encoding() { async fn create_and_update_with_different_encoding() {
let server = Server::new().await; let server = Server::new_shared().await;
let index = server.index_with_encoder("test", Encoder::Gzip); let index = server.index_with_encoder("test", Encoder::Gzip);
let (_, code) = index.create(None).await; let (task, code) = index.create(None).await;
assert_eq!(code, 202); assert_eq!(code, 202);
let index = server.index_with_encoder("test", Encoder::Brotli); let index = server.index_with_encoder("test", Encoder::Brotli);
index.update(Some("primary")).await; index.update(Some("primary")).await;
let response = index.wait_task(1).await; let response = index.wait_task(task.uid()).await.succeeded();
assert_eq!(response["status"], "succeeded"); assert_eq!(response["status"], "succeeded");
} }
#[actix_rt::test] #[actix_rt::test]
async fn update_nothing() { async fn update_nothing() {
let server = Server::new().await; let server = Server::new_shared().await;
let index = server.index("test"); let index = server.unique_index();
let (_, code) = index.create(None).await; let (task, code) = index.create(None).await;
assert_eq!(code, 202); assert_eq!(code, 202);
index.wait_task(0).await; index.wait_task(task.uid()).await.succeeded();
let (_, code) = index.update(None).await; let (task, code) = index.update(None).await;
assert_eq!(code, 202); assert_eq!(code, 202);
let response = index.wait_task(1).await; let response = index.wait_task(task.uid()).await.succeeded();
assert_eq!(response["status"], "succeeded"); assert_eq!(response["status"], "succeeded");
} }
#[actix_rt::test] #[actix_rt::test]
async fn error_update_existing_primary_key() { async fn error_update_existing_primary_key() {
let server = Server::new().await; let server = Server::new_shared().await;
let index = server.index("test"); let index = server.unique_index();
let (_response, code) = index.create(Some("id")).await; let (task, code) = index.create(Some("id")).await;
assert_eq!(code, 202); assert_eq!(code, 202);
@ -88,11 +88,11 @@ async fn error_update_existing_primary_key() {
]); ]);
index.add_documents(documents, None).await; index.add_documents(documents, None).await;
let (_, code) = index.update(Some("primary")).await; let (task, code) = index.update(Some("primary")).await;
assert_eq!(code, 202); assert_eq!(code, 202);
let response = index.wait_task(2).await; let response = index.wait_task(task.uid()).await.succeeded();
let expected_response = json!({ let expected_response = json!({
"message": "Index already has a primary key: `id`.", "message": "Index already has a primary key: `id`.",
@ -106,15 +106,16 @@ async fn error_update_existing_primary_key() {
#[actix_rt::test] #[actix_rt::test]
async fn error_update_unexisting_index() { async fn error_update_unexisting_index() {
let server = Server::new().await; let server = Server::new_shared().await;
let (_, code) = server.index("test").update(None).await; let index = shared_does_not_exists_index();
let (task, code) = index.update(None).await;
assert_eq!(code, 202); assert_eq!(code, 202);
let response = server.index("test").wait_task(0).await; let response = index.wait_task(task.uid()).await.succeeded();
let expected_response = json!({ let expected_response = json!({
"message": "Index `test` not found.", "message": "Index `DOES_NOT_EXISTS` not found.",
"code": "index_not_found", "code": "index_not_found",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found" "link": "https://docs.meilisearch.com/errors#index_not_found"