Update tests

This commit is contained in:
many 2021-11-04 17:03:13 +01:00
parent d9d6dee550
commit 3c696da274
No known key found for this signature in database
GPG Key ID: 2CEF23B75189EACA
2 changed files with 72 additions and 74 deletions

View File

@ -812,13 +812,15 @@ async fn error_add_documents_bad_document_id() {
let (response, code) = index.get_update(0).await; let (response, code) = index.get_update(0).await;
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], json!("failed")); 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")); let expected_error = json!({
assert_eq!(response["type"], json!("invalid_request")); "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 (_).",
assert_eq!( "code": "invalid_document_id",
response["link"], "type": "invalid_request",
json!("https://docs.meilisearch.com/errors#invalid_document_id") "link": "https://docs.meilisearch.com/errors#invalid_document_id"
); });
assert_eq!(response["error"], expected_error);
} }
#[actix_rt::test] #[actix_rt::test]
@ -837,13 +839,15 @@ async fn error_update_documents_bad_document_id() {
let (response, code) = index.get_update(0).await; let (response, code) = index.get_update(0).await;
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], json!("failed")); 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")); let expected_error = json!({
assert_eq!(response["type"], json!("invalid_request")); "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 (_).",
assert_eq!( "code": "invalid_document_id",
response["link"], "type": "invalid_request",
json!("https://docs.meilisearch.com/errors#invalid_document_id") "link": "https://docs.meilisearch.com/errors#invalid_document_id"
); });
assert_eq!(response["error"], expected_error);
} }
#[actix_rt::test] #[actix_rt::test]
@ -862,16 +866,15 @@ async fn error_add_documents_missing_document_id() {
let (response, code) = index.get_update(0).await; let (response, code) = index.get_update(0).await;
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "failed"); assert_eq!(response["status"], "failed");
assert_eq!(
response["message"], let expected_error = json!({
json!(r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#) "message": r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#,
); "code": "missing_document_id",
assert_eq!(response["code"], json!("missing_document_id")); "type": "invalid_request",
assert_eq!(response["type"], json!("invalid_request")); "link": "https://docs.meilisearch.com/errors#missing_document_id"
assert_eq!( });
response["link"],
json!("https://docs.meilisearch.com/errors#missing_document_id") assert_eq!(response["error"], expected_error);
);
} }
#[actix_rt::test] #[actix_rt::test]
@ -890,16 +893,15 @@ async fn error_update_documents_missing_document_id() {
let (response, code) = index.get_update(0).await; let (response, code) = index.get_update(0).await;
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "failed"); assert_eq!(response["status"], "failed");
assert_eq!(
response["message"], let expected_error = json!({
r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."# "message": r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#,
); "code": "missing_document_id",
assert_eq!(response["code"], "missing_document_id"); "type": "invalid_request",
assert_eq!(response["type"], "invalid_request"); "link": "https://docs.meilisearch.com/errors#missing_document_id"
assert_eq!( });
response["link"],
"https://docs.meilisearch.com/errors#missing_document_id" assert_eq!(response["error"], expected_error);
);
} }
#[actix_rt::test] #[actix_rt::test]
@ -927,16 +929,15 @@ async fn error_document_field_limit_reached() {
assert_eq!(code, 200); assert_eq!(code, 200);
// Documents without a primary key are not accepted. // Documents without a primary key are not accepted.
assert_eq!(response["status"], "failed"); assert_eq!(response["status"], "failed");
assert_eq!(
response["message"], let expected_error = json!({
"A document cannot contain more than 65,535 fields." "message": "A document cannot contain more than 65,535 fields.",
); "code": "document_fields_limit_reached",
assert_eq!(response["code"], "document_fields_limit_reached"); "type": "invalid_request",
assert_eq!(response["type"], "invalid_request"); "link": "https://docs.meilisearch.com/errors#document_fields_limit_reached"
assert_eq!( });
response["link"],
"https://docs.meilisearch.com/errors#document_fields_limit_reached" assert_eq!(response["error"], expected_error);
);
} }
#[actix_rt::test] #[actix_rt::test]
@ -960,16 +961,15 @@ async fn error_add_documents_invalid_geo_field() {
let (response, code) = index.get_update(1).await; let (response, code) = index.get_update(1).await;
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "failed"); assert_eq!(response["status"], "failed");
assert_eq!(
response["message"], let expected_error = json!({
r#"The document with the id: `11` contains an invalid _geo field: `foobar`."# "message": r#"The document with the id: `11` contains an invalid _geo field: `foobar`."#,
); "code": "invalid_geo_field",
assert_eq!(response["code"], "invalid_geo_field"); "type": "invalid_request",
assert_eq!(response["type"], "invalid_request"); "link": "https://docs.meilisearch.com/errors#invalid_geo_field"
assert_eq!( });
response["link"],
"https://docs.meilisearch.com/errors#invalid_geo_field" assert_eq!(response["error"], expected_error);
);
} }
#[actix_rt::test] #[actix_rt::test]
@ -1015,14 +1015,13 @@ async fn error_primary_key_inference() {
let (response, code) = index.get_update(0).await; let (response, code) = index.get_update(0).await;
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "failed"); assert_eq!(response["status"], "failed");
assert_eq!(
response["message"], let expected_error = json!({
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."# "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",
assert_eq!(response["code"], "primary_key_inference_failed"); "type": "invalid_request",
assert_eq!(response["type"], "invalid_request"); "link": "https://docs.meilisearch.com/errors#primary_key_inference_failed"
assert_eq!( });
response["link"],
"https://docs.meilisearch.com/errors#primary_key_inference_failed" assert_eq!(response["error"], expected_error);
);
} }

View File

@ -279,16 +279,15 @@ async fn error_set_invalid_ranking_rules() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "failed"); assert_eq!(response["status"], "failed");
assert_eq!(
response["message"], let expected_error = json!({
r#"`manyTheFish` ranking rule is invalid. Valid ranking rules are Words, Typo, Sort, Proximity, Attribute, Exactness and custom ranking rules."# "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",
assert_eq!(response["code"], "invalid_ranking_rule"); "type": "invalid_request",
assert_eq!(response["type"], "invalid_request"); "link": "https://docs.meilisearch.com/errors#invalid_ranking_rule"
assert_eq!( });
response["link"],
"https://docs.meilisearch.com/errors#invalid_ranking_rule" assert_eq!(response["error"], expected_error);
);
} }
#[actix_rt::test] #[actix_rt::test]