add tests for documents

This commit is contained in:
mpostma 2020-07-08 14:31:33 +02:00
parent a794970b72
commit 63260e6443
2 changed files with 41 additions and 9 deletions

View 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());
}

View File

@ -1,6 +1,6 @@
use assert_json_diff::assert_json_eq;
use actix_web::http::StatusCode;
use serde_json::json;
use assert_json_diff::assert_json_eq;
use serde_json::{json, Value};
mod common;
@ -72,7 +72,10 @@ async fn create_index_with_uid() {
let (response, status_code) = server.create_index(body).await;
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
@ -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!(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();
@ -702,7 +705,9 @@ async fn get_empty_index() {
async fn create_and_list_multiple_indices() {
let mut server = common::Server::with_uid("test");
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;
assert_eq!(response.as_array().unwrap().len(), 10);
@ -746,7 +751,9 @@ async fn correct_response_no_primary_key_index() {
#[actix_rt::test]
async fn correct_response_with_primary_key_index() {
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");
}
@ -760,11 +767,13 @@ async fn udpate_unexisting_index_is_error() {
}
#[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");
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;
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");
}