meilisearch/meilisearch-http/tests/documents_add.rs

178 lines
5.1 KiB
Rust
Raw Normal View History

use serde_json::json;
mod common;
// Test issue https://github.com/meilisearch/MeiliSearch/issues/519
#[test]
fn check_add_documents_with_primary_key_param() {
let mut server = common::Server::with_uid("movies");
// 1 - Create the index with no primary_key
let body = json!({
"uid": "movies",
});
let (response, status_code) = server.create_index(body);
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
// 2 - Add documents
let body = json!([{
"title": "Test",
"comment": "comment test"
}]);
let url = "/indexes/movies/documents?primaryKey=title";
let (response, status_code) = server.post_request(&url, body);
eprintln!("{:#?}", response);
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
server.wait_update_id(update_id);
2020-04-01 00:56:35 +08:00
// 3 - Check update success
let (response, status_code) = server.get_update_status(update_id);
assert_eq!(status_code, 200);
assert_eq!(response["status"], "processed");
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/568
#[test]
fn check_add_documents_with_nested_boolean() {
let mut server = common::Server::with_uid("tasks");
// 1 - Create the index with no primary_key
let body = json!({ "uid": "tasks" });
let (response, status_code) = server.create_index(body);
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
// 2 - Add a document that contains a boolean in a nested object
let body = json!([{
"id": 12161,
"created_at": "2019-04-10T14:57:57.522Z",
"foo": {
"bar": {
"id": 121,
"crash": false
},
"id": 45912
}
}]);
let url = "/indexes/tasks/documents";
let (response, status_code) = server.post_request(&url, body);
eprintln!("{:#?}", response);
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
server.wait_update_id(update_id);
2020-04-01 00:56:35 +08:00
// 3 - Check update success
let (response, status_code) = server.get_update_status(update_id);
assert_eq!(status_code, 200);
assert_eq!(response["status"], "processed");
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/571
#[test]
fn check_add_documents_with_nested_null() {
let mut server = common::Server::with_uid("tasks");
// 1 - Create the index with no primary_key
let body = json!({ "uid": "tasks" });
let (response, status_code) = server.create_index(body);
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
// 2 - Add a document that contains a null in a nested object
2020-04-11 01:05:05 +08:00
let body = json!([{
"id": 0,
"foo": {
"bar": null
2020-04-11 01:05:05 +08:00
}
}]);
let url = "/indexes/tasks/documents";
let (response, status_code) = server.post_request(&url, body);
eprintln!("{:#?}", response);
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
server.wait_update_id(update_id);
2020-04-01 00:56:35 +08:00
// 3 - Check update success
let (response, status_code) = server.get_update_status(update_id);
assert_eq!(status_code, 200);
assert_eq!(response["status"], "processed");
}
2020-04-01 00:56:35 +08:00
// Test issue https://github.com/meilisearch/MeiliSearch/issues/574
#[test]
fn check_add_documents_with_nested_sequence() {
let mut server = common::Server::with_uid("tasks");
// 1 - Create the index with no primary_key
let body = json!({ "uid": "tasks" });
let (response, status_code) = server.create_index(body);
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
// 2 - Add a document that contains a seq in a nested object
2020-04-11 01:05:05 +08:00
let body = json!([{
"id": 0,
"foo": {
2020-04-01 04:16:01 +08:00
"bar": [123,456],
2020-04-01 00:56:35 +08:00
"fez": [{
"id": 255,
"baz": "leesz",
"fuzz": {
"fax": [234]
2020-04-01 01:01:01 +08:00
},
"sas": []
2020-04-01 04:16:01 +08:00
}],
"foz": [{
"id": 255,
"baz": "leesz",
"fuzz": {
"fax": [234]
},
"sas": []
},
{
"id": 256,
"baz": "loss",
"fuzz": {
"fax": [235]
},
"sas": [321, 321]
2020-04-01 00:56:35 +08:00
}]
}
}]);
let url = "/indexes/tasks/documents";
let (response, status_code) = server.post_request(&url, body.clone());
eprintln!("{:#?}", response);
assert_eq!(status_code, 202);
let update_id = response["updateId"].as_u64().unwrap();
server.wait_update_id(update_id);
// 3 - Check update success
let (response, status_code) = server.get_update_status(update_id);
assert_eq!(status_code, 200);
assert_eq!(response["status"], "processed");
let url = "/indexes/tasks/search?q=leesz";
let (response, status_code) = server.get_request(&url);
assert_eq!(status_code, 200);
assert_eq!(response["hits"], body);
}