2020-03-05 14:17:15 +01:00
|
|
|
use assert_json_diff::assert_json_eq;
|
|
|
|
use serde_json::json;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn update_stop_words() {
|
2020-05-30 18:50:19 +05:30
|
|
|
let mut server = common::Server::test_server().await;
|
2020-03-05 14:17:15 +01:00
|
|
|
|
|
|
|
// 1 - Get stop words
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_stop_words().await;
|
2020-03-05 14:17:15 +01:00
|
|
|
assert_eq!(response.as_array().unwrap().is_empty(), true);
|
|
|
|
|
|
|
|
// 2 - Update stop words
|
|
|
|
|
2020-05-30 18:50:19 +05:30
|
|
|
let body = json!(["ut", "ea"]);
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_stop_words(body.clone()).await;
|
2020-03-05 14:17:15 +01:00
|
|
|
|
|
|
|
// 3 - Get all stop words and compare to the previous one
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_stop_words().await;
|
2020-03-05 14:17:15 +01:00
|
|
|
assert_json_eq!(body, response, ordered: false);
|
|
|
|
|
|
|
|
// 4 - Delete all stop words
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
server.delete_stop_words().await;
|
2020-03-05 14:17:15 +01:00
|
|
|
|
|
|
|
// 5 - Get all stop words and check if they are empty
|
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
let (response, _status_code) = server.get_stop_words().await;
|
2020-03-05 14:17:15 +01:00
|
|
|
assert_eq!(response.as_array().unwrap().is_empty(), true);
|
|
|
|
}
|
2020-04-06 19:25:56 +02:00
|
|
|
|
2020-04-16 11:09:47 +02:00
|
|
|
#[actix_rt::test]
|
|
|
|
async fn add_documents_and_stop_words() {
|
2020-05-30 18:50:19 +05:30
|
|
|
let mut server = common::Server::test_server().await;
|
2020-04-06 19:25:56 +02:00
|
|
|
|
|
|
|
// 2 - Update stop words
|
|
|
|
|
2020-05-30 18:50:19 +05:30
|
|
|
let body = json!(["ad", "in"]);
|
2020-04-16 11:09:47 +02:00
|
|
|
server.update_stop_words(body.clone()).await;
|
2020-04-06 19:25:56 +02:00
|
|
|
|
|
|
|
// 3 - Search for a document with stop words
|
|
|
|
|
2020-05-30 18:50:19 +05:30
|
|
|
let (response, _status_code) = server.search_get("q=in%20exercitation").await;
|
2020-04-06 19:25:56 +02:00
|
|
|
assert!(!response["hits"].as_array().unwrap().is_empty());
|
|
|
|
|
|
|
|
// 4 - Search for documents with *only* stop words
|
|
|
|
|
2020-05-30 18:50:19 +05:30
|
|
|
let (response, _status_code) = server.search_get("q=ad%20in").await;
|
2020-04-06 19:25:56 +02:00
|
|
|
assert!(response["hits"].as_array().unwrap().is_empty());
|
|
|
|
|
|
|
|
// 5 - Delete all stop words
|
|
|
|
|
|
|
|
// server.delete_stop_words();
|
|
|
|
|
|
|
|
// // 6 - Search for a document with one stop word
|
|
|
|
|
|
|
|
// assert!(!response["hits"].as_array().unwrap().is_empty());
|
|
|
|
}
|