2020-01-23 11:30:18 +01:00
|
|
|
use assert_json_diff::assert_json_eq;
|
2020-10-30 11:30:18 +01:00
|
|
|
use serde_json::json;
|
2020-03-10 11:29:56 +01:00
|
|
|
use std::convert::Into;
|
2020-01-18 19:00:41 +01:00
|
|
|
mod common;
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn write_all_and_delete() {
|
2020-05-30 16:39:48 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-01-18 19:00:41 +01:00
|
|
|
// 2 - Send the settings
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let body = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": [
|
2020-02-26 18:47:03 +01:00
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
2020-02-27 14:31:08 +01:00
|
|
|
"wordsPosition",
|
2020-02-26 18:47:03 +01:00
|
|
|
"exactness",
|
2020-05-30 16:39:48 +02:00
|
|
|
"desc(registered)",
|
|
|
|
"desc(age)",
|
2020-01-18 19:00:41 +01:00
|
|
|
],
|
2020-05-30 16:39:48 +02:00
|
|
|
"distinctAttribute": "id",
|
2020-01-29 18:30:21 +01:00
|
|
|
"searchableAttributes": [
|
2020-02-02 22:59:19 +01:00
|
|
|
"id",
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"registered",
|
|
|
|
"about"
|
2020-01-18 19:00:41 +01:00
|
|
|
],
|
2020-01-29 18:30:21 +01:00
|
|
|
"displayedAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"registered",
|
|
|
|
"age",
|
2020-01-18 19:00:41 +01:00
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"stopWords": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"ad",
|
|
|
|
"in",
|
|
|
|
"ut",
|
2020-01-18 19:00:41 +01:00
|
|
|
],
|
|
|
|
"synonyms": {
|
2020-05-30 16:39:48 +02:00
|
|
|
"road": ["street", "avenue"],
|
|
|
|
"street": ["avenue"],
|
2020-01-27 18:27:42 +01:00
|
|
|
},
|
2020-05-30 16:39:48 +02:00
|
|
|
"attributesForFaceting": ["name"],
|
2020-01-18 19:00:41 +01:00
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(body.clone()).await;
|
2020-01-18 19:00:41 +01:00
|
|
|
|
2020-01-18 19:30:25 +01:00
|
|
|
// 3 - Get all settings and compare to the previous one
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
2020-01-18 19:30:25 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
assert_json_eq!(body, response, ordered: false);
|
2020-01-18 19:30:25 +01:00
|
|
|
|
|
|
|
// 4 - Delete all settings
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.delete_all_settings().await;
|
2020-01-18 19:30:25 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
// 5 - Get all settings and check if they are set to default values
|
2020-01-18 19:30:25 +01:00
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
2020-01-18 19:00:41 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let expect = json!({
|
2020-02-26 18:47:03 +01:00
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
2020-02-27 14:31:08 +01:00
|
|
|
"wordsPosition",
|
2020-02-26 18:47:03 +01:00
|
|
|
"exactness"
|
|
|
|
],
|
2020-02-26 16:05:02 +01:00
|
|
|
"distinctAttribute": null,
|
2020-07-10 11:37:01 +02:00
|
|
|
"searchableAttributes": ["*"],
|
|
|
|
"displayedAttributes": ["*"],
|
2020-03-05 15:05:04 +01:00
|
|
|
"stopWords": [],
|
|
|
|
"synonyms": {},
|
2020-06-03 11:09:25 +02:00
|
|
|
"attributesForFaceting": [],
|
2020-01-18 19:30:25 +01:00
|
|
|
});
|
2020-01-18 19:00:41 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
assert_json_eq!(expect, response, ordered: false);
|
2020-01-18 19:00:41 +01:00
|
|
|
}
|
2020-01-20 09:52:24 +01:00
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn write_all_and_update() {
|
2020-05-30 16:39:48 +02:00
|
|
|
let mut server = common::Server::test_server().await;
|
2020-01-20 09:52:24 +01:00
|
|
|
|
|
|
|
// 2 - Send the settings
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let body = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": [
|
2020-02-26 18:47:03 +01:00
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
2020-02-27 14:31:08 +01:00
|
|
|
"wordsPosition",
|
2020-02-26 18:47:03 +01:00
|
|
|
"exactness",
|
2020-05-30 16:39:48 +02:00
|
|
|
"desc(registered)",
|
|
|
|
"desc(age)",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-05-30 16:39:48 +02:00
|
|
|
"distinctAttribute": "id",
|
2020-01-29 18:30:21 +01:00
|
|
|
"searchableAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"registered",
|
|
|
|
"about"
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-01-29 18:30:21 +01:00
|
|
|
"displayedAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"registered",
|
|
|
|
"age",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-01-21 12:03:48 +01:00
|
|
|
"stopWords": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"ad",
|
|
|
|
"in",
|
|
|
|
"ut",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
|
|
|
"synonyms": {
|
2020-05-30 16:39:48 +02:00
|
|
|
"road": ["street", "avenue"],
|
|
|
|
"street": ["avenue"],
|
2020-01-27 18:27:42 +01:00
|
|
|
},
|
2020-05-30 16:39:48 +02:00
|
|
|
"attributesForFaceting": ["name"],
|
2020-01-20 09:52:24 +01:00
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(body.clone()).await;
|
2020-01-20 09:52:24 +01:00
|
|
|
|
|
|
|
// 3 - Get all settings and compare to the previous one
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
2020-01-20 09:52:24 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
assert_json_eq!(body, response, ordered: false);
|
2020-01-20 09:52:24 +01:00
|
|
|
|
|
|
|
// 4 - Update all settings
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let body = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": [
|
2020-02-26 18:47:03 +01:00
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
2020-02-27 14:31:08 +01:00
|
|
|
"wordsPosition",
|
2020-02-26 18:47:03 +01:00
|
|
|
"exactness",
|
2020-05-30 16:39:48 +02:00
|
|
|
"desc(age)",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-03-11 14:42:58 +01:00
|
|
|
"distinctAttribute": null,
|
2020-01-29 18:30:21 +01:00
|
|
|
"searchableAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"age",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-01-29 18:30:21 +01:00
|
|
|
"displayedAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"age",
|
|
|
|
"registered",
|
|
|
|
"picture",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-03-11 14:42:58 +01:00
|
|
|
"stopWords": [],
|
2020-01-20 09:52:24 +01:00
|
|
|
"synonyms": {
|
2020-05-30 16:39:48 +02:00
|
|
|
"road": ["street", "avenue"],
|
|
|
|
"street": ["avenue"],
|
2020-01-27 18:27:42 +01:00
|
|
|
},
|
2020-05-05 22:27:06 +02:00
|
|
|
"attributesForFaceting": ["title"],
|
2020-01-20 09:52:24 +01:00
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(body).await;
|
2020-01-20 09:52:24 +01:00
|
|
|
|
|
|
|
// 5 - Get all settings and check if the content is the same of (4)
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
2020-01-20 09:52:24 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let expected = json!({
|
2020-01-21 12:03:48 +01:00
|
|
|
"rankingRules": [
|
2020-02-26 18:47:03 +01:00
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
2020-02-27 14:31:08 +01:00
|
|
|
"wordsPosition",
|
2020-02-26 18:47:03 +01:00
|
|
|
"exactness",
|
2020-05-30 16:39:48 +02:00
|
|
|
"desc(age)",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-02-26 16:05:02 +01:00
|
|
|
"distinctAttribute": null,
|
2020-01-29 18:30:21 +01:00
|
|
|
"searchableAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"age",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-01-29 18:30:21 +01:00
|
|
|
"displayedAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"age",
|
|
|
|
"registered",
|
|
|
|
"picture",
|
2020-01-20 09:52:24 +01:00
|
|
|
],
|
2020-03-05 15:05:04 +01:00
|
|
|
"stopWords": [],
|
2020-01-20 09:52:24 +01:00
|
|
|
"synonyms": {
|
2020-05-30 16:39:48 +02:00
|
|
|
"road": ["street", "avenue"],
|
|
|
|
"street": ["avenue"],
|
2020-01-27 08:52:36 +01:00
|
|
|
},
|
2020-05-05 22:27:06 +02:00
|
|
|
"attributesForFaceting": ["title"],
|
2020-01-20 09:52:24 +01:00
|
|
|
});
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
assert_json_eq!(expected, response, ordered: false);
|
2020-01-20 09:52:24 +01:00
|
|
|
}
|
2020-03-05 18:29:10 +01:00
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_default_settings() {
|
2020-05-30 16:39:48 +02:00
|
|
|
let mut server = common::Server::with_uid("test");
|
2020-03-05 18:29:10 +01:00
|
|
|
let body = json!({
|
2020-05-30 16:39:48 +02:00
|
|
|
"uid": "test",
|
2020-03-05 18:29:10 +01:00
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
server.create_index(body).await;
|
2020-03-05 18:29:10 +01:00
|
|
|
|
|
|
|
// 1 - Get all settings and compare to the previous one
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
|
|
|
"exactness"
|
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
2020-07-10 11:37:01 +02:00
|
|
|
"searchableAttributes": ["*"],
|
|
|
|
"displayedAttributes": ["*"],
|
2020-03-05 18:29:10 +01:00
|
|
|
"stopWords": [],
|
|
|
|
"synonyms": {},
|
2020-06-03 11:09:25 +02:00
|
|
|
"attributesForFaceting": [],
|
2020-03-05 18:29:10 +01:00
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
2020-03-05 18:29:10 +01:00
|
|
|
|
|
|
|
assert_json_eq!(body, response, ordered: false);
|
|
|
|
}
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_default_settings_2() {
|
2020-05-30 16:39:48 +02:00
|
|
|
let mut server = common::Server::with_uid("test");
|
2020-03-05 18:29:10 +01:00
|
|
|
let body = json!({
|
2020-05-30 16:39:48 +02:00
|
|
|
"uid": "test",
|
2020-03-09 18:40:49 +01:00
|
|
|
"primaryKey": "id",
|
2020-03-05 18:29:10 +01:00
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
server.create_index(body).await;
|
2020-03-05 18:29:10 +01:00
|
|
|
|
|
|
|
// 1 - Get all settings and compare to the previous one
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
|
|
|
"exactness"
|
|
|
|
],
|
|
|
|
"distinctAttribute": null,
|
2020-07-10 11:37:01 +02:00
|
|
|
"searchableAttributes": ["*"],
|
|
|
|
"displayedAttributes": ["*"],
|
2020-03-05 18:29:10 +01:00
|
|
|
"stopWords": [],
|
|
|
|
"synonyms": {},
|
2020-06-03 11:09:25 +02:00
|
|
|
"attributesForFaceting": [],
|
2020-03-05 18:29:10 +01:00
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
2020-03-05 18:29:10 +01:00
|
|
|
|
|
|
|
assert_json_eq!(body, response, ordered: false);
|
|
|
|
}
|
2020-03-11 14:42:58 +01:00
|
|
|
|
|
|
|
// Test issue https://github.com/meilisearch/MeiliSearch/issues/516
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn write_setting_and_update_partial() {
|
2020-05-30 16:39:48 +02:00
|
|
|
let mut server = common::Server::with_uid("test");
|
2020-03-11 14:42:58 +01:00
|
|
|
let body = json!({
|
2020-05-30 16:39:48 +02:00
|
|
|
"uid": "test",
|
2020-03-11 14:42:58 +01:00
|
|
|
});
|
2020-04-16 11:09:47 +02:00
|
|
|
server.create_index(body).await;
|
2020-03-11 14:42:58 +01:00
|
|
|
|
|
|
|
// 2 - Send the settings
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"searchableAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-03-11 14:42:58 +01:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"registered",
|
|
|
|
"age",
|
2020-03-11 14:42:58 +01:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(body.clone()).await;
|
2020-03-11 14:42:58 +01:00
|
|
|
|
|
|
|
// 2 - Send the settings
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
|
|
|
"exactness",
|
2020-05-30 16:39:48 +02:00
|
|
|
"desc(age)",
|
|
|
|
"desc(registered)",
|
2020-03-11 14:42:58 +01:00
|
|
|
],
|
2020-05-30 16:39:48 +02:00
|
|
|
"distinctAttribute": "id",
|
2020-03-11 14:42:58 +01:00
|
|
|
"stopWords": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"ad",
|
|
|
|
"in",
|
|
|
|
"ut",
|
2020-03-11 14:42:58 +01:00
|
|
|
],
|
|
|
|
"synonyms": {
|
2020-05-30 16:39:48 +02:00
|
|
|
"road": ["street", "avenue"],
|
|
|
|
"street": ["avenue"],
|
2020-03-11 14:42:58 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_all_settings(body.clone()).await;
|
2020-03-11 14:42:58 +01:00
|
|
|
|
|
|
|
// 2 - Send the settings
|
|
|
|
|
|
|
|
let expected = json!({
|
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
|
|
|
"exactness",
|
2020-05-30 16:39:48 +02:00
|
|
|
"desc(age)",
|
|
|
|
"desc(registered)",
|
2020-03-11 14:42:58 +01:00
|
|
|
],
|
2020-05-30 16:39:48 +02:00
|
|
|
"distinctAttribute": "id",
|
2020-03-11 14:42:58 +01:00
|
|
|
"searchableAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"about"
|
2020-03-11 14:42:58 +01:00
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"name",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"registered",
|
|
|
|
"age",
|
2020-03-11 14:42:58 +01:00
|
|
|
],
|
|
|
|
"stopWords": [
|
2020-05-30 16:39:48 +02:00
|
|
|
"ad",
|
|
|
|
"in",
|
|
|
|
"ut",
|
2020-03-11 14:42:58 +01:00
|
|
|
],
|
|
|
|
"synonyms": {
|
2020-05-30 16:39:48 +02:00
|
|
|
"road": ["street", "avenue"],
|
|
|
|
"street": ["avenue"],
|
2020-03-11 14:42:58 +01:00
|
|
|
},
|
2020-06-03 11:09:25 +02:00
|
|
|
"attributesForFaceting": [],
|
2020-03-11 14:42:58 +01:00
|
|
|
});
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
2020-03-11 14:42:58 +01:00
|
|
|
|
|
|
|
assert_json_eq!(expected, response, ordered: false);
|
|
|
|
}
|
2020-06-03 11:09:25 +02:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn attributes_for_faceting_settings() {
|
|
|
|
let mut server = common::Server::test_server().await;
|
|
|
|
// initial attributes array should be empty
|
|
|
|
let (response, _status_code) = server.get_request("/indexes/test/settings/attributes-for-faceting").await;
|
|
|
|
assert_eq!(response, json!([]));
|
|
|
|
// add an attribute and test for its presence
|
|
|
|
let (_response, _status_code) = server.post_request_async(
|
|
|
|
"/indexes/test/settings/attributes-for-faceting",
|
|
|
|
json!(["foobar"])).await;
|
|
|
|
let (response, _status_code) = server.get_request("/indexes/test/settings/attributes-for-faceting").await;
|
|
|
|
assert_eq!(response, json!(["foobar"]));
|
|
|
|
// remove all attributes and test for emptiness
|
|
|
|
let (_response, _status_code) = server.delete_request_async(
|
|
|
|
"/indexes/test/settings/attributes-for-faceting").await;
|
|
|
|
let (response, _status_code) = server.get_request("/indexes/test/settings/attributes-for-faceting").await;
|
|
|
|
assert_eq!(response, json!([]));
|
|
|
|
}
|
2020-06-16 09:52:58 +02:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn setting_ranking_rules_dont_mess_with_other_settings() {
|
|
|
|
let mut server = common::Server::test_server().await;
|
|
|
|
let body = json!({
|
|
|
|
"rankingRules": ["asc(foobar)"]
|
|
|
|
});
|
|
|
|
server.update_all_settings(body).await;
|
|
|
|
let (response, _) = server.get_all_settings().await;
|
|
|
|
assert_eq!(response["rankingRules"].as_array().unwrap().len(), 1);
|
|
|
|
assert_eq!(response["rankingRules"].as_array().unwrap().first().unwrap().as_str().unwrap(), "asc(foobar)");
|
|
|
|
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"));
|
|
|
|
}
|
2020-07-15 18:51:36 +02:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn displayed_and_searchable_attributes_reset_to_wildcard() {
|
|
|
|
let mut server = common::Server::test_server().await;
|
|
|
|
server.update_all_settings(json!({ "searchableAttributes": ["color"], "displayedAttributes": ["color"] })).await;
|
|
|
|
let (response, _) = server.get_all_settings().await;
|
2020-07-15 19:21:03 +02:00
|
|
|
|
2020-07-15 18:51:36 +02:00
|
|
|
assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "color");
|
|
|
|
assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "color");
|
2020-07-15 19:21:03 +02:00
|
|
|
|
2020-07-15 18:51:36 +02:00
|
|
|
server.delete_searchable_attributes().await;
|
|
|
|
server.delete_displayed_attributes().await;
|
2020-07-15 19:21:03 +02:00
|
|
|
|
|
|
|
let (response, _) = server.get_all_settings().await;
|
|
|
|
|
2020-07-16 16:12:23 +02:00
|
|
|
assert_eq!(response["searchableAttributes"].as_array().unwrap().len(), 1);
|
|
|
|
assert_eq!(response["displayedAttributes"].as_array().unwrap().len(), 1);
|
2020-07-15 19:21:03 +02:00
|
|
|
assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*");
|
|
|
|
assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*");
|
|
|
|
|
|
|
|
let mut server = common::Server::test_server().await;
|
|
|
|
server.update_all_settings(json!({ "searchableAttributes": ["color"], "displayedAttributes": ["color"] })).await;
|
|
|
|
let (response, _) = server.get_all_settings().await;
|
|
|
|
assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "color");
|
|
|
|
assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "color");
|
|
|
|
|
|
|
|
server.update_all_settings(json!({ "searchableAttributes": [], "displayedAttributes": [] })).await;
|
|
|
|
|
2020-07-15 18:51:36 +02:00
|
|
|
let (response, _) = server.get_all_settings().await;
|
2020-07-16 16:12:23 +02:00
|
|
|
|
|
|
|
assert_eq!(response["searchableAttributes"].as_array().unwrap().len(), 1);
|
|
|
|
assert_eq!(response["displayedAttributes"].as_array().unwrap().len(), 1);
|
|
|
|
assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*");
|
|
|
|
assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn settings_that_contains_wildcard_is_wildcard() {
|
|
|
|
let mut server = common::Server::test_server().await;
|
|
|
|
server.update_all_settings(json!({ "searchableAttributes": ["color", "*"], "displayedAttributes": ["color", "*"] })).await;
|
|
|
|
|
|
|
|
let (response, _) = server.get_all_settings().await;
|
|
|
|
|
|
|
|
assert_eq!(response["searchableAttributes"].as_array().unwrap().len(), 1);
|
|
|
|
assert_eq!(response["displayedAttributes"].as_array().unwrap().len(), 1);
|
2020-07-15 18:51:36 +02:00
|
|
|
assert_eq!(response["searchableAttributes"].as_array().unwrap()[0], "*");
|
|
|
|
assert_eq!(response["displayedAttributes"].as_array().unwrap()[0], "*");
|
|
|
|
}
|
2020-10-10 04:43:09 +02:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_displayed_attributes_field() {
|
|
|
|
let mut server = common::Server::test_server().await;
|
|
|
|
|
|
|
|
let body = json!({
|
2020-08-31 18:15:07 +02:00
|
|
|
"rankingRules": [
|
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
|
|
|
"exactness",
|
|
|
|
"desc(registered)",
|
|
|
|
"desc(age)",
|
|
|
|
],
|
|
|
|
"distinctAttribute": "id",
|
|
|
|
"searchableAttributes": [
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"color",
|
|
|
|
"gender",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"registered",
|
|
|
|
"about"
|
|
|
|
],
|
|
|
|
"displayedAttributes": [
|
2020-10-30 11:30:18 +01:00
|
|
|
"age",
|
2020-08-31 18:15:07 +02:00
|
|
|
"email",
|
2020-10-30 11:30:18 +01:00
|
|
|
"gender",
|
|
|
|
"name",
|
2020-08-31 18:15:07 +02:00
|
|
|
"registered",
|
|
|
|
],
|
|
|
|
"stopWords": [
|
|
|
|
"ad",
|
|
|
|
"in",
|
|
|
|
"ut",
|
|
|
|
],
|
|
|
|
"synonyms": {
|
2020-10-30 11:30:18 +01:00
|
|
|
"road": ["avenue", "street"],
|
2020-08-31 18:15:07 +02:00
|
|
|
"street": ["avenue"],
|
|
|
|
},
|
2020-10-30 11:30:18 +01:00
|
|
|
"attributesForFaceting": ["name"],
|
2020-08-31 18:15:07 +02:00
|
|
|
});
|
|
|
|
|
2020-10-30 11:30:18 +01:00
|
|
|
server.update_all_settings(body.clone()).await;
|
2020-08-31 18:15:07 +02:00
|
|
|
|
|
|
|
let (response, _status_code) = server.get_all_settings().await;
|
|
|
|
|
2020-10-30 11:30:18 +01:00
|
|
|
assert_json_eq!(body, response, ordered: true);
|
|
|
|
}
|