mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 18:17:39 +08:00
fix tests
This commit is contained in:
parent
51b7cb2722
commit
c06dd35af1
@ -112,7 +112,6 @@ impl Server {
|
||||
"longitude",
|
||||
"tags",
|
||||
],
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(body).await;
|
||||
@ -426,16 +425,6 @@ impl Server {
|
||||
self.delete_request_async(&url).await
|
||||
}
|
||||
|
||||
pub async fn get_accept_new_fields(&mut self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings/accept-new-fields", self.uid);
|
||||
self.get_request(&url).await
|
||||
}
|
||||
|
||||
pub async fn update_accept_new_fields(&mut self, body: Value) {
|
||||
let url = format!("/indexes/{}/settings/accept-new-fields", self.uid);
|
||||
self.post_request_async(&url, body).await;
|
||||
}
|
||||
|
||||
pub async fn get_synonyms(&mut self) -> (Value, StatusCode) {
|
||||
let url = format!("/indexes/{}/settings/synonyms", self.uid);
|
||||
self.get_request(&url).await
|
||||
|
@ -41,7 +41,6 @@ async fn search_with_settings_basic() {
|
||||
],
|
||||
"stopWords": null,
|
||||
"synonyms": null,
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(config).await;
|
||||
@ -122,7 +121,6 @@ async fn search_with_settings_stop_words() {
|
||||
],
|
||||
"stopWords": ["ea"],
|
||||
"synonyms": null,
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(config).await;
|
||||
@ -206,7 +204,6 @@ async fn search_with_settings_synonyms() {
|
||||
"exercitation"
|
||||
]
|
||||
},
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(config).await;
|
||||
@ -286,7 +283,6 @@ async fn search_with_settings_ranking_rules() {
|
||||
],
|
||||
"stopWords": null,
|
||||
"synonyms": null,
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(config).await;
|
||||
@ -369,7 +365,6 @@ async fn search_with_settings_searchable_attributes() {
|
||||
"exercitation"
|
||||
]
|
||||
},
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(config).await;
|
||||
@ -435,7 +430,6 @@ async fn search_with_settings_displayed_attributes() {
|
||||
],
|
||||
"stopWords": null,
|
||||
"synonyms": null,
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(config).await;
|
||||
@ -502,7 +496,6 @@ async fn search_with_settings_searchable_attributes_2() {
|
||||
],
|
||||
"stopWords": null,
|
||||
"synonyms": null,
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(config).await;
|
||||
|
@ -48,7 +48,6 @@ async fn write_all_and_delete() {
|
||||
"street": ["avenue"],
|
||||
},
|
||||
"attributesForFaceting": ["name"],
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(body.clone()).await;
|
||||
@ -77,46 +76,11 @@ async fn write_all_and_delete() {
|
||||
"exactness"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"searchableAttributes": [
|
||||
"address",
|
||||
"id",
|
||||
"longitude",
|
||||
"phone",
|
||||
"age",
|
||||
"gender",
|
||||
"latitude",
|
||||
"email",
|
||||
"about",
|
||||
"registered",
|
||||
"picture",
|
||||
"isActive",
|
||||
"tags",
|
||||
"name",
|
||||
"color",
|
||||
"balance"
|
||||
],
|
||||
"displayedAttributes": [
|
||||
"address",
|
||||
"id",
|
||||
"longitude",
|
||||
"phone",
|
||||
"age",
|
||||
"gender",
|
||||
"latitude",
|
||||
"email",
|
||||
"about",
|
||||
"registered",
|
||||
"picture",
|
||||
"isActive",
|
||||
"tags",
|
||||
"name",
|
||||
"color",
|
||||
"balance"
|
||||
],
|
||||
"searchableAttributes": ["*"],
|
||||
"displayedAttributes": ["*"],
|
||||
"stopWords": [],
|
||||
"synonyms": {},
|
||||
"attributesForFaceting": [],
|
||||
"acceptNewFields": true,
|
||||
});
|
||||
|
||||
assert_json_eq!(expect, response, ordered: false);
|
||||
@ -168,7 +132,6 @@ async fn write_all_and_update() {
|
||||
"street": ["avenue"],
|
||||
},
|
||||
"attributesForFaceting": ["name"],
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(body.clone()).await;
|
||||
@ -210,7 +173,6 @@ async fn write_all_and_update() {
|
||||
"street": ["avenue"],
|
||||
},
|
||||
"attributesForFaceting": ["title"],
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(body).await;
|
||||
@ -248,7 +210,6 @@ async fn write_all_and_update() {
|
||||
"street": ["avenue"],
|
||||
},
|
||||
"attributesForFaceting": ["title"],
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
assert_json_eq!(expected, response, ordered: false);
|
||||
@ -274,12 +235,11 @@ async fn test_default_settings() {
|
||||
"exactness"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"searchableAttributes": [],
|
||||
"displayedAttributes": [],
|
||||
"searchableAttributes": ["*"],
|
||||
"displayedAttributes": ["*"],
|
||||
"stopWords": [],
|
||||
"synonyms": {},
|
||||
"attributesForFaceting": [],
|
||||
"acceptNewFields": true,
|
||||
});
|
||||
|
||||
let (response, _status_code) = server.get_all_settings().await;
|
||||
@ -308,16 +268,11 @@ async fn test_default_settings_2() {
|
||||
"exactness"
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"searchableAttributes": [
|
||||
"id"
|
||||
],
|
||||
"displayedAttributes": [
|
||||
"id"
|
||||
],
|
||||
"searchableAttributes": ["*"],
|
||||
"displayedAttributes": ["*"],
|
||||
"stopWords": [],
|
||||
"synonyms": {},
|
||||
"attributesForFaceting": [],
|
||||
"acceptNewFields": true,
|
||||
});
|
||||
|
||||
let (response, _status_code) = server.get_all_settings().await;
|
||||
@ -381,7 +336,6 @@ async fn write_setting_and_update_partial() {
|
||||
"road": ["street", "avenue"],
|
||||
"street": ["avenue"],
|
||||
},
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
server.update_all_settings(body.clone()).await;
|
||||
@ -427,7 +381,6 @@ async fn write_setting_and_update_partial() {
|
||||
"street": ["avenue"],
|
||||
},
|
||||
"attributesForFaceting": [],
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
let (response, _status_code) = server.get_all_settings().await;
|
||||
@ -467,19 +420,3 @@ async fn setting_ranking_rules_dont_mess_with_other_settings() {
|
||||
assert!(!response["searchableAttributes"].as_array().unwrap().iter().any(|e| e.as_str().unwrap() == "foobar"));
|
||||
assert!(!response["displayedAttributes"].as_array().unwrap().iter().any(|e| e.as_str().unwrap() == "foobar"));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn distinct_attribute_recorded_as_known_field() {
|
||||
let mut server = common::Server::test_server().await;
|
||||
let body = json!({
|
||||
"distinctAttribute": "foobar",
|
||||
"acceptNewFields": true
|
||||
});
|
||||
server.update_all_settings(body).await;
|
||||
let document = json!([{"id": 9348127, "foobar": "hello", "foo": "bar"}]);
|
||||
server.add_or_update_multiple_documents(document).await;
|
||||
// foobar should not be added to the searchable attributes because it is already known, but "foo" should
|
||||
let (response, _) = server.get_all_settings().await;
|
||||
assert!(response["searchableAttributes"].as_array().unwrap().iter().any(|v| v.as_str().unwrap() == "foo"));
|
||||
assert!(!response["searchableAttributes"].as_array().unwrap().iter().any(|v| v.as_str().unwrap() == "foobar"));
|
||||
}
|
||||
|
@ -1,349 +0,0 @@
|
||||
use assert_json_diff::assert_json_eq;
|
||||
use serde_json::json;
|
||||
|
||||
mod common;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn index_new_fields_default() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body).await;
|
||||
|
||||
// 1 - Add a document
|
||||
|
||||
let body = json!([{
|
||||
"id": 1,
|
||||
"title": "I'm a legend",
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 2 - Get the complete document
|
||||
|
||||
let expected = json!({
|
||||
"id": 1,
|
||||
"title": "I'm a legend",
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(1).await;
|
||||
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"
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 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"
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(2).await;
|
||||
assert_eq!(status_code, 200);
|
||||
assert_json_eq!(response, expected);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn index_new_fields_true() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body).await;
|
||||
|
||||
// 1 - Set indexNewFields = true
|
||||
|
||||
server.update_accept_new_fields(json!(true)).await;
|
||||
|
||||
// 2 - Add a document
|
||||
|
||||
let body = json!([{
|
||||
"id": 1,
|
||||
"title": "I'm a legend",
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 3 - Get the complete document
|
||||
|
||||
let expected = json!({
|
||||
"id": 1,
|
||||
"title": "I'm a legend",
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(1).await;
|
||||
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"
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 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"
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(2).await;
|
||||
assert_eq!(status_code, 200);
|
||||
assert_json_eq!(response, expected);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn index_new_fields_false() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body).await;
|
||||
|
||||
// 1 - Set indexNewFields = false
|
||||
|
||||
server.update_accept_new_fields(json!(false)).await;
|
||||
|
||||
// 2 - Add a document
|
||||
|
||||
let body = json!([{
|
||||
"id": 1,
|
||||
"title": "I'm a legend",
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 3 - Get the complete document
|
||||
|
||||
let expected = json!({
|
||||
"id": 1,
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(1).await;
|
||||
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"
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 5 - Get the complete document
|
||||
|
||||
let expected = json!({
|
||||
"id": 2,
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(2).await;
|
||||
assert_eq!(status_code, 200);
|
||||
assert_json_eq!(response, expected);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn index_new_fields_true_then_false() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body).await;
|
||||
|
||||
// 1 - Set indexNewFields = true
|
||||
|
||||
server.update_accept_new_fields(json!(true)).await;
|
||||
|
||||
// 2 - Add a document
|
||||
|
||||
let body = json!([{
|
||||
"id": 1,
|
||||
"title": "I'm a legend",
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 3 - Get the complete document
|
||||
|
||||
let expected = json!({
|
||||
"id": 1,
|
||||
"title": "I'm a legend",
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(1).await;
|
||||
assert_eq!(status_code, 200);
|
||||
assert_json_eq!(response, expected);
|
||||
|
||||
// 4 - Set indexNewFields = false
|
||||
|
||||
server.update_accept_new_fields(json!(false)).await;
|
||||
|
||||
// 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"
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 6 - Get the complete document
|
||||
|
||||
let expected = json!({
|
||||
"id": 2,
|
||||
"title": "I'm not a legend",
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(2).await;
|
||||
assert_eq!(status_code, 200);
|
||||
assert_json_eq!(response, expected);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn index_new_fields_false_then_true() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
"primaryKey": "id",
|
||||
});
|
||||
server.create_index(body).await;
|
||||
|
||||
// 1 - Set indexNewFields = false
|
||||
|
||||
server.update_accept_new_fields(json!(false)).await;
|
||||
|
||||
// 2 - Add a document
|
||||
|
||||
let body = json!([{
|
||||
"id": 1,
|
||||
"title": "I'm a legend",
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 3 - Get the complete document
|
||||
|
||||
let expected = json!({
|
||||
"id": 1,
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(1).await;
|
||||
assert_eq!(status_code, 200);
|
||||
assert_json_eq!(response, expected);
|
||||
|
||||
// 4 - Set indexNewFields = false
|
||||
|
||||
server.update_accept_new_fields(json!(true)).await;
|
||||
|
||||
// 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"
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 6 - Get the complete document
|
||||
|
||||
let expected = json!({
|
||||
"id": 1,
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(1).await;
|
||||
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"
|
||||
});
|
||||
|
||||
let (response, status_code) = server.get_document(2).await;
|
||||
assert_eq!(status_code, 200);
|
||||
assert_json_eq!(response, expected);
|
||||
}
|
||||
|
||||
// Fix issue https://github.com/meilisearch/MeiliSearch/issues/518
|
||||
#[actix_rt::test]
|
||||
async fn accept_new_fields_does_not_take_into_account_the_primary_key() {
|
||||
let mut server = common::Server::with_uid("movies");
|
||||
|
||||
// 1 - Create an index with no primary-key
|
||||
|
||||
let body = json!({
|
||||
"uid": "movies",
|
||||
});
|
||||
let (response, status_code) = server.create_index(body).await;
|
||||
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,
|
||||
});
|
||||
|
||||
server.update_all_settings(body).await;
|
||||
|
||||
// 4 - Add a document
|
||||
|
||||
let body = json!([{
|
||||
"id": 1,
|
||||
"title": "Test",
|
||||
"comment": "comment test"
|
||||
}]);
|
||||
|
||||
server.add_or_replace_multiple_documents(body).await;
|
||||
|
||||
// 5 - Get settings, they should not changed
|
||||
|
||||
let (response, _status_code) = server.get_all_settings().await;
|
||||
|
||||
let expected = json!({
|
||||
"rankingRules": [
|
||||
"typo",
|
||||
"words",
|
||||
"proximity",
|
||||
"attribute",
|
||||
"wordsPosition",
|
||||
"exactness",
|
||||
],
|
||||
"distinctAttribute": null,
|
||||
"searchableAttributes": ["title"],
|
||||
"displayedAttributes": ["title"],
|
||||
"stopWords": [],
|
||||
"synonyms": {},
|
||||
"attributesForFaceting": [],
|
||||
"acceptNewFields": false,
|
||||
});
|
||||
|
||||
assert_json_eq!(response, expected, ordered: false);
|
||||
}
|
@ -171,6 +171,7 @@ async fn write_custom_ranking_and_index_documents() {
|
||||
|
||||
let expected = json!({
|
||||
"id": 1,
|
||||
"name": "Cherry Orr",
|
||||
"color": "green"
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user