mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 17:11:15 +08:00
update tests for settings
This commit is contained in:
parent
559c2f8907
commit
40d7396d90
@ -18,7 +18,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
let stop_words_fst = index.main.stop_words_fst(&reader)?;
|
let stop_words_fst = index.main.stop_words_fst(&reader)?;
|
||||||
let stop_words = stop_words_fst.unwrap_or_default().stream().into_strs()?;
|
let stop_words = stop_words_fst.unwrap_or_default().stream().into_strs()?;
|
||||||
let stop_words: BTreeSet<String> = stop_words.into_iter().collect();
|
let stop_words: BTreeSet<String> = stop_words.into_iter().collect();
|
||||||
let stop_words = if stop_words.is_empty() {
|
let stop_words = if !stop_words.is_empty() {
|
||||||
Some(stop_words)
|
Some(stop_words)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -40,7 +40,7 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let synonyms = if synonyms.is_empty() {
|
let synonyms = if !synonyms.is_empty() {
|
||||||
Some(synonyms)
|
Some(synonyms)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -38,8 +38,7 @@ fn write_all_and_delete() {
|
|||||||
|
|
||||||
// 2 - Send the settings
|
// 2 - Send the settings
|
||||||
|
|
||||||
let json = json!({
|
let json = json!([
|
||||||
"rankingRules": [
|
|
||||||
"_typo",
|
"_typo",
|
||||||
"_words",
|
"_words",
|
||||||
"_proximity",
|
"_proximity",
|
||||||
@ -48,13 +47,11 @@ fn write_all_and_delete() {
|
|||||||
"_exact",
|
"_exact",
|
||||||
"dsc(release_date)",
|
"dsc(release_date)",
|
||||||
"dsc(rank)",
|
"dsc(rank)",
|
||||||
],
|
]);
|
||||||
"rankingDistinct": "movie_id",
|
|
||||||
});
|
|
||||||
|
|
||||||
let body = json.to_string().into_bytes();
|
let body = json.to_string().into_bytes();
|
||||||
|
|
||||||
let req = http::Request::post("/indexes/movies/settings/ranking")
|
let req = http::Request::post("/indexes/movies/settings/ranking-rules")
|
||||||
.body(Body::from(body))
|
.body(Body::from(body))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
@ -64,7 +61,7 @@ fn write_all_and_delete() {
|
|||||||
|
|
||||||
// 3 - Get all settings and compare to the previous one
|
// 3 - Get all settings and compare to the previous one
|
||||||
|
|
||||||
let req = http::Request::get("/indexes/movies/settings/ranking")
|
let req = http::Request::get("/indexes/movies/settings/ranking-rules")
|
||||||
.body(Body::empty())
|
.body(Body::empty())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
@ -78,7 +75,7 @@ fn write_all_and_delete() {
|
|||||||
|
|
||||||
// 4 - Delete all settings
|
// 4 - Delete all settings
|
||||||
|
|
||||||
let req = http::Request::delete("/indexes/movies/settings/ranking")
|
let req = http::Request::delete("/indexes/movies/settings/ranking-rules")
|
||||||
.body(Body::empty())
|
.body(Body::empty())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
@ -88,7 +85,7 @@ fn write_all_and_delete() {
|
|||||||
|
|
||||||
// 5 - Get all settings and check if they are empty
|
// 5 - Get all settings and check if they are empty
|
||||||
|
|
||||||
let req = http::Request::get("/indexes/movies/settings/ranking")
|
let req = http::Request::get("/indexes/movies/settings/ranking-rules")
|
||||||
.body(Body::empty())
|
.body(Body::empty())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
@ -98,10 +95,7 @@ fn write_all_and_delete() {
|
|||||||
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
||||||
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
||||||
|
|
||||||
let json = json!({
|
let json = json!(null);
|
||||||
"rankingRules": null,
|
|
||||||
"rankingDistinct": null,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_json_eq!(json, res_value, ordered: false);
|
assert_json_eq!(json, res_value, ordered: false);
|
||||||
}
|
}
|
||||||
@ -135,8 +129,7 @@ fn write_all_and_update() {
|
|||||||
|
|
||||||
// 2 - Send the settings
|
// 2 - Send the settings
|
||||||
|
|
||||||
let json = json!({
|
let json = json!([
|
||||||
"rankingRules": [
|
|
||||||
"_typo",
|
"_typo",
|
||||||
"_words",
|
"_words",
|
||||||
"_proximity",
|
"_proximity",
|
||||||
@ -145,13 +138,11 @@ fn write_all_and_update() {
|
|||||||
"_exact",
|
"_exact",
|
||||||
"dsc(release_date)",
|
"dsc(release_date)",
|
||||||
"dsc(rank)",
|
"dsc(rank)",
|
||||||
],
|
]);
|
||||||
"rankingDistinct": "movie_id",
|
|
||||||
});
|
|
||||||
|
|
||||||
let body = json.to_string().into_bytes();
|
let body = json.to_string().into_bytes();
|
||||||
|
|
||||||
let req = http::Request::post("/indexes/movies/settings/ranking")
|
let req = http::Request::post("/indexes/movies/settings/ranking-rules")
|
||||||
.body(Body::from(body))
|
.body(Body::from(body))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
@ -161,7 +152,7 @@ fn write_all_and_update() {
|
|||||||
|
|
||||||
// 3 - Get all settings and compare to the previous one
|
// 3 - Get all settings and compare to the previous one
|
||||||
|
|
||||||
let req = http::Request::get("/indexes/movies/settings/ranking")
|
let req = http::Request::get("/indexes/movies/settings/ranking-rules")
|
||||||
.body(Body::empty())
|
.body(Body::empty())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
@ -175,8 +166,7 @@ fn write_all_and_update() {
|
|||||||
|
|
||||||
// 4 - Update all settings
|
// 4 - Update all settings
|
||||||
|
|
||||||
let json_update = json!({
|
let json_update = json!([
|
||||||
"rankingRules": [
|
|
||||||
"_typo",
|
"_typo",
|
||||||
"_words",
|
"_words",
|
||||||
"_proximity",
|
"_proximity",
|
||||||
@ -184,13 +174,11 @@ fn write_all_and_update() {
|
|||||||
"_words_position",
|
"_words_position",
|
||||||
"_exact",
|
"_exact",
|
||||||
"dsc(release_date)",
|
"dsc(release_date)",
|
||||||
],
|
]);
|
||||||
"rankingDistinct": null,
|
|
||||||
});
|
|
||||||
|
|
||||||
let body_update = json_update.to_string().into_bytes();
|
let body_update = json_update.to_string().into_bytes();
|
||||||
|
|
||||||
let req = http::Request::post("/indexes/movies/settings/ranking")
|
let req = http::Request::post("/indexes/movies/settings/ranking-rules")
|
||||||
.body(Body::from(body_update))
|
.body(Body::from(body_update))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
@ -200,7 +188,7 @@ fn write_all_and_update() {
|
|||||||
|
|
||||||
// 5 - Get all settings and check if the content is the same of (4)
|
// 5 - Get all settings and check if the content is the same of (4)
|
||||||
|
|
||||||
let req = http::Request::get("/indexes/movies/settings/ranking")
|
let req = http::Request::get("/indexes/movies/settings/ranking-rules")
|
||||||
.body(Body::empty())
|
.body(Body::empty())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let res = server.simulate(req).unwrap();
|
let res = server.simulate(req).unwrap();
|
||||||
@ -210,8 +198,7 @@ fn write_all_and_update() {
|
|||||||
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
block_on(res.into_body().read_to_end(&mut buf)).unwrap();
|
||||||
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
let res_value: Value = serde_json::from_slice(&buf).unwrap();
|
||||||
|
|
||||||
let res_expected = json!({
|
let res_expected = json!([
|
||||||
"rankingRules": [
|
|
||||||
"_typo",
|
"_typo",
|
||||||
"_words",
|
"_words",
|
||||||
"_proximity",
|
"_proximity",
|
||||||
@ -219,9 +206,7 @@ fn write_all_and_update() {
|
|||||||
"_words_position",
|
"_words_position",
|
||||||
"_exact",
|
"_exact",
|
||||||
"dsc(release_date)",
|
"dsc(release_date)",
|
||||||
],
|
]);
|
||||||
"rankingDistinct": null,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_json_eq!(res_expected, res_value, ordered: false);
|
assert_json_eq!(res_expected, res_value, ordered: false);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user