add tests

This commit is contained in:
marin postma 2021-06-23 16:21:32 +02:00
parent 322d6b8cfe
commit b9b4feada8
No known key found for this signature in database
GPG Key ID: 6088B7721C3E39F9
2 changed files with 41 additions and 8 deletions

View File

@ -1,5 +1,21 @@
use std::collections::HashMap;
use once_cell::sync::Lazy;
use serde_json::{Value, json};
use crate::common::Server;
use serde_json::json;
static DEFAULT_SETTINGS_VALUES: Lazy<HashMap<&'static str, Value>> = Lazy::new(|| {
let mut map = HashMap::new();
map.insert("displayed_attributes", json!(["*"]));
map.insert("searchable_attributes", json!(["*"]));
map.insert("filterable_attributes", json!([]));
map.insert("distinct_attribute", json!(Value::Null));
map.insert("ranking_rules", json!(["words", "typo", "proximity", "attribute", "exactness"]));
map.insert("stop_words", json!([]));
map.insert("synonyms", json!({}));
map
});
#[actix_rt::test]
async fn get_settings_unexisting_index() {
@ -142,6 +158,7 @@ macro_rules! test_setting_routes {
$(
mod $setting {
use crate::common::Server;
use super::DEFAULT_SETTINGS_VALUES;
#[actix_rt::test]
async fn get_unexisting_index() {
@ -177,8 +194,25 @@ macro_rules! test_setting_routes {
.chars()
.map(|c| if c == '_' { '-' } else { c })
.collect::<String>());
let (_response, code) = server.service.delete(url).await;
assert_eq!(code, 404);
let (response, code) = server.service.delete(url).await;
assert_eq!(code, 404, "{}", response);
}
#[actix_rt::test]
async fn get_default() {
let server = Server::new().await;
let index = server.index("test");
let (response, code) = index.create(None).await;
assert_eq!(code, 200, "{}", response);
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, 200, "{}", response);
let expected = DEFAULT_SETTINGS_VALUES.get(stringify!($setting)).unwrap();
assert_eq!(expected, &response);
}
}
)*
@ -189,6 +223,8 @@ test_setting_routes!(
filterable_attributes,
displayed_attributes,
searchable_attributes,
distinct_attribute,
stop_words,
ranking_rules,
synonyms
);

View File

@ -54,11 +54,8 @@ async fn stats() {
assert_eq!(code, 202, "{}", response);
assert_eq!(response["updateId"], 0);
let (response, code) = server.stats().await;
assert_eq!(code, 200, "{}", response);
index.wait_update_id(0).await;
let response = index.wait_update_id(0).await;
println!("response: {}", response);
let (response, code) = server.stats().await;