2557: add more tests on the formatted route r=Kerollmops a=irevoire

We had a bunch of tests trying to send array of array in a get request, this is actually not supported thus I updated the tests to only send a single array or a direct string.

Also, the real tests that ensure the array of array are well handled are in milli so I don’t think we should lose time trying to « improve » our test surface on this point.

Co-authored-by: Irevoire <tamo@meilisearch.com>
This commit is contained in:
bors[bot] 2022-06-28 13:41:53 +00:00 committed by GitHub
commit 8a64ee0c14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 341 additions and 272 deletions

4
Cargo.lock generated
View File

@ -3986,9 +3986,9 @@ checksum = "b6d12cb7a57bbf2ab670ed9545bae3648048547f9039279a89ce000208e585c1"
[[package]] [[package]]
name = "yaup" name = "yaup"
version = "0.1.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f8e1d3d18db742c8b9ad2f5f3c5bf5b63aa67b9933617c8f8350d39a3c173c6" checksum = "3bc9ef6963f7e857050aabf31ebc44184f278bcfec4c3671552c1a916b152b45"
dependencies = [ dependencies = [
"serde", "serde",
"url", "url",

View File

@ -84,7 +84,7 @@ assert-json-diff = "2.0.1"
manifest-dir-macros = "0.1.14" manifest-dir-macros = "0.1.14"
maplit = "1.0.2" maplit = "1.0.2"
urlencoding = "2.1.0" urlencoding = "2.1.0"
yaup = "0.1.0" yaup = "0.2.0"
[features] [features]
default = ["analytics", "mini-dashboard"] default = ["analytics", "mini-dashboard"]

View File

@ -107,7 +107,7 @@ async fn filter_invalid_syntax_array() {
"link": "https://docs.meilisearch.com/errors#invalid_filter" "link": "https://docs.meilisearch.com/errors#invalid_filter"
}); });
index index
.search(json!({"filter": [["title & Glass"]]}), |response, code| { .search(json!({"filter": ["title & Glass"]}), |response, code| {
assert_eq!(response, expected_response); assert_eq!(response, expected_response);
assert_eq!(code, 400); assert_eq!(code, 400);
}) })
@ -164,7 +164,7 @@ async fn filter_invalid_attribute_array() {
"link": "https://docs.meilisearch.com/errors#invalid_filter" "link": "https://docs.meilisearch.com/errors#invalid_filter"
}); });
index index
.search(json!({"filter": [["many = Glass"]]}), |response, code| { .search(json!({"filter": ["many = Glass"]}), |response, code| {
assert_eq!(response, expected_response); assert_eq!(response, expected_response);
assert_eq!(code, 400); assert_eq!(code, 400);
}) })
@ -218,7 +218,7 @@ async fn filter_reserved_geo_attribute_array() {
"link": "https://docs.meilisearch.com/errors#invalid_filter" "link": "https://docs.meilisearch.com/errors#invalid_filter"
}); });
index index
.search(json!({"filter": [["_geo = Glass"]]}), |response, code| { .search(json!({"filter": ["_geo = Glass"]}), |response, code| {
assert_eq!(response, expected_response); assert_eq!(response, expected_response);
assert_eq!(code, 400); assert_eq!(code, 400);
}) })
@ -273,7 +273,7 @@ async fn filter_reserved_attribute_array() {
}); });
index index
.search( .search(
json!({"filter": [["_geoDistance = Glass"]]}), json!({"filter": ["_geoDistance = Glass"]}),
|response, code| { |response, code| {
assert_eq!(response, expected_response); assert_eq!(response, expected_response);
assert_eq!(code, 400); assert_eq!(code, 400);

View File

@ -33,9 +33,10 @@ async fn formatted_contain_wildcard() {
) )
.await; .await;
let (response, code) = index index
.search_post(json!({ "q": "pesti", "attributesToRetrieve": ["*"] })) .search(
.await; json!({ "q": "pesti", "attributesToRetrieve": ["*"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -44,12 +45,14 @@ async fn formatted_contain_wildcard() {
"cattos": "pesti", "cattos": "pesti",
}) })
); );
},
let (response, code) = index
.search_post(
json!({ "q": "pesti", "attributesToRetrieve": ["*"], "attributesToHighlight": ["id"], "showMatchesPosition": true }),
) )
.await; .await;
index
.search(
json!({ "q": "pesti", "attributesToRetrieve": ["*"], "attributesToHighlight": ["id"], "showMatchesPosition": true }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -63,28 +66,14 @@ async fn formatted_contain_wildcard() {
"_matchesPosition": {"cattos": [{"start": 0, "length": 5}]}, "_matchesPosition": {"cattos": [{"start": 0, "length": 5}]},
}) })
); );
}
let (response, code) = index
.search_post(
json!({ "q": "pesti", "attributesToRetrieve": ["*"], "attributesToCrop": ["*"] }),
) )
.await; .await;
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
"cattos": "pesti",
"_formatted": {
"id": "852",
"cattos": "pesti",
}
})
);
let (response, code) = index index
.search_post(json!({ "q": "pesti", "attributesToCrop": ["*"] })) .search(
.await; json!({ "q": "pesti", "attributesToRetrieve": ["*"], "attributesToCrop": ["*"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -97,6 +86,29 @@ async fn formatted_contain_wildcard() {
} }
}) })
); );
},
)
.await;
index
.search(
json!({ "q": "pesti", "attributesToCrop": ["*"] }),
|response, code| {
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
"cattos": "pesti",
"_formatted": {
"id": "852",
"cattos": "pesti",
}
})
);
},
)
.await;
} }
#[actix_rt::test] #[actix_rt::test]
@ -108,9 +120,10 @@ async fn format_nested() {
index.add_documents(documents, None).await; index.add_documents(documents, None).await;
index.wait_task(0).await; index.wait_task(0).await;
let (response, code) = index index
.search_post(json!({ "q": "pesti", "attributesToRetrieve": ["doggos"] })) .search(
.await; json!({ "q": "pesti", "attributesToRetrieve": ["doggos"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -127,10 +140,14 @@ async fn format_nested() {
], ],
}) })
); );
},
let (response, code) = index )
.search_post(json!({ "q": "pesti", "attributesToRetrieve": ["doggos.name"] }))
.await; .await;
index
.search(
json!({ "q": "pesti", "attributesToRetrieve": ["doggos.name"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -145,12 +162,14 @@ async fn format_nested() {
], ],
}) })
); );
},
let (response, code) = index
.search_post(
json!({ "q": "bobby", "attributesToRetrieve": ["doggos.name"], "showMatchesPosition": true }),
) )
.await; .await;
index
.search(
json!({ "q": "bobby", "attributesToRetrieve": ["doggos.name"], "showMatchesPosition": true }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -166,10 +185,13 @@ async fn format_nested() {
"_matchesPosition": {"doggos.name": [{"start": 0, "length": 5}]}, "_matchesPosition": {"doggos.name": [{"start": 0, "length": 5}]},
}) })
); );
}
let (response, code) = index )
.search_post(json!({ "q": "pesti", "attributesToRetrieve": [], "attributesToHighlight": ["doggos.name"] }))
.await; .await;
index
.search(json!({ "q": "pesti", "attributesToRetrieve": [], "attributesToHighlight": ["doggos.name"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -186,10 +208,12 @@ async fn format_nested() {
}, },
}) })
); );
})
let (response, code) = index
.search_post(json!({ "q": "pesti", "attributesToRetrieve": [], "attributesToCrop": ["doggos.name"] }))
.await; .await;
index
.search(json!({ "q": "pesti", "attributesToRetrieve": [], "attributesToCrop": ["doggos.name"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -206,10 +230,12 @@ async fn format_nested() {
}, },
}) })
); );
})
let (response, code) = index
.search_post(json!({ "q": "pesti", "attributesToRetrieve": ["doggos.name"], "attributesToHighlight": ["doggos.age"] }))
.await; .await;
index
.search(json!({ "q": "pesti", "attributesToRetrieve": ["doggos.name"], "attributesToHighlight": ["doggos.age"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -236,10 +262,12 @@ async fn format_nested() {
}, },
}) })
); );
})
let (response, code) = index
.search_post(json!({ "q": "pesti", "attributesToRetrieve": [], "attributesToHighlight": ["doggos.age"], "attributesToCrop": ["doggos.name"] }))
.await; .await;
index
.search(json!({ "q": "pesti", "attributesToRetrieve": [], "attributesToHighlight": ["doggos.age"], "attributesToCrop": ["doggos.name"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -259,6 +287,9 @@ async fn format_nested() {
}) })
); );
} }
)
.await;
}
#[actix_rt::test] #[actix_rt::test]
async fn displayedattr_2_smol() { async fn displayedattr_2_smol() {
@ -274,9 +305,9 @@ async fn displayedattr_2_smol() {
index.add_documents(documents, None).await; index.add_documents(documents, None).await;
index.wait_task(1).await; index.wait_task(1).await;
let (response, code) = index index
.search_post(json!({ "attributesToRetrieve": ["father", "id"], "attributesToHighlight": ["mother"], "attributesToCrop": ["cattos"] })) .search(json!({ "attributesToRetrieve": ["father", "id"], "attributesToHighlight": ["mother"], "attributesToCrop": ["cattos"] }),
.await; |response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -284,10 +315,13 @@ async fn displayedattr_2_smol() {
"id": 852, "id": 852,
}) })
); );
})
let (response, code) = index
.search_post(json!({ "attributesToRetrieve": ["id"] }))
.await; .await;
index
.search(
json!({ "attributesToRetrieve": ["id"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -295,101 +329,116 @@ async fn displayedattr_2_smol() {
"id": 852, "id": 852,
}) })
); );
},
let (response, code) = index
.search_post(json!({ "attributesToHighlight": ["id"] }))
.await;
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
"_formatted": {
"id": "852",
}
})
);
let (response, code) = index
.search_post(json!({ "attributesToCrop": ["id"] }))
.await;
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
"_formatted": {
"id": "852",
}
})
);
let (response, code) = index
.search_post(json!({ "attributesToHighlight": ["id"], "attributesToCrop": ["id"] }))
.await;
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
"_formatted": {
"id": "852",
}
})
);
let (response, code) = index
.search_post(json!({ "attributesToHighlight": ["cattos"] }))
.await;
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
})
);
let (response, code) = index
.search_post(json!({ "attributesToCrop": ["cattos"] }))
.await;
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
})
);
let (response, code) = index
.search_post(json!({ "attributesToRetrieve": ["cattos"] }))
.await;
assert_eq!(code, 200, "{}", response);
assert_eq!(response["hits"][0], json!({}));
let (response, code) = index
.search_post(
json!({ "attributesToRetrieve": ["cattos"], "attributesToHighlight": ["cattos"], "attributesToCrop": ["cattos"] }),
) )
.await; .await;
index
.search(
json!({ "attributesToHighlight": ["id"] }),
|response, code| {
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
"_formatted": {
"id": "852",
}
})
);
},
)
.await;
index
.search(json!({ "attributesToCrop": ["id"] }), |response, code| {
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
"_formatted": {
"id": "852",
}
})
);
})
.await;
index
.search(
json!({ "attributesToHighlight": ["id"], "attributesToCrop": ["id"] }),
|response, code| {
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
"_formatted": {
"id": "852",
}
})
);
},
)
.await;
index
.search(
json!({ "attributesToHighlight": ["cattos"] }),
|response, code| {
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
})
);
},
)
.await;
index
.search(
json!({ "attributesToCrop": ["cattos"] }),
|response, code| {
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"id": 852,
})
);
},
)
.await;
index
.search(
json!({ "attributesToRetrieve": ["cattos"] }),
|response, code| {
assert_eq!(code, 200, "{}", response);
assert_eq!(response["hits"][0], json!({}));
},
)
.await;
index
.search(
json!({ "attributesToRetrieve": ["cattos"], "attributesToHighlight": ["cattos"], "attributesToCrop": ["cattos"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!(response["hits"][0], json!({})); assert_eq!(response["hits"][0], json!({}));
let (response, code) = index
.search_post(json!({ "attributesToRetrieve": ["cattos"], "attributesToHighlight": ["id"] }))
.await;
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"_formatted": {
"id": "852",
} }
}) )
); .await;
let (response, code) = index index
.search_post(json!({ "attributesToRetrieve": ["cattos"], "attributesToCrop": ["id"] })) .search(
.await; json!({ "attributesToRetrieve": ["cattos"], "attributesToHighlight": ["id"] }),
|response, code| {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!( assert_eq!(
response["hits"][0], response["hits"][0],
@ -399,4 +448,24 @@ async fn displayedattr_2_smol() {
} }
}) })
); );
},
)
.await;
index
.search(
json!({ "attributesToRetrieve": ["cattos"], "attributesToCrop": ["id"] }),
|response, code| {
assert_eq!(code, 200, "{}", response);
assert_eq!(
response["hits"][0],
json!({
"_formatted": {
"id": "852",
}
})
);
},
)
.await;
} }