2020-03-05 15:05:04 +01:00
|
|
|
use assert_json_diff::assert_json_eq;
|
|
|
|
use serde_json::json;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn index_new_fields_default() {
|
2020-03-05 15:05:04 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
2020-03-09 18:40:49 +01:00
|
|
|
"primaryKey": "id",
|
2020-03-05 15:05:04 +01:00
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
server.create_index(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 1 - Add a document
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 1,
|
|
|
|
"title": "I'm a legend",
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 2 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 1,
|
|
|
|
"title": "I'm a legend",
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(1).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
|
|
|
|
// 3 - Add a document with more fields
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 2,
|
|
|
|
"title": "I'm not a legend",
|
|
|
|
"description": "A bad copy of the original movie I'm a lengend"
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 4 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 2,
|
|
|
|
"title": "I'm not a legend",
|
|
|
|
"description": "A bad copy of the original movie I'm a lengend"
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(2).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn index_new_fields_true() {
|
2020-03-05 15:05:04 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
2020-03-09 18:40:49 +01:00
|
|
|
"primaryKey": "id",
|
2020-03-05 15:05:04 +01:00
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
server.create_index(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 1 - Set indexNewFields = true
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_accept_new_fields(json!(true)).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 2 - Add a document
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 1,
|
|
|
|
"title": "I'm a legend",
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 3 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 1,
|
|
|
|
"title": "I'm a legend",
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(1).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
|
|
|
|
// 4 - Add a document with more fields
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 2,
|
|
|
|
"title": "I'm not a legend",
|
|
|
|
"description": "A bad copy of the original movie I'm a lengend"
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 5 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 2,
|
|
|
|
"title": "I'm not a legend",
|
|
|
|
"description": "A bad copy of the original movie I'm a lengend"
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(2).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn index_new_fields_false() {
|
2020-03-05 15:05:04 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
2020-03-09 18:40:49 +01:00
|
|
|
"primaryKey": "id",
|
2020-03-05 15:05:04 +01:00
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
server.create_index(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 1 - Set indexNewFields = false
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_accept_new_fields(json!(false)).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 2 - Add a document
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 1,
|
|
|
|
"title": "I'm a legend",
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 3 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 1,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(1).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
|
|
|
|
// 4 - Add a document with more fields
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 2,
|
|
|
|
"title": "I'm not a legend",
|
|
|
|
"description": "A bad copy of the original movie I'm a lengend"
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 5 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 2,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(2).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn index_new_fields_true_then_false() {
|
2020-03-05 15:05:04 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
2020-03-09 18:40:49 +01:00
|
|
|
"primaryKey": "id",
|
2020-03-05 15:05:04 +01:00
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
server.create_index(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 1 - Set indexNewFields = true
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_accept_new_fields(json!(true)).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 2 - Add a document
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 1,
|
|
|
|
"title": "I'm a legend",
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 3 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 1,
|
|
|
|
"title": "I'm a legend",
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(1).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
|
|
|
|
// 4 - Set indexNewFields = false
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_accept_new_fields(json!(false)).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 5 - Add a document with more fields
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 2,
|
|
|
|
"title": "I'm not a legend",
|
|
|
|
"description": "A bad copy of the original movie I'm a lengend"
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 6 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 2,
|
|
|
|
"title": "I'm not a legend",
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(2).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn index_new_fields_false_then_true() {
|
2020-03-05 15:05:04 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
2020-03-09 18:40:49 +01:00
|
|
|
"primaryKey": "id",
|
2020-03-05 15:05:04 +01:00
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
server.create_index(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 1 - Set indexNewFields = false
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_accept_new_fields(json!(false)).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 2 - Add a document
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 1,
|
|
|
|
"title": "I'm a legend",
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 3 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 1,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(1).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
|
|
|
|
// 4 - Set indexNewFields = false
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_accept_new_fields(json!(true)).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 5 - Add a document with more fields
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 2,
|
|
|
|
"title": "I'm not a legend",
|
|
|
|
"description": "A bad copy of the original movie I'm a lengend"
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
|
|
|
|
// 6 - Get the complete document
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 1,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(1).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"id": 2,
|
|
|
|
"description": "A bad copy of the original movie I'm a lengend"
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, status_code) = server.get_document(2).await;
|
2020-03-05 15:05:04 +01:00
|
|
|
assert_eq!(status_code, 200);
|
|
|
|
assert_json_eq!(response, expected);
|
|
|
|
}
|
2020-03-11 12:00:40 +01:00
|
|
|
|
|
|
|
// Fix issue https://github.com/meilisearch/MeiliSearch/issues/518
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn accept_new_fields_does_not_take_into_account_the_primary_key() {
|
2020-03-11 12:00:40 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
|
|
|
|
// 1 - Create an 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 12:00:40 +01:00
|
|
|
assert_eq!(status_code, 201);
|
|
|
|
assert_eq!(response["primaryKey"], json!(null));
|
|
|
|
|
|
|
|
// 2 - Add searchable and displayed attributes as: ["title"] & Set acceptNewFields to false
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"searchableAttributes": ["title"],
|
|
|
|
"displayedAttributes": ["title"],
|
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(body).await;
|
2020-03-11 12:00:40 +01:00
|
|
|
|
|
|
|
// 4 - Add a document
|
|
|
|
|
|
|
|
let body = json!([{
|
|
|
|
"id": 1,
|
|
|
|
"title": "Test",
|
|
|
|
"comment": "comment test"
|
|
|
|
}]);
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.add_or_replace_multiple_documents(body).await;
|
2020-03-11 12:00:40 +01:00
|
|
|
|
|
|
|
// 5 - Get settings, they should not changed
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
2020-03-11 12:00:40 +01:00
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
|
|
|
"exactness",
|
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
|
|
|
"searchableAttributes": ["title"],
|
|
|
|
"displayedAttributes": ["title"],
|
|
|
|
"stopWords": [],
|
|
|
|
"synonyms": {},
|
2020-06-03 11:09:25 +02:00
|
|
|
"attributesForFaceting": [],
|
2020-03-11 12:00:40 +01:00
|
|
|
"acceptNewFields": false,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_json_eq!(response, expected, ordered: false);
|
|
|
|
}
|