2020-01-28 17:45:57 +01:00
|
|
|
use assert_json_diff::assert_json_eq;
|
|
|
|
use serde_json::json;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn write_all_and_delete() {
|
2020-03-04 14:18:07 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
server.populate_movies();
|
2020-01-28 17:45:57 +01:00
|
|
|
|
|
|
|
// 2 - Send the settings
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let body = json!([
|
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-03-02 17:13:23 +01:00
|
|
|
"desc(release_date)",
|
|
|
|
"desc(rank)",
|
2020-02-10 16:51:17 +01:00
|
|
|
]);
|
2020-01-28 17:45:57 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
server.update_ranking_rules(body.clone());
|
2020-01-28 17:45:57 +01:00
|
|
|
|
|
|
|
// 3 - Get all settings and compare to the previous one
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let (response, _status_code) = server.get_ranking_rules();
|
2020-02-02 22:59:19 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
assert_json_eq!(body, response, ordered: false);
|
2020-01-28 17:45:57 +01:00
|
|
|
|
|
|
|
// 4 - Delete all settings
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
server.delete_ranking_rules();
|
2020-01-28 17:45:57 +01:00
|
|
|
|
|
|
|
// 5 - Get all settings and check if they are empty
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let (response, _status_code) = server.get_ranking_rules();
|
2020-01-28 17:45:57 +01:00
|
|
|
|
2020-03-05 15:18:19 +01:00
|
|
|
let expected = json!([
|
2020-03-02 14:34:29 +01:00
|
|
|
"typo",
|
|
|
|
"words",
|
|
|
|
"proximity",
|
|
|
|
"attribute",
|
|
|
|
"wordsPosition",
|
|
|
|
"exactness"
|
2020-02-26 18:47:03 +01:00
|
|
|
]);
|
2020-02-02 22:59:19 +01:00
|
|
|
|
2020-03-05 15:18:19 +01:00
|
|
|
assert_json_eq!(expected, response, ordered: false);
|
2020-01-28 17:45:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn write_all_and_update() {
|
2020-03-04 14:18:07 +01:00
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
server.populate_movies();
|
2020-01-28 17:45:57 +01:00
|
|
|
|
|
|
|
// 2 - Send the settings
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let body = json!([
|
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-03-02 17:13:23 +01:00
|
|
|
"desc(release_date)",
|
|
|
|
"desc(rank)",
|
2020-02-10 16:51:17 +01:00
|
|
|
]);
|
2020-01-28 17:45:57 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
server.update_ranking_rules(body.clone());
|
2020-01-28 17:45:57 +01:00
|
|
|
|
|
|
|
// 3 - Get all settings and compare to the previous one
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let (response, _status_code) = server.get_ranking_rules();
|
2020-01-28 17:45:57 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
assert_json_eq!(body, response, ordered: false);
|
2020-01-28 17:45:57 +01:00
|
|
|
|
|
|
|
// 4 - Update all settings
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let body = json!([
|
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-03-02 17:13:23 +01:00
|
|
|
"desc(release_date)",
|
2020-02-10 16:51:17 +01:00
|
|
|
]);
|
2020-01-28 17:45:57 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
server.update_ranking_rules(body);
|
2020-01-28 17:45:57 +01:00
|
|
|
|
|
|
|
// 5 - Get all settings and check if the content is the same of (4)
|
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let (response, _status_code) = server.get_ranking_rules();
|
2020-01-28 17:45:57 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
let expected = json!([
|
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-03-02 17:13:23 +01:00
|
|
|
"desc(release_date)",
|
2020-02-10 16:51:17 +01:00
|
|
|
]);
|
2020-01-28 17:45:57 +01:00
|
|
|
|
2020-03-04 14:18:07 +01:00
|
|
|
assert_json_eq!(expected, response, ordered: false);
|
2020-01-28 17:45:57 +01:00
|
|
|
}
|
2020-03-05 15:18:19 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn send_undefined_rule() {
|
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
|
|
|
"identifier": "id",
|
|
|
|
});
|
|
|
|
server.create_index(body);
|
|
|
|
|
|
|
|
let body = json!([
|
|
|
|
"typos",
|
|
|
|
]);
|
|
|
|
|
|
|
|
let (_response, status_code) = server.update_ranking_rules_sync(body);
|
|
|
|
assert_eq!(status_code, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn send_malformed_custom_rule() {
|
|
|
|
let mut server = common::Server::with_uid("movies");
|
|
|
|
let body = json!({
|
|
|
|
"uid": "movies",
|
|
|
|
"identifier": "id",
|
|
|
|
});
|
|
|
|
server.create_index(body);
|
|
|
|
|
|
|
|
let body = json!([
|
|
|
|
"dsc(truc)",
|
|
|
|
]);
|
|
|
|
|
|
|
|
let (_response, status_code) = server.update_ranking_rules_sync(body);
|
|
|
|
assert_eq!(status_code, 400);
|
|
|
|
}
|