Reverse assert comparison to have a consistent error message

This commit is contained in:
ManyTheFish 2023-06-20 16:57:50 +02:00
parent 114f878205
commit dc391deca0

View File

@ -41,7 +41,7 @@ async fn simple_search_on_title() {
.search( .search(
json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"]}), json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"]}),
|response, code| { |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 2); assert_eq!(response["hits"].as_array().unwrap().len(), 2);
}, },
) )
@ -56,7 +56,7 @@ async fn simple_prefix_search_on_title() {
// simple search should return 2 documents (ids: 2 and 3). // simple search should return 2 documents (ids: 2 and 3).
index index
.search(json!({"q": "Captain Mar", "attributesToSearchOn": ["title"]}), |response, code| { .search(json!({"q": "Captain Mar", "attributesToSearchOn": ["title"]}), |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 2); assert_eq!(response["hits"].as_array().unwrap().len(), 2);
}) })
.await; .await;
@ -69,7 +69,7 @@ async fn simple_search_on_title_matching_strategy_all() {
// simple search matching strategy all should only return 1 document (ids: 2). // simple search matching strategy all should only return 1 document (ids: 2).
index index
.search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "matchingStrategy": "all"}), |response, code| { .search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "matchingStrategy": "all"}), |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 1); assert_eq!(response["hits"].as_array().unwrap().len(), 1);
}) })
.await; .await;
@ -84,7 +84,7 @@ async fn simple_search_on_unknown_field() {
.search( .search(
json!({"q": "Captain Marvel", "attributesToSearchOn": ["unknown"]}), json!({"q": "Captain Marvel", "attributesToSearchOn": ["unknown"]}),
|response, code| { |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 0); assert_eq!(response["hits"].as_array().unwrap().len(), 0);
}, },
) )
@ -98,7 +98,7 @@ async fn simple_search_on_no_field() {
// simple search on no field shouldn't return any document. // simple search on no field shouldn't return any document.
index index
.search(json!({"q": "Captain Marvel", "attributesToSearchOn": []}), |response, code| { .search(json!({"q": "Captain Marvel", "attributesToSearchOn": []}), |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!(response["hits"].as_array().unwrap().len(), 0); assert_eq!(response["hits"].as_array().unwrap().len(), 0);
}) })
.await; .await;
@ -114,7 +114,7 @@ async fn word_ranking_rule_order() {
.search( .search(
json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}), json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}),
|response, code| { |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!( assert_eq!(
response["hits"], response["hits"],
json!([ json!([
@ -139,7 +139,7 @@ async fn word_ranking_rule_order_exact_words() {
.search( .search(
json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}), json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}),
|response, code| { |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!( assert_eq!(
response["hits"], response["hits"],
json!([ json!([
@ -174,7 +174,7 @@ async fn typo_ranking_rule_order() {
// Document 2 should appear before document 1. // Document 2 should appear before document 1.
index index
.search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}), |response, code| { .search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["title"], "attributesToRetrieve": ["id"]}), |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!( assert_eq!(
response["hits"], response["hits"],
json!([ json!([
@ -210,7 +210,7 @@ async fn attributes_ranking_rule_order() {
// Document 2 should appear before document 1. // Document 2 should appear before document 1.
index index
.search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["desc", "footer"], "attributesToRetrieve": ["id"]}), |response, code| { .search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["desc", "footer"], "attributesToRetrieve": ["id"]}), |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!( assert_eq!(
response["hits"], response["hits"],
json!([ json!([
@ -244,7 +244,7 @@ async fn exactness_ranking_rule_order() {
// Document 2 should appear before document 1. // Document 2 should appear before document 1.
index index
.search(json!({"q": "Captain Marvel", "attributesToRetrieve": ["id"], "attributesToSearchOn": ["desc"]}), |response, code| { .search(json!({"q": "Captain Marvel", "attributesToRetrieve": ["id"], "attributesToSearchOn": ["desc"]}), |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(200, code, "{}", response);
assert_eq!( assert_eq!(
response["hits"], response["hits"],
json!([ json!([