mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
add tests for documents
This commit is contained in:
parent
a794970b72
commit
63260e6443
23
meilisearch-http/tests/documents_get.rs
Normal file
23
meilisearch-http/tests/documents_get.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use serde_json::json;
|
||||||
|
use actix_web::http::StatusCode;
|
||||||
|
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn get_documents_from_unexisting_index_is_error() {
|
||||||
|
let mut server = common::Server::with_uid("test");
|
||||||
|
let (response, status) = server.get_all_documents().await;
|
||||||
|
assert_eq!(status, StatusCode::NOT_FOUND);
|
||||||
|
assert_eq!(response["errorCode"], "index_not_found");
|
||||||
|
assert_eq!(response["errorType"], "invalid_request_error");
|
||||||
|
assert_eq!(response["errorLink"], "https://docs.meilisearch.com/errors#index_not_found");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn get_empty_documents_list() {
|
||||||
|
let mut server = common::Server::with_uid("test");
|
||||||
|
server.create_index(json!({ "uid": "test" })).await;
|
||||||
|
let (response, status) = server.get_all_documents().await;
|
||||||
|
assert_eq!(status, StatusCode::OK);
|
||||||
|
assert!(response.as_array().unwrap().is_empty());
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
use assert_json_diff::assert_json_eq;
|
|
||||||
use actix_web::http::StatusCode;
|
use actix_web::http::StatusCode;
|
||||||
use serde_json::json;
|
use assert_json_diff::assert_json_eq;
|
||||||
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
@ -72,7 +72,10 @@ async fn create_index_with_uid() {
|
|||||||
let (response, status_code) = server.create_index(body).await;
|
let (response, status_code) = server.create_index(body).await;
|
||||||
|
|
||||||
assert_eq!(status_code, 400);
|
assert_eq!(status_code, 400);
|
||||||
assert_eq!(response["errorCode"].as_str().unwrap(), "index_already_exists");
|
assert_eq!(
|
||||||
|
response["errorCode"].as_str().unwrap(),
|
||||||
|
"index_already_exists"
|
||||||
|
);
|
||||||
|
|
||||||
// 2 - Check the list of indexes
|
// 2 - Check the list of indexes
|
||||||
|
|
||||||
@ -676,7 +679,7 @@ async fn check_first_update_should_bring_up_processed_status_after_first_docs_ad
|
|||||||
assert_eq!(status_code, 201);
|
assert_eq!(status_code, 201);
|
||||||
assert_eq!(response["primaryKey"], json!(null));
|
assert_eq!(response["primaryKey"], json!(null));
|
||||||
|
|
||||||
let dataset = include_bytes!("assets/movies.json");
|
let dataset = include_bytes!("./assets/test_set.json");
|
||||||
|
|
||||||
let body: Value = serde_json::from_slice(dataset).unwrap();
|
let body: Value = serde_json::from_slice(dataset).unwrap();
|
||||||
|
|
||||||
@ -702,7 +705,9 @@ async fn get_empty_index() {
|
|||||||
async fn create_and_list_multiple_indices() {
|
async fn create_and_list_multiple_indices() {
|
||||||
let mut server = common::Server::with_uid("test");
|
let mut server = common::Server::with_uid("test");
|
||||||
for i in 0..10 {
|
for i in 0..10 {
|
||||||
server.create_index(json!({ "uid": format!("test{}", i) })).await;
|
server
|
||||||
|
.create_index(json!({ "uid": format!("test{}", i) }))
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
let (response, _status) = server.list_indexes().await;
|
let (response, _status) = server.list_indexes().await;
|
||||||
assert_eq!(response.as_array().unwrap().len(), 10);
|
assert_eq!(response.as_array().unwrap().len(), 10);
|
||||||
@ -746,7 +751,9 @@ async fn correct_response_no_primary_key_index() {
|
|||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn correct_response_with_primary_key_index() {
|
async fn correct_response_with_primary_key_index() {
|
||||||
let mut server = common::Server::with_uid("test");
|
let mut server = common::Server::with_uid("test");
|
||||||
let (response, _status) = server.create_index(json!({ "uid": "test", "primaryKey": "test" })).await;
|
let (response, _status) = server
|
||||||
|
.create_index(json!({ "uid": "test", "primaryKey": "test" }))
|
||||||
|
.await;
|
||||||
assert_eq!(response["primaryKey"], "test");
|
assert_eq!(response["primaryKey"], "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,11 +767,13 @@ async fn udpate_unexisting_index_is_error() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn upate_existing_primary_key_is_error() {
|
async fn update_existing_primary_key_is_error() {
|
||||||
let mut server = common::Server::with_uid("test");
|
let mut server = common::Server::with_uid("test");
|
||||||
server.create_index(json!({ "uid": "test", "primaryKey": "key" })).await;
|
server
|
||||||
|
.create_index(json!({ "uid": "test", "primaryKey": "key" }))
|
||||||
|
.await;
|
||||||
let (response, status) = server.update_index(json!({ "primaryKey": "test2" })).await;
|
let (response, status) = server.update_index(json!({ "primaryKey": "test2" })).await;
|
||||||
assert_eq!(status, StatusCode::BAD_REQUEST);
|
assert_eq!(status, StatusCode::BAD_REQUEST);
|
||||||
assert_eq!(response["errorCode"], "bad_request");
|
assert_eq!(response["errorCode"], "primary_key_already_present");
|
||||||
assert_eq!(response["errorType"], "invalid_request_error");
|
assert_eq!(response["errorType"], "invalid_request_error");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user