From 3c696da2747551a2b2223f2c47c74de2051543b5 Mon Sep 17 00:00:00 2001 From: many Date: Thu, 4 Nov 2021 17:03:13 +0100 Subject: [PATCH 1/2] Update tests --- .../tests/documents/add_documents.rs | 127 +++++++++--------- .../tests/settings/get_settings.rs | 19 ++- 2 files changed, 72 insertions(+), 74 deletions(-) diff --git a/meilisearch-http/tests/documents/add_documents.rs b/meilisearch-http/tests/documents/add_documents.rs index 23f52f0a9..689537022 100644 --- a/meilisearch-http/tests/documents/add_documents.rs +++ b/meilisearch-http/tests/documents/add_documents.rs @@ -812,13 +812,15 @@ async fn error_add_documents_bad_document_id() { let (response, code) = index.get_update(0).await; assert_eq!(code, 200); assert_eq!(response["status"], json!("failed")); - assert_eq!(response["message"], json!("Document identifier `foo & bar` is invalid. A document identifier can be of type integer or string, only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_).")); - assert_eq!(response["code"], json!("invalid_document_id")); - assert_eq!(response["type"], json!("invalid_request")); - assert_eq!( - response["link"], - json!("https://docs.meilisearch.com/errors#invalid_document_id") - ); + + let expected_error = json!({ + "message": "Document identifier `foo & bar` is invalid. A document identifier can be of type integer or string, only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_).", + "code": "invalid_document_id", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_document_id" + }); + + assert_eq!(response["error"], expected_error); } #[actix_rt::test] @@ -837,13 +839,15 @@ async fn error_update_documents_bad_document_id() { let (response, code) = index.get_update(0).await; assert_eq!(code, 200); assert_eq!(response["status"], json!("failed")); - assert_eq!(response["message"], json!("Document identifier `foo & bar` is invalid. A document identifier can be of type integer or string, only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_).")); - assert_eq!(response["code"], json!("invalid_document_id")); - assert_eq!(response["type"], json!("invalid_request")); - assert_eq!( - response["link"], - json!("https://docs.meilisearch.com/errors#invalid_document_id") - ); + + let expected_error = json!({ + "message": "Document identifier `foo & bar` is invalid. A document identifier can be of type integer or string, only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_).", + "code": "invalid_document_id", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_document_id" + }); + + assert_eq!(response["error"], expected_error); } #[actix_rt::test] @@ -862,16 +866,15 @@ async fn error_add_documents_missing_document_id() { let (response, code) = index.get_update(0).await; assert_eq!(code, 200); assert_eq!(response["status"], "failed"); - assert_eq!( - response["message"], - json!(r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#) - ); - assert_eq!(response["code"], json!("missing_document_id")); - assert_eq!(response["type"], json!("invalid_request")); - assert_eq!( - response["link"], - json!("https://docs.meilisearch.com/errors#missing_document_id") - ); + + let expected_error = json!({ + "message": r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#, + "code": "missing_document_id", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#missing_document_id" + }); + + assert_eq!(response["error"], expected_error); } #[actix_rt::test] @@ -890,16 +893,15 @@ async fn error_update_documents_missing_document_id() { let (response, code) = index.get_update(0).await; assert_eq!(code, 200); assert_eq!(response["status"], "failed"); - assert_eq!( - response["message"], - r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."# - ); - assert_eq!(response["code"], "missing_document_id"); - assert_eq!(response["type"], "invalid_request"); - assert_eq!( - response["link"], - "https://docs.meilisearch.com/errors#missing_document_id" - ); + + let expected_error = json!({ + "message": r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#, + "code": "missing_document_id", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#missing_document_id" + }); + + assert_eq!(response["error"], expected_error); } #[actix_rt::test] @@ -927,16 +929,15 @@ async fn error_document_field_limit_reached() { assert_eq!(code, 200); // Documents without a primary key are not accepted. assert_eq!(response["status"], "failed"); - assert_eq!( - response["message"], - "A document cannot contain more than 65,535 fields." - ); - assert_eq!(response["code"], "document_fields_limit_reached"); - assert_eq!(response["type"], "invalid_request"); - assert_eq!( - response["link"], - "https://docs.meilisearch.com/errors#document_fields_limit_reached" - ); + + let expected_error = json!({ + "message": "A document cannot contain more than 65,535 fields.", + "code": "document_fields_limit_reached", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#document_fields_limit_reached" + }); + + assert_eq!(response["error"], expected_error); } #[actix_rt::test] @@ -960,16 +961,15 @@ async fn error_add_documents_invalid_geo_field() { let (response, code) = index.get_update(1).await; assert_eq!(code, 200); assert_eq!(response["status"], "failed"); - assert_eq!( - response["message"], - r#"The document with the id: `11` contains an invalid _geo field: `foobar`."# - ); - assert_eq!(response["code"], "invalid_geo_field"); - assert_eq!(response["type"], "invalid_request"); - assert_eq!( - response["link"], - "https://docs.meilisearch.com/errors#invalid_geo_field" - ); + + let expected_error = json!({ + "message": r#"The document with the id: `11` contains an invalid _geo field: `foobar`."#, + "code": "invalid_geo_field", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_geo_field" + }); + + assert_eq!(response["error"], expected_error); } #[actix_rt::test] @@ -1015,14 +1015,13 @@ async fn error_primary_key_inference() { let (response, code) = index.get_update(0).await; assert_eq!(code, 200); assert_eq!(response["status"], "failed"); - assert_eq!( - response["message"], - r#"The primary key inference process failed because the engine did not find any fields containing `id` substring in their name. If your document identifier does not contain any `id` substring, you can set the primary key of the index."# - ); - assert_eq!(response["code"], "primary_key_inference_failed"); - assert_eq!(response["type"], "invalid_request"); - assert_eq!( - response["link"], - "https://docs.meilisearch.com/errors#primary_key_inference_failed" - ); + + let expected_error = json!({ + "message": r#"The primary key inference process failed because the engine did not find any fields containing `id` substring in their name. If your document identifier does not contain any `id` substring, you can set the primary key of the index."#, + "code": "primary_key_inference_failed", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#primary_key_inference_failed" + }); + + assert_eq!(response["error"], expected_error); } diff --git a/meilisearch-http/tests/settings/get_settings.rs b/meilisearch-http/tests/settings/get_settings.rs index c8d4a13c2..05959c069 100644 --- a/meilisearch-http/tests/settings/get_settings.rs +++ b/meilisearch-http/tests/settings/get_settings.rs @@ -279,16 +279,15 @@ async fn error_set_invalid_ranking_rules() { assert_eq!(code, 200); assert_eq!(response["status"], "failed"); - assert_eq!( - response["message"], - r#"`manyTheFish` ranking rule is invalid. Valid ranking rules are Words, Typo, Sort, Proximity, Attribute, Exactness and custom ranking rules."# - ); - assert_eq!(response["code"], "invalid_ranking_rule"); - assert_eq!(response["type"], "invalid_request"); - assert_eq!( - response["link"], - "https://docs.meilisearch.com/errors#invalid_ranking_rule" - ); + + let expected_error = json!({ + "message": r#"`manyTheFish` ranking rule is invalid. Valid ranking rules are Words, Typo, Sort, Proximity, Attribute, Exactness and custom ranking rules."#, + "code": "invalid_ranking_rule", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid_ranking_rule" + }); + + assert_eq!(response["error"], expected_error); } #[actix_rt::test] From 6bbc1b431603e594be8ce8026ac496f5982e97be Mon Sep 17 00:00:00 2001 From: many Date: Thu, 4 Nov 2021 17:04:06 +0100 Subject: [PATCH 2/2] Remove error flattening in task serialization --- meilisearch-http/src/routes/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index 2c27b7b45..87504dcb9 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -97,8 +97,7 @@ pub struct FailedUpdateResult { pub update_id: u64, #[serde(rename = "type")] pub update_type: UpdateType, - #[serde(flatten)] - pub response: ResponseError, + pub error: ResponseError, pub duration: f64, // in seconds pub enqueued_at: DateTime, pub processed_at: DateTime, @@ -190,12 +189,12 @@ impl From for UpdateStatusResponse { let update_id = failed.id(); let processed_at = failed.failed_at; let enqueued_at = failed.from.from.enqueued_at; - let response = failed.into(); + let error = failed.into(); let content = FailedUpdateResult { update_id, update_type, - response, + error, duration, enqueued_at, processed_at,