mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
Add bad_request error tests
This commit is contained in:
parent
0a9d6e8210
commit
8ec0c4c913
10 changed files with 1088 additions and 167 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue