2021-02-24 09:30:51 +01:00
|
|
|
use crate::common::Server;
|
|
|
|
use serde_json::json;
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn get_settings_unexisting_index() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let (_response, code) = server.index("test").settings().await;
|
|
|
|
assert_eq!(code, 400)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn get_settings() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
index.create(None).await;
|
|
|
|
let (response, code) = index.settings().await;
|
|
|
|
assert_eq!(code, 200);
|
|
|
|
let settings = response.as_object().unwrap();
|
2021-04-19 20:23:25 +02:00
|
|
|
assert_eq!(settings.keys().len(), 6);
|
2021-02-24 09:30:51 +01:00
|
|
|
assert_eq!(settings["displayedAttributes"], json!(["*"]));
|
|
|
|
assert_eq!(settings["searchableAttributes"], json!(["*"]));
|
2021-04-28 16:43:49 +02:00
|
|
|
assert_eq!(settings["attributesForFaceting"], json!(null));
|
2021-04-20 12:07:22 +02:00
|
|
|
assert_eq!(settings["distinctAttribute"], json!(null));
|
2021-03-15 18:11:10 +01:00
|
|
|
assert_eq!(
|
|
|
|
settings["rankingRules"],
|
2021-04-14 17:53:12 +02:00
|
|
|
json!(["words", "typo", "proximity", "attribute", "exactness"])
|
2021-03-15 18:11:10 +01:00
|
|
|
);
|
2021-04-06 15:43:27 +02:00
|
|
|
assert_eq!(settings["stopWords"], json!([]));
|
2021-02-24 09:30:51 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 09:42:36 +01:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn update_settings_unknown_field() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
let (_response, code) = index.update_settings(json!({"foo": 12})).await;
|
|
|
|
assert_eq!(code, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_partial_update() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
2021-03-15 18:11:10 +01:00
|
|
|
let (_response, _code) = index
|
|
|
|
.update_settings(json!({"displayedAttributes": ["foo"]}))
|
|
|
|
.await;
|
2021-02-24 09:42:36 +01:00
|
|
|
index.wait_update_id(0).await;
|
|
|
|
let (response, code) = index.settings().await;
|
|
|
|
assert_eq!(code, 200);
|
2021-03-15 18:11:10 +01:00
|
|
|
assert_eq!(response["displayedAttributes"], json!(["foo"]));
|
|
|
|
assert_eq!(response["searchableAttributes"], json!(["*"]));
|
2021-02-24 09:42:36 +01:00
|
|
|
|
2021-03-15 18:11:10 +01:00
|
|
|
let (_response, _) = index
|
|
|
|
.update_settings(json!({"searchableAttributes": ["bar"]}))
|
|
|
|
.await;
|
2021-02-24 09:42:36 +01:00
|
|
|
index.wait_update_id(1).await;
|
|
|
|
|
|
|
|
let (response, code) = index.settings().await;
|
|
|
|
assert_eq!(code, 200);
|
2021-03-15 18:11:10 +01:00
|
|
|
assert_eq!(response["displayedAttributes"], json!(["foo"]));
|
|
|
|
assert_eq!(response["searchableAttributes"], json!(["bar"]));
|
2021-02-24 09:42:36 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 10:14:36 +01:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn delete_settings_unexisting_index() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
let (_response, code) = index.delete_settings().await;
|
|
|
|
assert_eq!(code, 400);
|
|
|
|
}
|
|
|
|
|
2021-02-24 10:19:22 +01:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn reset_all_settings() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
2021-03-15 18:11:10 +01:00
|
|
|
index
|
2021-04-06 18:29:38 +02:00
|
|
|
.update_settings(json!({"displayedAttributes": ["foo"], "searchableAttributes": ["bar"], "stopWords": ["the"] }))
|
2021-03-15 18:11:10 +01:00
|
|
|
.await;
|
2021-02-24 10:19:22 +01:00
|
|
|
index.wait_update_id(0).await;
|
|
|
|
let (response, code) = index.settings().await;
|
|
|
|
assert_eq!(code, 200);
|
2021-03-15 18:11:10 +01:00
|
|
|
assert_eq!(response["displayedAttributes"], json!(["foo"]));
|
|
|
|
assert_eq!(response["searchableAttributes"], json!(["bar"]));
|
2021-04-06 18:29:38 +02:00
|
|
|
assert_eq!(response["stopWords"], json!(["the"]));
|
2021-02-24 10:19:22 +01:00
|
|
|
|
|
|
|
index.delete_settings().await;
|
|
|
|
index.wait_update_id(1).await;
|
|
|
|
|
|
|
|
let (response, code) = index.settings().await;
|
|
|
|
assert_eq!(code, 200);
|
2021-03-15 18:11:10 +01:00
|
|
|
assert_eq!(response["displayedAttributes"], json!(["*"]));
|
|
|
|
assert_eq!(response["searchableAttributes"], json!(["*"]));
|
2021-04-06 18:29:38 +02:00
|
|
|
assert_eq!(response["stopWords"], json!([]));
|
2021-02-24 10:19:22 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 09:30:51 +01:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn update_setting_unexisting_index() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test");
|
|
|
|
let (_response, code) = index.update_settings(json!({})).await;
|
2021-03-17 14:44:32 +01:00
|
|
|
assert_eq!(code, 202);
|
2021-02-24 09:30:51 +01:00
|
|
|
let (_response, code) = index.get().await;
|
|
|
|
assert_eq!(code, 200);
|
2021-03-17 15:09:13 +01:00
|
|
|
let (_response, code) = index.delete_settings().await;
|
|
|
|
assert_eq!(code, 202);
|
2021-02-24 09:30:51 +01:00
|
|
|
}
|
|
|
|
|
2021-03-10 14:43:10 +01:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn update_setting_unexisting_index_invalid_uid() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let index = server.index("test##! ");
|
|
|
|
let (_response, code) = index.update_settings(json!({})).await;
|
|
|
|
assert_eq!(code, 400);
|
|
|
|
}
|
|
|
|
|
2021-02-24 09:30:51 +01:00
|
|
|
macro_rules! test_setting_routes {
|
|
|
|
($($setting:ident), *) => {
|
|
|
|
$(
|
|
|
|
mod $setting {
|
|
|
|
use crate::common::Server;
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn get_unexisting_index() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let url = format!("/indexes/test/settings/{}",
|
|
|
|
stringify!($setting)
|
|
|
|
.chars()
|
|
|
|
.map(|c| if c == '_' { '-' } else { c })
|
|
|
|
.collect::<String>());
|
|
|
|
let (_response, code) = server.service.get(url).await;
|
|
|
|
assert_eq!(code, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn update_unexisting_index() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let url = format!("/indexes/test/settings/{}",
|
|
|
|
stringify!($setting)
|
|
|
|
.chars()
|
|
|
|
.map(|c| if c == '_' { '-' } else { c })
|
|
|
|
.collect::<String>());
|
2021-03-12 00:37:43 +01:00
|
|
|
let (response, code) = server.service.post(url, serde_json::Value::Null).await;
|
2021-04-01 15:50:45 +02:00
|
|
|
assert_eq!(code, 202, "{}", response);
|
2021-03-12 00:37:43 +01:00
|
|
|
let (response, code) = server.index("test").get().await;
|
|
|
|
assert_eq!(code, 200, "{}", response);
|
2021-02-24 09:30:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn delete_unexisting_index() {
|
|
|
|
let server = Server::new().await;
|
|
|
|
let url = format!("/indexes/test/settings/{}",
|
|
|
|
stringify!($setting)
|
|
|
|
.chars()
|
|
|
|
.map(|c| if c == '_' { '-' } else { c })
|
|
|
|
.collect::<String>());
|
|
|
|
let (_response, code) = server.service.delete(url).await;
|
|
|
|
assert_eq!(code, 400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
test_setting_routes!(
|
|
|
|
attributes_for_faceting,
|
|
|
|
displayed_attributes,
|
2021-04-06 18:29:38 +02:00
|
|
|
searchable_attributes,
|
|
|
|
stop_words
|
2021-03-15 18:11:10 +01:00
|
|
|
);
|