From 3c696da2747551a2b2223f2c47c74de2051543b5 Mon Sep 17 00:00:00 2001 From: many Date: Thu, 4 Nov 2021 17:03:13 +0100 Subject: [PATCH] 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]