2020-03-11 14:12:38 +01:00
|
|
|
use serde_json::json;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
// Test issue https://github.com/meilisearch/MeiliSearch/issues/519
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn check_add_documents_with_primary_key_param() {
|
2020-03-11 14:12:38 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
|
|
|
|
// 1 - Create the index with no primary_key
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.create_index(body).await;
|
2020-03-11 14:12:38 +01:00
|
|
|
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";
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.post_request(&url, body).await;
|
2020-03-11 14:12:38 +01:00
|
|
|
eprintln!("{:#?}", response);
|
|
|
|
assert_eq!(status_code, 202);
|
|
|
|
let update_id = response["updateId"].as_u64().unwrap();
|
2020-04-16 11:09:47 +02:00
|
|
|
server.wait_update_id(update_id).await;
|
2020-03-11 14:12:38 +01:00
|
|
|
|
2020-03-31 18:56:35 +02:00
|
|
|
// 3 - Check update success
|
2020-03-11 14:12:38 +01:00
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_update_status(update_id).await;
|
2020-03-11 14:12:38 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_eq!(response["status"], "processed");
|
|
|
|
}
|
2020-03-31 10:39:58 +02:00
|
|
|
|
|
|
|
// Test issue https://github.com/meilisearch/MeiliSearch/issues/568
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn check_add_documents_with_nested_boolean() {
|
2020-03-31 10:39:58 +02:00
|
|
|
let mut server = common::Server::with_uid("tasks");
|
|
|
|
|
|
|
|
// 1 - Create the index with no primary_key
|
|
|
|
|
|
|
|
let body = json!({ "uid": "tasks" });
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.create_index(body).await;
|
2020-03-31 10:39:58 +02:00
|
|
|
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";
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.post_request(&url, body).await;
|
2020-03-31 10:39:58 +02:00
|
|
|
eprintln!("{:#?}", response);
|
|
|
|
assert_eq!(status_code, 202);
|
|
|
|
let update_id = response["updateId"].as_u64().unwrap();
|
2020-04-16 11:09:47 +02:00
|
|
|
server.wait_update_id(update_id).await;
|
2020-03-31 10:39:58 +02:00
|
|
|
|
2020-03-31 18:56:35 +02:00
|
|
|
// 3 - Check update success
|
2020-03-31 10:39:58 +02:00
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_update_status(update_id).await;
|
2020-03-31 10:39:58 +02:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_eq!(response["status"], "processed");
|
|
|
|
}
|
2020-03-31 13:00:13 +02:00
|
|
|
|
|
|
|
// Test issue https://github.com/meilisearch/MeiliSearch/issues/571
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn check_add_documents_with_nested_null() {
|
2020-03-31 13:00:13 +02:00
|
|
|
let mut server = common::Server::with_uid("tasks");
|
|
|
|
|
|
|
|
// 1 - Create the index with no primary_key
|
|
|
|
|
|
|
|
let body = json!({ "uid": "tasks" });
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.create_index(body).await;
|
2020-03-31 13:00:13 +02:00
|
|
|
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-10 19:05:05 +02:00
|
|
|
let body = json!([{
|
|
|
|
"id": 0,
|
|
|
|
"foo": {
|
2020-03-31 14:13:09 +02:00
|
|
|
"bar": null
|
2020-04-10 19:05:05 +02:00
|
|
|
}
|
2020-03-31 14:13:09 +02:00
|
|
|
}]);
|
2020-03-31 13:00:13 +02:00
|
|
|
|
|
|
|
let url = "/indexes/tasks/documents";
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.post_request(&url, body).await;
|
2020-03-31 13:00:13 +02:00
|
|
|
eprintln!("{:#?}", response);
|
|
|
|
assert_eq!(status_code, 202);
|
|
|
|
let update_id = response["updateId"].as_u64().unwrap();
|
2020-04-16 11:09:47 +02:00
|
|
|
server.wait_update_id(update_id).await;
|
2020-03-31 13:00:13 +02:00
|
|
|
|
2020-03-31 18:56:35 +02:00
|
|
|
// 3 - Check update success
|
2020-03-31 13:00:13 +02:00
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_update_status(update_id).await;
|
2020-03-31 13:00:13 +02:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_eq!(response["status"], "processed");
|
2020-03-31 14:13:09 +02:00
|
|
|
}
|
2020-03-31 18:56:35 +02:00
|
|
|
|
|
|
|
// Test issue https://github.com/meilisearch/MeiliSearch/issues/574
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn check_add_documents_with_nested_sequence() {
|
2020-03-31 18:56:35 +02:00
|
|
|
let mut server = common::Server::with_uid("tasks");
|
|
|
|
|
|
|
|
// 1 - Create the index with no primary_key
|
|
|
|
|
|
|
|
let body = json!({ "uid": "tasks" });
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.create_index(body).await;
|
2020-03-31 18:56:35 +02:00
|
|
|
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-10 19:05:05 +02:00
|
|
|
let body = json!([{
|
|
|
|
"id": 0,
|
|
|
|
"foo": {
|
2020-03-31 22:16:01 +02:00
|
|
|
"bar": [123,456],
|
2020-03-31 18:56:35 +02:00
|
|
|
"fez": [{
|
|
|
|
"id": 255,
|
|
|
|
"baz": "leesz",
|
|
|
|
"fuzz": {
|
|
|
|
"fax": [234]
|
2020-03-31 19:01:01 +02:00
|
|
|
},
|
|
|
|
"sas": []
|
2020-03-31 22:16:01 +02:00
|
|
|
}],
|
|
|
|
"foz": [{
|
|
|
|
"id": 255,
|
|
|
|
"baz": "leesz",
|
|
|
|
"fuzz": {
|
|
|
|
"fax": [234]
|
|
|
|
},
|
|
|
|
"sas": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 256,
|
|
|
|
"baz": "loss",
|
|
|
|
"fuzz": {
|
|
|
|
"fax": [235]
|
|
|
|
},
|
|
|
|
"sas": [321, 321]
|
2020-03-31 18:56:35 +02:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
|
|
|
|
let url = "/indexes/tasks/documents";
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.post_request(&url, body.clone()).await;
|
2020-03-31 18:56:35 +02:00
|
|
|
eprintln!("{:#?}", response);
|
|
|
|
assert_eq!(status_code, 202);
|
|
|
|
let update_id = response["updateId"].as_u64().unwrap();
|
2020-04-16 11:09:47 +02:00
|
|
|
server.wait_update_id(update_id).await;
|
2020-03-31 18:56:35 +02:00
|
|
|
|
|
|
|
// 3 - Check update success
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_update_status(update_id).await;
|
2020-03-31 18:56:35 +02:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_eq!(response["status"], "processed");
|
|
|
|
|
|
|
|
let url = "/indexes/tasks/search?q=leesz";
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_request(&url).await;
|
2020-03-31 18:56:35 +02:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_eq!(response["hits"], body);
|
|
|
|
}
|