431 lines
9.7 KiB
Rust
Raw Permalink Normal View History

2020-01-23 11:30:18 +01:00
use assert_json_diff::assert_json_eq;
2020-01-18 19:00:41 +01:00
use serde_json::json;
2020-03-10 11:29:56 +01:00
use std::convert::Into;
2020-01-18 19:00:41 +01:00
mod common;
#[test]
2020-01-20 09:52:24 +01:00
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-18 19:00:41 +01:00
// 2 - Send the settings
2020-03-04 14:18:07 +01:00
let body = json!({
2020-01-21 12:03:48 +01:00
"rankingRules": [
2020-02-26 18:47:03 +01:00
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
2020-02-26 18:47:03 +01:00
"exactness",
"desc(release_date)",
"desc(rank)",
2020-01-18 19:00:41 +01:00
],
2020-02-26 16:05:02 +01:00
"distinctAttribute": "movie_id",
2020-01-29 18:30:21 +01:00
"searchableAttributes": [
2020-02-02 22:59:19 +01:00
"id",
2020-01-18 19:00:41 +01:00
"movie_id",
"title",
"description",
"poster",
"release_date",
"rank",
],
2020-01-29 18:30:21 +01:00
"displayedAttributes": [
2020-01-18 19:00:41 +01:00
"title",
"description",
"poster",
"release_date",
"rank",
],
2020-01-21 12:03:48 +01:00
"stopWords": [
2020-01-18 19:00:41 +01:00
"the",
"a",
"an",
],
"synonyms": {
"wolverine": ["xmen", "logan"],
"logan": ["wolverine"],
2020-01-27 18:27:42 +01:00
},
2020-02-26 16:05:02 +01:00
"acceptNewFields": false,
2020-01-18 19:00:41 +01:00
});
2020-03-04 14:18:07 +01:00
server.update_all_settings(body.clone());
2020-01-18 19:00:41 +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_all_settings();
2020-03-04 14:18:07 +01:00
assert_json_eq!(body, response, ordered: false);
// 4 - Delete all settings
2020-03-04 14:18:07 +01:00
server.delete_all_settings();
2020-03-04 14:18:07 +01:00
// 5 - Get all settings and check if they are set to default values
2020-03-04 14:18:07 +01:00
let (response, _status_code) = server.get_all_settings();
2020-01-18 19:00:41 +01:00
2020-03-04 14:18:07 +01:00
let expect = json!({
2020-02-26 18:47:03 +01:00
"rankingRules": [
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
2020-02-26 18:47:03 +01:00
"exactness"
],
2020-02-26 16:05:02 +01:00
"distinctAttribute": null,
2020-02-26 18:47:03 +01:00
"searchableAttributes": [
2020-03-04 14:18:07 +01:00
"poster_path",
"director",
2020-02-26 18:47:03 +01:00
"id",
2020-03-04 14:18:07 +01:00
"production_companies",
"producer",
2020-02-26 18:47:03 +01:00
"poster",
"movie_id",
2020-03-04 14:18:07 +01:00
"vote_count",
"cast",
"release_date",
"vote_average",
"rank",
"genres",
"overview",
"description",
"tagline",
"popularity",
"title"
2020-02-26 18:47:03 +01:00
],
"displayedAttributes": [
2020-03-04 14:18:07 +01:00
"poster_path",
2020-02-26 18:47:03 +01:00
"poster",
2020-03-04 14:18:07 +01:00
"vote_count",
2020-02-26 18:47:03 +01:00
"id",
2020-03-04 14:18:07 +01:00
"movie_id",
"title",
2020-02-26 18:47:03 +01:00
"rank",
2020-03-04 14:18:07 +01:00
"tagline",
"cast",
"producer",
"production_companies",
"description",
"director",
"genres",
"release_date",
"overview",
"vote_average",
"popularity"
2020-02-26 18:47:03 +01:00
],
"stopWords": [],
"synonyms": {},
2020-02-26 16:05:02 +01:00
"acceptNewFields": true,
});
2020-01-18 19:00:41 +01:00
2020-03-04 14:18:07 +01:00
assert_json_eq!(expect, response, ordered: false);
2020-01-18 19:00:41 +01:00
}
2020-01-20 09:52:24 +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-20 09:52:24 +01:00
// 2 - Send the settings
2020-03-04 14:18:07 +01:00
let body = json!({
2020-01-21 12:03:48 +01:00
"rankingRules": [
2020-02-26 18:47:03 +01:00
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
2020-02-26 18:47:03 +01:00
"exactness",
"desc(release_date)",
"desc(rank)",
2020-01-20 09:52:24 +01:00
],
2020-02-26 16:05:02 +01:00
"distinctAttribute": "movie_id",
2020-01-29 18:30:21 +01:00
"searchableAttributes": [
2020-01-20 09:52:24 +01:00
"uid",
"movie_id",
"title",
"description",
"poster",
"release_date",
"rank",
],
2020-01-29 18:30:21 +01:00
"displayedAttributes": [
2020-01-20 09:52:24 +01:00
"title",
"description",
"poster",
"release_date",
"rank",
],
2020-01-21 12:03:48 +01:00
"stopWords": [
2020-01-20 09:52:24 +01:00
"the",
"a",
"an",
],
"synonyms": {
"wolverine": ["xmen", "logan"],
"logan": ["wolverine"],
2020-01-27 18:27:42 +01:00
},
2020-02-26 16:05:02 +01:00
"acceptNewFields": false,
2020-01-20 09:52:24 +01:00
});
2020-03-04 14:18:07 +01:00
server.update_all_settings(body.clone());
2020-01-20 09:52:24 +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_all_settings();
2020-01-20 09:52:24 +01:00
2020-03-04 14:18:07 +01:00
assert_json_eq!(body, response, ordered: false);
2020-01-20 09:52:24 +01:00
// 4 - Update all settings
2020-03-04 14:18:07 +01:00
let body = json!({
2020-01-21 12:03:48 +01:00
"rankingRules": [
2020-02-26 18:47:03 +01:00
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
2020-02-26 18:47:03 +01:00
"exactness",
"desc(release_date)",
2020-01-20 09:52:24 +01:00
],
"distinctAttribute": null,
2020-01-29 18:30:21 +01:00
"searchableAttributes": [
2020-01-20 09:52:24 +01:00
"title",
"description",
"uid",
],
2020-01-29 18:30:21 +01:00
"displayedAttributes": [
2020-01-20 09:52:24 +01:00
"title",
"description",
"release_date",
"rank",
"poster",
],
"stopWords": [],
2020-01-20 09:52:24 +01:00
"synonyms": {
"wolverine": ["xmen", "logan"],
"logan": ["wolverine", "xmen"],
2020-01-27 18:27:42 +01:00
},
2020-02-26 16:05:02 +01:00
"acceptNewFields": false,
2020-01-20 09:52:24 +01:00
});
2020-03-04 14:18:07 +01:00
server.update_all_settings(body);
2020-01-20 09:52:24 +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_all_settings();
2020-01-20 09:52:24 +01:00
2020-03-04 14:18:07 +01:00
let expected = json!({
2020-01-21 12:03:48 +01:00
"rankingRules": [
2020-02-26 18:47:03 +01:00
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
2020-02-26 18:47:03 +01:00
"exactness",
"desc(release_date)",
2020-01-20 09:52:24 +01:00
],
2020-02-26 16:05:02 +01:00
"distinctAttribute": null,
2020-01-29 18:30:21 +01:00
"searchableAttributes": [
2020-01-20 09:52:24 +01:00
"title",
"description",
"uid",
],
2020-01-29 18:30:21 +01:00
"displayedAttributes": [
2020-01-20 09:52:24 +01:00
"title",
"description",
"release_date",
"rank",
"poster",
],
"stopWords": [],
2020-01-20 09:52:24 +01:00
"synonyms": {
"wolverine": ["xmen", "logan"],
"logan": ["wolverine", "xmen"],
2020-01-27 08:52:36 +01:00
},
2020-02-26 16:05:02 +01:00
"acceptNewFields": false
2020-01-20 09:52:24 +01:00
});
2020-03-04 14:18:07 +01:00
assert_json_eq!(expected, response, ordered: false);
2020-01-20 09:52:24 +01:00
}
#[test]
fn test_default_settings() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
});
server.create_index(body);
// 1 - Get all settings and compare to the previous one
let body = json!({
"rankingRules": [
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness"
],
"distinctAttribute": null,
"searchableAttributes": [],
"displayedAttributes": [],
"stopWords": [],
"synonyms": {},
"acceptNewFields": true,
});
let (response, _status_code) = server.get_all_settings();
assert_json_eq!(body, response, ordered: false);
}
#[test]
fn test_default_settings_2() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
// 1 - Get all settings and compare to the previous one
let body = json!({
"rankingRules": [
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness"
],
"distinctAttribute": null,
"searchableAttributes": [
"id"
],
"displayedAttributes": [
"id"
],
"stopWords": [],
"synonyms": {},
"acceptNewFields": true,
});
let (response, _status_code) = server.get_all_settings();
assert_json_eq!(body, response, ordered: false);
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/516
#[test]
fn write_setting_and_update_partial() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
});
server.create_index(body);
// 2 - Send the settings
let body = json!({
"searchableAttributes": [
"uid",
"movie_id",
"title",
"description",
"poster",
"release_date",
"rank",
],
"displayedAttributes": [
"title",
"description",
"poster",
"release_date",
"rank",
]
});
server.update_all_settings(body.clone());
// 2 - Send the settings
let body = json!({
"rankingRules": [
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"desc(release_date)",
"desc(rank)",
],
"distinctAttribute": "movie_id",
"stopWords": [
"the",
"a",
"an",
],
"synonyms": {
"wolverine": ["xmen", "logan"],
"logan": ["wolverine"],
},
"acceptNewFields": false,
});
server.update_all_settings(body.clone());
// 2 - Send the settings
let expected = json!({
"rankingRules": [
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"desc(release_date)",
"desc(rank)",
],
"distinctAttribute": "movie_id",
"searchableAttributes": [
"uid",
"movie_id",
"title",
"description",
"poster",
"release_date",
"rank",
],
"displayedAttributes": [
"title",
"description",
"poster",
"release_date",
"rank",
],
"stopWords": [
"the",
"a",
"an",
],
"synonyms": {
"wolverine": ["xmen", "logan"],
"logan": ["wolverine"],
},
"acceptNewFields": false,
});
let (response, _status_code) = server.get_all_settings();
assert_json_eq!(expected, response, ordered: false);
}