Add bad_request error tests

This commit is contained in:
many
2021-10-21 14:42:01 +02:00
parent 0a9d6e8210
commit 8ec0c4c913
10 changed files with 1088 additions and 167 deletions

View File

@ -49,28 +49,6 @@ async fn create_index_with_invalid_primary_key() {
assert_eq!(response["primaryKey"], Value::Null);
}
// TODO: partial test since we are testing error, amd error is not yet fully implemented in
// transplant
#[actix_rt::test]
async fn create_existing_index() {
let server = Server::new().await;
let index = server.index("test");
let (_, code) = index.create(Some("primary")).await;
assert_eq!(code, 201);
let (_response, code) = index.create(Some("primary")).await;
assert_eq!(code, 400);
}
#[actix_rt::test]
async fn create_with_invalid_index_uid() {
let server = Server::new().await;
let index = server.index("test test#!");
let (_, code) = index.create(None).await;
assert_eq!(code, 400);
}
#[actix_rt::test]
async fn test_create_multiple_indexes() {
let server = Server::new().await;
@ -88,3 +66,41 @@ async fn test_create_multiple_indexes() {
assert_eq!(index3.get().await.1, 200);
assert_eq!(index4.get().await.1, 404);
}
#[actix_rt::test]
async fn error_create_existing_index() {
let server = Server::new().await;
let index = server.index("test");
let (_, code) = index.create(Some("primary")).await;
assert_eq!(code, 201);
let (response, code) = index.create(Some("primary")).await;
let expected_response = json!({
"message": "Index primary already exists.",
"code": "index_already_exists",
"type": "invalid_request",
"link":"https://docs.meilisearch.com/errors#index_already_exists"
});
assert_eq!(response, expected_response);
assert_eq!(code, 409);
}
#[actix_rt::test]
async fn error_create_with_invalid_index_uid() {
let server = Server::new().await;
let index = server.index("test test#!");
let (response, code) = index.create(None).await;
let expected_response = json!({
"message": "test test#! is not a valid index uid. Index uid can be an integer or a string containing only alphanumeric characters, hyphens (-) and underscores (_).",
"code": "invalid_index_uid",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_index_uid"
});
assert_eq!(response, expected_response);
assert_eq!(code, 400);
}

View File

@ -18,11 +18,19 @@ async fn create_and_delete_index() {
}
#[actix_rt::test]
async fn delete_unexisting_index() {
async fn error_delete_unexisting_index() {
let server = Server::new().await;
let index = server.index("test");
let (_response, code) = index.delete().await;
let (response, code) = index.delete().await;
let expected_response = json!({
"message": "Index test not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
});
assert_eq!(response, expected_response);
assert_eq!(code, 404);
}

View File

@ -1,4 +1,5 @@
use crate::common::Server;
use serde_json::json;
use serde_json::Value;
#[actix_rt::test]
@ -21,15 +22,21 @@ async fn create_and_get_index() {
assert_eq!(response.as_object().unwrap().len(), 5);
}
// TODO: partial test since we are testing error, and error is not yet fully implemented in
// transplant
#[actix_rt::test]
async fn get_unexisting_index() {
async fn error_get_unexisting_index() {
let server = Server::new().await;
let index = server.index("test");
let (_response, code) = index.get().await;
let (response, code) = index.get().await;
let expected_response = json!({
"message": "Index test not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
});
assert_eq!(response, expected_response);
assert_eq!(code, 404);
}

View File

@ -46,3 +46,19 @@ async fn stats() {
assert_eq!(response["fieldDistribution"]["name"], 1);
assert_eq!(response["fieldDistribution"]["age"], 1);
}
#[actix_rt::test]
async fn error_get_stats_unexisting_index() {
let server = Server::new().await;
let (response, code) = server.index("test").stats().await;
let expected_response = json!({
"message": "Index test not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
});
assert_eq!(response, expected_response);
assert_eq!(code, 404);
}

View File

@ -1,5 +1,6 @@
use crate::common::Server;
use chrono::DateTime;
use serde_json::json;
#[actix_rt::test]
async fn update_primary_key() {
@ -39,26 +40,39 @@ async fn update_nothing() {
assert_eq!(response, update);
}
// TODO: partial test since we are testing error, amd error is not yet fully implemented in
// transplant
#[actix_rt::test]
async fn update_existing_primary_key() {
async fn error_update_existing_primary_key() {
let server = Server::new().await;
let index = server.index("test");
let (_response, code) = index.create(Some("primary")).await;
assert_eq!(code, 201);
let (_update, code) = index.update(Some("primary2")).await;
let (response, code) = index.update(Some("primary2")).await;
let expected_response = json!({
"message": "Index test already has a primary key.",
"code": "index_primary_key_already_exists",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_primary_key_already_exists"
});
assert_eq!(response, expected_response);
assert_eq!(code, 400);
}
// TODO: partial test since we are testing error, amd error is not yet fully implemented in
// transplant
#[actix_rt::test]
async fn test_unexisting_index() {
async fn error_update_unexisting_index() {
let server = Server::new().await;
let (_response, code) = server.index("test").update(None).await;
let (response, code) = server.index("test").update(None).await;
let expected_response = json!({
"message": "Index test not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
});
assert_eq!(response, expected_response);
assert_eq!(code, 404);
}