test setting attributes before adding documents

This commit is contained in:
mpostma 2020-07-10 14:54:35 +02:00
parent c06dd35af1
commit 36b763b84e

View File

@ -1195,15 +1195,21 @@ async fn search_with_differents_attributes_8() {
#[actix_rt::test] #[actix_rt::test]
async fn test_faceted_search_valid() { async fn test_faceted_search_valid() {
let mut server = common::Server::test_server().await; // set facetting attributes before adding documents
let mut server = common::Server::with_uid("test");
server.create_index(json!({ "uid": "test" })).await;
// simple tests on attributes with string value
let body = json!({ let body = json!({
"attributesForFaceting": ["color"] "attributesForFaceting": ["color"]
}); });
server.update_all_settings(body).await; server.update_all_settings(body).await;
let dataset = include_bytes!("assets/test_set.json");
let body: Value = serde_json::from_slice(dataset).unwrap();
server.add_or_update_multiple_documents(body).await;
// simple tests on attributes with string value
let query = json!({ let query = json!({
"q": "a", "q": "a",
"facetFilters": ["color:green"] "facetFilters": ["color:green"]
@ -1357,8 +1363,8 @@ async fn test_faceted_search_invalid() {
test_post_get_search!(server, query, |response, status_code| { test_post_get_search!(server, query, |response, status_code| {
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
assert_eq!(response["errorCode"], "invalid_facet"); assert_eq!(response["errorCode"], "invalid_facet");
}); });
let body = json!({ let body = json!({
"attributesForFaceting": ["color", "tags"] "attributesForFaceting": ["color", "tags"]
@ -1373,7 +1379,7 @@ async fn test_faceted_search_invalid() {
test_post_get_search!(server, query, |response, status_code| { test_post_get_search!(server, query, |response, status_code| {
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
assert_eq!(response["errorCode"], "invalid_facet"); assert_eq!(response["errorCode"], "invalid_facet");
}); });
// [[]] // [[]]
let query = json!({ let query = json!({
@ -1383,7 +1389,7 @@ async fn test_faceted_search_invalid() {
test_post_get_search!(server, query, |response, status_code| { test_post_get_search!(server, query, |response, status_code| {
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
assert_eq!(response["errorCode"], "invalid_facet"); assert_eq!(response["errorCode"], "invalid_facet");
}); });
// ["color:green", []] // ["color:green", []]
@ -1394,7 +1400,7 @@ async fn test_faceted_search_invalid() {
test_post_get_search!(server, query, |response, status_code| { test_post_get_search!(server, query, |response, status_code| {
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
assert_eq!(response["errorCode"], "invalid_facet"); assert_eq!(response["errorCode"], "invalid_facet");
}); });
// too much depth // too much depth
@ -1406,7 +1412,7 @@ async fn test_faceted_search_invalid() {
test_post_get_search!(server, query, |response, status_code| { test_post_get_search!(server, query, |response, status_code| {
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
assert_eq!(response["errorCode"], "invalid_facet"); assert_eq!(response["errorCode"], "invalid_facet");
}); });
// [["color:green", ["color:blue"]]] // [["color:green", ["color:blue"]]]
@ -1417,7 +1423,7 @@ async fn test_faceted_search_invalid() {
test_post_get_search!(server, query, |response, status_code| { test_post_get_search!(server, query, |response, status_code| {
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
assert_eq!(response["errorCode"], "invalid_facet"); assert_eq!(response["errorCode"], "invalid_facet");
}); });
// "color:green" // "color:green"
@ -1428,7 +1434,7 @@ async fn test_faceted_search_invalid() {
test_post_get_search!(server, query, |response, status_code| { test_post_get_search!(server, query, |response, status_code| {
assert_eq!(status_code, 400); assert_eq!(status_code, 400);
assert_eq!(response["errorCode"], "invalid_facet"); assert_eq!(response["errorCode"], "invalid_facet");
}); });
} }