2023-01-18 15:28:02 +01:00
use meili_snap ::* ;
2023-02-16 13:59:58 +01:00
use urlencoding ::encode ;
2023-01-18 15:28:02 +01:00
2024-07-30 10:27:57 +02:00
use crate ::common ::{
shared_does_not_exists_index , shared_empty_index , shared_index_with_documents , Server ,
} ;
2023-09-11 16:50:53 +02:00
use crate ::json ;
2023-01-18 15:28:02 +01:00
#[ actix_rt::test ]
async fn get_all_documents_bad_offset ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-01-18 15:28:02 +01:00
let ( response , code ) = index . get_all_documents_raw ( " ?offset " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `offset`: could not parse `` as a positive integer " ,
" code " : " invalid_document_offset " ,
" type " : " invalid_request " ,
2023-01-19 15:48:20 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_offset "
2023-01-18 15:28:02 +01:00
}
" ###);
let ( response , code ) = index . get_all_documents_raw ( " ?offset=doggo " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `offset`: could not parse `doggo` as a positive integer " ,
" code " : " invalid_document_offset " ,
" type " : " invalid_request " ,
2023-01-19 15:48:20 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_offset "
2023-01-18 15:28:02 +01:00
}
" ###);
let ( response , code ) = index . get_all_documents_raw ( " ?offset=-1 " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `offset`: could not parse `-1` as a positive integer " ,
" code " : " invalid_document_offset " ,
" type " : " invalid_request " ,
2023-01-19 15:48:20 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_offset "
2023-01-18 15:28:02 +01:00
}
" ###);
}
#[ actix_rt::test ]
async fn get_all_documents_bad_limit ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-01-18 15:28:02 +01:00
let ( response , code ) = index . get_all_documents_raw ( " ?limit " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `limit`: could not parse `` as a positive integer " ,
" code " : " invalid_document_limit " ,
" type " : " invalid_request " ,
2023-01-19 15:48:20 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_limit "
2023-01-18 15:28:02 +01:00
}
" ###);
let ( response , code ) = index . get_all_documents_raw ( " ?limit=doggo " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `limit`: could not parse `doggo` as a positive integer " ,
" code " : " invalid_document_limit " ,
" type " : " invalid_request " ,
2023-01-19 15:48:20 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_limit "
2023-01-18 15:28:02 +01:00
}
" ###);
let ( response , code ) = index . get_all_documents_raw ( " ?limit=-1 " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `limit`: could not parse `-1` as a positive integer " ,
" code " : " invalid_document_limit " ,
" type " : " invalid_request " ,
2023-01-19 15:48:20 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_limit "
2023-01-18 15:28:02 +01:00
}
" ###);
}
2023-05-03 19:11:53 +02:00
#[ actix_rt::test ]
async fn get_all_documents_bad_filter ( ) {
2024-07-30 10:27:57 +02:00
let index = shared_does_not_exists_index ( ) . await ;
2023-05-03 19:11:53 +02:00
let ( response , code ) = index . get_all_documents_raw ( " ?filter " ) . await ;
snapshot! ( code , @ " 404 Not Found " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
2024-07-30 10:27:57 +02:00
" message " : " Index `DOES_NOT_EXISTS` not found. " ,
2023-05-03 19:11:53 +02:00
" code " : " index_not_found " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#index_not_found "
}
" ###);
let ( response , code ) = index . get_all_documents_raw ( " ?filter=doggo " ) . await ;
snapshot! ( code , @ " 404 Not Found " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
2024-07-30 10:27:57 +02:00
" message " : " Index `DOES_NOT_EXISTS` not found. " ,
2023-05-03 19:11:53 +02:00
" code " : " index_not_found " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#index_not_found "
}
" ###);
let ( response , code ) = index . get_all_documents_raw ( " ?filter=doggo=bernese " ) . await ;
snapshot! ( code , @ " 404 Not Found " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
2024-07-30 10:27:57 +02:00
" message " : " Index `DOES_NOT_EXISTS` not found. " ,
2023-05-03 19:11:53 +02:00
" code " : " index_not_found " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#index_not_found "
}
" ###);
2024-07-30 10:27:57 +02:00
let index = shared_empty_index ( ) . await ;
2023-05-03 19:11:53 +02:00
let ( response , code ) = index . get_all_documents_raw ( " ?filter " ) . await ;
snapshot! ( code , @ " 200 OK " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" results " : [ ] ,
" offset " : 0 ,
" limit " : 20 ,
" total " : 0
}
" ###);
let ( response , code ) = index . get_all_documents_raw ( " ?filter=doggo " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
2024-09-17 16:59:22 +02:00
" message " : " Was expecting an operation `=`, `!=`, `>=`, `>`, `<=`, `<`, `IN`, `NOT IN`, `TO`, `EXISTS`, `NOT EXISTS`, `IS NULL`, `IS NOT NULL`, `IS EMPTY`, `IS NOT EMPTY`, `CONTAINS`, `NOT CONTAINS`, `STARTS WITH`, `NOT STARTS WITH`, `_geoRadius`, or `_geoBoundingBox` at `doggo`. \n 1:6 doggo " ,
2023-05-04 15:19:17 +02:00
" code " : " invalid_document_filter " ,
2023-05-03 19:11:53 +02:00
" type " : " invalid_request " ,
2023-05-04 15:19:17 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
2023-05-03 19:11:53 +02:00
}
" ###);
let ( response , code ) = index . get_all_documents_raw ( " ?filter=doggo=bernese " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Attribute `doggo` is not filterable. This index does not have configured filterable attributes. \n 1:6 doggo=bernese " ,
2023-05-16 13:56:18 +02:00
" code " : " invalid_document_filter " ,
2023-05-03 19:11:53 +02:00
" type " : " invalid_request " ,
2023-05-16 13:56:18 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
2023-05-03 19:11:53 +02:00
}
" ###);
}
2023-01-18 15:28:02 +01:00
#[ actix_rt::test ]
async fn delete_documents_batch ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-01-18 15:28:02 +01:00
let ( response , code ) = index . delete_batch_raw ( json! ( " doggo " ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Json deserialize error: invalid type: string \" doggo \" , expected a sequence at line 1 column 7 " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
2023-01-19 15:48:20 +01:00
" link " : " https://docs.meilisearch.com/errors#bad_request "
2023-01-18 15:28:02 +01:00
}
" ###);
}
2023-02-16 13:59:58 +01:00
#[ actix_rt::test ]
async fn replace_documents_missing_payload ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2024-02-22 15:51:47 +01:00
let ( response , code ) =
index . raw_add_documents ( " " , vec! [ ( " Content-Type " , " application/json " ) ] , " " ) . await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A json payload is missing. " ,
" code " : " missing_payload " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_payload "
}
" ###);
2024-02-22 15:51:47 +01:00
let ( response , code ) =
index . raw_add_documents ( " " , vec! [ ( " Content-Type " , " application/x-ndjson " ) ] , " " ) . await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A ndjson payload is missing. " ,
" code " : " missing_payload " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_payload "
}
" ###);
2024-02-22 15:51:47 +01:00
let ( response , code ) =
index . raw_add_documents ( " " , vec! [ ( " Content-Type " , " text/csv " ) ] , " " ) . await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A csv payload is missing. " ,
" code " : " missing_payload " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_payload "
}
" ###);
}
#[ actix_rt::test ]
async fn update_documents_missing_payload ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-02-16 13:59:58 +01:00
let ( response , code ) = index . raw_update_documents ( " " , Some ( " application/json " ) , " " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A json payload is missing. " ,
" code " : " missing_payload " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_payload "
}
" ###);
let ( response , code ) = index . raw_update_documents ( " " , Some ( " application/x-ndjson " ) , " " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A ndjson payload is missing. " ,
" code " : " missing_payload " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_payload "
}
" ###);
let ( response , code ) = index . raw_update_documents ( " " , Some ( " text/csv " ) , " " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A csv payload is missing. " ,
" code " : " missing_payload " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_payload "
}
" ###);
}
#[ actix_rt::test ]
async fn replace_documents_missing_content_type ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2024-02-22 15:51:47 +01:00
let ( response , code ) = index . raw_add_documents ( " " , Vec ::new ( ) , " " ) . await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A Content-Type header is missing. Accepted values for the Content-Type header are: `application/json`, `application/x-ndjson`, `text/csv` " ,
" code " : " missing_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_content_type "
}
" ###);
// even with a csv delimiter specified this error is triggered first
2024-02-22 15:51:47 +01:00
let ( response , code ) = index . raw_add_documents ( " " , Vec ::new ( ) , " ?csvDelimiter=; " ) . await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A Content-Type header is missing. Accepted values for the Content-Type header are: `application/json`, `application/x-ndjson`, `text/csv` " ,
" code " : " missing_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_content_type "
}
" ###);
}
#[ actix_rt::test ]
async fn update_documents_missing_content_type ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-02-16 13:59:58 +01:00
let ( response , code ) = index . raw_update_documents ( " " , None , " " ) . await ;
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A Content-Type header is missing. Accepted values for the Content-Type header are: `application/json`, `application/x-ndjson`, `text/csv` " ,
" code " : " missing_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_content_type "
}
" ###);
// even with a csv delimiter specified this error is triggered first
let ( response , code ) = index . raw_update_documents ( " " , None , " ?csvDelimiter=; " ) . await ;
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " A Content-Type header is missing. Accepted values for the Content-Type header are: `application/json`, `application/x-ndjson`, `text/csv` " ,
" code " : " missing_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_content_type "
}
" ###);
}
#[ actix_rt::test ]
async fn replace_documents_bad_content_type ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2024-02-22 15:51:47 +01:00
let ( response , code ) = index . raw_add_documents ( " " , vec! [ ( " Content-Type " , " doggo " ) ] , " " ) . await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " The Content-Type `doggo` is invalid. Accepted values for the Content-Type header are: `application/json`, `application/x-ndjson`, `text/csv` " ,
" code " : " invalid_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_content_type "
}
" ###);
}
#[ actix_rt::test ]
async fn update_documents_bad_content_type ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-02-16 13:59:58 +01:00
let ( response , code ) = index . raw_update_documents ( " " , Some ( " doggo " ) , " " ) . await ;
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " The Content-Type `doggo` is invalid. Accepted values for the Content-Type header are: `application/json`, `application/x-ndjson`, `text/csv` " ,
" code " : " invalid_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_content_type "
}
" ###);
}
#[ actix_rt::test ]
async fn replace_documents_bad_csv_delimiter ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2024-02-22 15:51:47 +01:00
let ( response , code ) = index
. raw_add_documents ( " " , vec! [ ( " Content-Type " , " application/json " ) ] , " ?csvDelimiter " )
. await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `csvDelimiter`: expected a string of one character, but found an empty string " ,
2023-02-22 19:26:48 +01:00
" code " : " invalid_document_csv_delimiter " ,
2023-02-16 13:59:58 +01:00
" type " : " invalid_request " ,
2023-02-22 19:26:48 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_csv_delimiter "
2023-02-16 13:59:58 +01:00
}
" ###);
2024-02-22 15:51:47 +01:00
let ( response , code ) = index
. raw_add_documents ( " " , vec! [ ( " Content-Type " , " application/json " ) ] , " ?csvDelimiter=doggo " )
. await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `csvDelimiter`: expected a string of one character, but found the following string of 5 characters: `doggo` " ,
2023-02-22 19:26:48 +01:00
" code " : " invalid_document_csv_delimiter " ,
2023-02-16 13:59:58 +01:00
" type " : " invalid_request " ,
2023-02-22 19:26:48 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_csv_delimiter "
2023-02-16 13:59:58 +01:00
}
" ###);
2023-02-16 18:00:40 +01:00
let ( response , code ) = index
2024-02-22 15:51:47 +01:00
. raw_add_documents (
" " ,
vec! [ ( " Content-Type " , " application/json " ) ] ,
& format! ( " ?csvDelimiter= {} " , encode ( " 🍰 " ) ) ,
)
2023-02-16 18:00:40 +01:00
. await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " csv delimiter must be an ascii character. Found: `🍰` " ,
2023-02-22 19:26:48 +01:00
" code " : " invalid_document_csv_delimiter " ,
2023-02-16 13:59:58 +01:00
" type " : " invalid_request " ,
2023-02-22 19:26:48 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_csv_delimiter "
2023-02-16 13:59:58 +01:00
}
" ###);
}
#[ actix_rt::test ]
async fn update_documents_bad_csv_delimiter ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-02-16 13:59:58 +01:00
let ( response , code ) =
index . raw_update_documents ( " " , Some ( " application/json " ) , " ?csvDelimiter " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `csvDelimiter`: expected a string of one character, but found an empty string " ,
2023-02-22 19:26:48 +01:00
" code " : " invalid_document_csv_delimiter " ,
2023-02-16 13:59:58 +01:00
" type " : " invalid_request " ,
2023-02-22 19:26:48 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_csv_delimiter "
2023-02-16 13:59:58 +01:00
}
" ###);
let ( response , code ) =
index . raw_update_documents ( " " , Some ( " application/json " ) , " ?csvDelimiter=doggo " ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " Invalid value in parameter `csvDelimiter`: expected a string of one character, but found the following string of 5 characters: `doggo` " ,
2023-02-22 19:26:48 +01:00
" code " : " invalid_document_csv_delimiter " ,
2023-02-16 13:59:58 +01:00
" type " : " invalid_request " ,
2023-02-22 19:26:48 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_csv_delimiter "
2023-02-16 13:59:58 +01:00
}
" ###);
2023-02-16 18:00:40 +01:00
let ( response , code ) = index
. raw_update_documents (
" " ,
Some ( " application/json " ) ,
& format! ( " ?csvDelimiter= {} " , encode ( " 🍰 " ) ) ,
)
. await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " csv delimiter must be an ascii character. Found: `🍰` " ,
2023-02-22 19:26:48 +01:00
" code " : " invalid_document_csv_delimiter " ,
2023-02-16 13:59:58 +01:00
" type " : " invalid_request " ,
2023-02-22 19:26:48 +01:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_csv_delimiter "
2023-02-16 13:59:58 +01:00
}
" ###);
}
#[ actix_rt::test ]
async fn replace_documents_csv_delimiter_with_bad_content_type ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2024-02-22 15:51:47 +01:00
let ( response , code ) = index
. raw_add_documents ( " " , vec! [ ( " Content-Type " , " application/json " ) ] , " ?csvDelimiter=a " )
. await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " The Content-Type `application/json` does not support the use of a csv delimiter. The csv delimiter can only be used with the Content-Type `text/csv`. " ,
" code " : " invalid_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_content_type "
}
" ###);
2024-02-22 15:51:47 +01:00
let ( response , code ) = index
. raw_add_documents ( " " , vec! [ ( " Content-Type " , " application/x-ndjson " ) ] , " ?csvDelimiter=a " )
. await ;
2023-02-16 13:59:58 +01:00
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " The Content-Type `application/x-ndjson` does not support the use of a csv delimiter. The csv delimiter can only be used with the Content-Type `text/csv`. " ,
" code " : " invalid_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_content_type "
}
" ###);
}
#[ actix_rt::test ]
async fn update_documents_csv_delimiter_with_bad_content_type ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-02-16 13:59:58 +01:00
let ( response , code ) =
index . raw_update_documents ( " " , Some ( " application/json " ) , " ?csvDelimiter=a " ) . await ;
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " The Content-Type `application/json` does not support the use of a csv delimiter. The csv delimiter can only be used with the Content-Type `text/csv`. " ,
" code " : " invalid_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_content_type "
}
" ###);
let ( response , code ) =
index . raw_update_documents ( " " , Some ( " application/x-ndjson " ) , " ?csvDelimiter=a " ) . await ;
snapshot! ( code , @ " 415 Unsupported Media Type " ) ;
snapshot! ( json_string! ( response ) , @ r ###"
{
" message " : " The Content-Type `application/x-ndjson` does not support the use of a csv delimiter. The csv delimiter can only be used with the Content-Type `text/csv`. " ,
" code " : " invalid_content_type " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_content_type "
}
" ###);
}
2023-04-11 19:51:17 +02:00
#[ actix_rt::test ]
async fn delete_document_by_filter ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-04-11 19:51:17 +02:00
let ( response , code ) = index . delete_document_by_filter ( json! ( " hello " ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-18 16:32:50 +02:00
snapshot! ( response , @ r ###"
2023-04-11 19:51:17 +02:00
{
2023-04-27 19:28:05 +02:00
" message " : " Invalid value type: expected an object, but found a string: ` \" hello \" ` " ,
" code " : " bad_request " ,
2023-04-11 19:51:17 +02:00
" type " : " invalid_request " ,
2023-04-27 19:28:05 +02:00
" link " : " https://docs.meilisearch.com/errors#bad_request "
2023-04-11 19:51:17 +02:00
}
" ###);
2023-05-02 17:46:04 +02:00
// send bad payload type
let ( response , code ) = index . delete_document_by_filter ( json! ( { " filter " : true } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-18 16:32:50 +02:00
snapshot! ( response , @ r ###"
2023-05-02 17:46:04 +02:00
{
" message " : " Invalid syntax for the filter parameter: `expected String, Array, found: true`. " ,
2023-05-24 11:53:16 +02:00
" code " : " invalid_document_filter " ,
2023-05-02 17:46:04 +02:00
" type " : " invalid_request " ,
2023-05-24 11:53:16 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
2023-05-02 17:46:04 +02:00
}
" ###);
2023-04-11 19:51:17 +02:00
// send bad filter
let ( response , code ) = index . delete_document_by_filter ( json! ( { " filter " : " hello " } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-18 16:32:50 +02:00
snapshot! ( response , @ r ###"
2023-04-11 19:51:17 +02:00
{
2024-09-17 16:59:22 +02:00
" message " : " Was expecting an operation `=`, `!=`, `>=`, `>`, `<=`, `<`, `IN`, `NOT IN`, `TO`, `EXISTS`, `NOT EXISTS`, `IS NULL`, `IS NOT NULL`, `IS EMPTY`, `IS NOT EMPTY`, `CONTAINS`, `NOT CONTAINS`, `STARTS WITH`, `NOT STARTS WITH`, `_geoRadius`, or `_geoBoundingBox` at `hello`. \n 1:6 hello " ,
2023-05-24 11:53:16 +02:00
" code " : " invalid_document_filter " ,
2023-05-02 17:46:04 +02:00
" type " : " invalid_request " ,
2023-05-24 11:53:16 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
2023-05-02 17:46:04 +02:00
}
" ###);
// send empty filter
let ( response , code ) = index . delete_document_by_filter ( json! ( { " filter " : " " } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-18 16:32:50 +02:00
snapshot! ( response , @ r ###"
2023-05-02 17:46:04 +02:00
{
" message " : " Sending an empty filter is forbidden. " ,
2023-05-24 11:53:16 +02:00
" code " : " invalid_document_filter " ,
2023-04-11 19:51:17 +02:00
" type " : " invalid_request " ,
2023-05-24 11:53:16 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
2023-04-11 19:51:17 +02:00
}
" ###);
2023-05-24 11:29:20 +02:00
// do not send any filter
let ( response , code ) = index . delete_document_by_filter ( json! ( { } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-18 16:32:50 +02:00
snapshot! ( response , @ r ###"
2023-05-24 11:29:20 +02:00
{
" message " : " Missing field `filter` " ,
" code " : " missing_document_filter " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#missing_document_filter "
}
" ###);
2024-07-30 10:27:57 +02:00
let index = shared_does_not_exists_index ( ) . await ;
2023-04-11 19:51:17 +02:00
// index does not exists
2024-07-30 10:27:57 +02:00
let ( response , _code ) =
index . delete_document_by_filter_fail ( json! ( { " filter " : " doggo = bernese " } ) ) . await ;
2024-07-18 16:32:50 +02:00
snapshot! ( response , @ r ###"
2023-04-11 19:51:17 +02:00
{
2024-07-18 16:32:50 +02:00
" uid " : " [uid] " ,
2024-11-13 11:27:12 +01:00
" batchUid " : " [batch_uid] " ,
2024-07-30 10:27:57 +02:00
" indexUid " : " DOES_NOT_EXISTS " ,
2023-04-11 19:51:17 +02:00
" status " : " failed " ,
" type " : " documentDeletion " ,
" canceledBy " : null ,
" details " : {
2023-05-02 22:53:16 +02:00
" providedIds " : 0 ,
2023-04-11 19:51:17 +02:00
" deletedDocuments " : 0 ,
" originalFilter " : " \" doggo = bernese \" "
} ,
" error " : {
2024-07-30 10:27:57 +02:00
" message " : " Index `DOES_NOT_EXISTS` not found. " ,
2023-04-11 19:51:17 +02:00
" code " : " index_not_found " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#index_not_found "
} ,
" duration " : " [duration] " ,
" enqueuedAt " : " [date] " ,
" startedAt " : " [date] " ,
" finishedAt " : " [date] "
}
" ###);
// no filterable are set
2024-07-30 10:27:57 +02:00
let index = shared_empty_index ( ) . await ;
let ( response , _code ) =
index . delete_document_by_filter_fail ( json! ( { " filter " : " doggo = bernese " } ) ) . await ;
2024-07-18 16:32:50 +02:00
snapshot! ( response , @ r ###"
2023-04-11 19:51:17 +02:00
{
2024-07-18 16:32:50 +02:00
" uid " : " [uid] " ,
2024-11-13 11:27:12 +01:00
" batchUid " : " [batch_uid] " ,
2024-07-30 10:27:57 +02:00
" indexUid " : " EMPTY_INDEX " ,
2023-04-11 19:51:17 +02:00
" status " : " failed " ,
" type " : " documentDeletion " ,
" canceledBy " : null ,
" details " : {
2023-05-02 22:53:16 +02:00
" providedIds " : 0 ,
2023-04-11 19:51:17 +02:00
" deletedDocuments " : 0 ,
" originalFilter " : " \" doggo = bernese \" "
} ,
" error " : {
" message " : " Attribute `doggo` is not filterable. This index does not have configured filterable attributes. \n 1:6 doggo = bernese " ,
2023-05-16 13:56:18 +02:00
" code " : " invalid_document_filter " ,
2023-04-11 19:51:17 +02:00
" type " : " invalid_request " ,
2023-05-16 13:56:18 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
2023-04-11 19:51:17 +02:00
} ,
" duration " : " [duration] " ,
" enqueuedAt " : " [date] " ,
" startedAt " : " [date] " ,
" finishedAt " : " [date] "
}
" ###);
// not filterable while there is a filterable attribute
2024-07-30 10:27:57 +02:00
let index = shared_index_with_documents ( ) . await ;
2023-04-11 19:51:17 +02:00
let ( response , code ) =
2024-07-30 10:27:57 +02:00
index . delete_document_by_filter_fail ( json! ( { " filter " : " catto = jorts " } ) ) . await ;
2023-04-11 19:51:17 +02:00
snapshot! ( code , @ " 202 Accepted " ) ;
2024-07-18 16:32:50 +02:00
let response = server . wait_task ( response . uid ( ) ) . await ;
snapshot! ( response , @ r ###"
2023-04-11 19:51:17 +02:00
{
2024-07-18 16:32:50 +02:00
" uid " : " [uid] " ,
2024-11-13 11:27:12 +01:00
" batchUid " : " [batch_uid] " ,
2024-07-30 10:27:57 +02:00
" indexUid " : " SHARED_DOCUMENTS " ,
2023-04-11 19:51:17 +02:00
" status " : " failed " ,
" type " : " documentDeletion " ,
" canceledBy " : null ,
" details " : {
2023-05-02 22:53:16 +02:00
" providedIds " : 0 ,
2023-04-11 19:51:17 +02:00
" deletedDocuments " : 0 ,
" originalFilter " : " \" catto = jorts \" "
} ,
" error " : {
2024-07-30 10:27:57 +02:00
" message " : " Attribute `catto` is not filterable. Available filterable attributes are: `id`, `title`. \n 1:6 catto = jorts " ,
2023-05-16 13:56:18 +02:00
" code " : " invalid_document_filter " ,
2023-04-11 19:51:17 +02:00
" type " : " invalid_request " ,
2023-05-16 13:56:18 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
2023-04-11 19:51:17 +02:00
} ,
" duration " : " [duration] " ,
" enqueuedAt " : " [date] " ,
" startedAt " : " [date] " ,
" finishedAt " : " [date] "
}
" ###);
}
2023-05-02 20:03:45 +02:00
#[ actix_rt::test ]
async fn fetch_document_by_filter ( ) {
2024-07-18 17:26:43 +02:00
let server = Server ::new_shared ( ) ;
2024-07-30 10:27:57 +02:00
let index = server . unique_index ( ) ;
2023-05-02 20:03:45 +02:00
index . update_settings_filterable_attributes ( json! ( [ " color " ] ) ) . await ;
2024-07-30 11:20:42 +02:00
let ( task , _code ) = index
2023-05-02 20:03:45 +02:00
. add_documents (
json! ( [
{ " id " : 0 , " color " : " red " } ,
{ " id " : 1 , " color " : " blue " } ,
{ " id " : 2 , " color " : " blue " } ,
{ " id " : 3 } ,
] ) ,
Some ( " id " ) ,
)
. await ;
2024-07-30 11:20:42 +02:00
index . wait_task ( task . uid ( ) ) . await . succeeded ( ) ;
2023-05-02 20:03:45 +02:00
let ( response , code ) = index . get_document_by_filter ( json! ( null ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2023-05-02 20:03:45 +02:00
{
" message " : " Invalid value type: expected an object, but found null " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
let ( response , code ) = index . get_document_by_filter ( json! ( { " offset " : " doggo " } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2023-05-02 20:03:45 +02:00
{
" message " : " Invalid value type at `.offset`: expected a positive integer, but found a string: ` \" doggo \" ` " ,
2023-05-04 15:19:17 +02:00
" code " : " invalid_document_offset " ,
2023-05-02 20:03:45 +02:00
" type " : " invalid_request " ,
2023-05-04 15:19:17 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_offset "
2023-05-02 20:03:45 +02:00
}
" ###);
let ( response , code ) = index . get_document_by_filter ( json! ( { " limit " : " doggo " } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2023-05-02 20:03:45 +02:00
{
" message " : " Invalid value type at `.limit`: expected a positive integer, but found a string: ` \" doggo \" ` " ,
2023-05-04 15:19:17 +02:00
" code " : " invalid_document_limit " ,
2023-05-02 20:03:45 +02:00
" type " : " invalid_request " ,
2023-05-04 15:19:17 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_limit "
2023-05-02 20:03:45 +02:00
}
" ###);
2023-05-03 20:43:57 +02:00
let ( response , code ) = index . get_document_by_filter ( json! ( { " fields " : " doggo " } ) ) . await ;
2023-05-02 20:03:45 +02:00
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2023-05-02 20:03:45 +02:00
{
2023-05-03 20:43:57 +02:00
" message " : " Invalid value type at `.fields`: expected an array, but found a string: ` \" doggo \" ` " ,
2023-05-04 15:19:17 +02:00
" code " : " invalid_document_fields " ,
2023-05-02 20:03:45 +02:00
" type " : " invalid_request " ,
2023-05-04 15:19:17 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_fields "
2023-05-02 20:03:45 +02:00
}
" ###);
let ( response , code ) = index . get_document_by_filter ( json! ( { " filter " : true } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2023-05-02 20:03:45 +02:00
{
" message " : " Invalid syntax for the filter parameter: `expected String, Array, found: true`. " ,
2023-05-04 15:19:17 +02:00
" code " : " invalid_document_filter " ,
2023-05-02 20:03:45 +02:00
" type " : " invalid_request " ,
2023-05-04 15:19:17 +02:00
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
2023-05-02 20:03:45 +02:00
}
" ###);
2023-05-16 13:56:18 +02:00
let ( response , code ) = index . get_document_by_filter ( json! ( { " filter " : " cool doggo " } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2023-05-16 13:56:18 +02:00
{
2024-09-17 16:59:22 +02:00
" message " : " Was expecting an operation `=`, `!=`, `>=`, `>`, `<=`, `<`, `IN`, `NOT IN`, `TO`, `EXISTS`, `NOT EXISTS`, `IS NULL`, `IS NOT NULL`, `IS EMPTY`, `IS NOT EMPTY`, `CONTAINS`, `NOT CONTAINS`, `STARTS WITH`, `NOT STARTS WITH`, `_geoRadius`, or `_geoBoundingBox` at `cool doggo`. \n 1:11 cool doggo " ,
2023-05-16 13:56:18 +02:00
" code " : " invalid_document_filter " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
}
" ###);
let ( response , code ) =
index . get_document_by_filter ( json! ( { " filter " : " doggo = bernese " } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2023-05-16 13:56:18 +02:00
{
" message " : " Attribute `doggo` is not filterable. Available filterable attributes are: `color`. \n 1:6 doggo = bernese " ,
" code " : " invalid_document_filter " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_document_filter "
}
" ###);
2023-05-02 20:03:45 +02:00
}
2024-06-05 23:40:29 +02:00
#[ actix_rt::test ]
async fn retrieve_vectors ( ) {
2024-07-30 11:20:42 +02:00
let index = shared_empty_index ( ) . await ;
// GET ALL DOCUMENTS BY QUERY
2024-06-05 23:40:29 +02:00
let ( response , _code ) = index . get_all_documents_raw ( " ?retrieveVectors=tamo " ) . await ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2024-06-05 23:40:29 +02:00
{
" message " : " Invalid value in parameter `retrieveVectors`: could not parse `tamo` as a boolean, expected either `true` or `false` " ,
" code " : " invalid_document_retrieve_vectors " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_document_retrieve_vectors "
}
" ###);
2024-06-10 18:26:12 +02:00
let ( response , _code ) = index . get_all_documents_raw ( " ?retrieveVectors=true " ) . await ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2024-06-10 18:26:12 +02:00
{
" message " : " Passing `retrieveVectors` as a parameter requires enabling the `vector store` experimental feature. See https://github.com/meilisearch/product/discussions/677 " ,
" code " : " feature_not_enabled " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#feature_not_enabled "
}
" ###);
// FETCH ALL DOCUMENTS BY POST
let ( response , _code ) =
index . get_document_by_filter ( json! ( { " retrieveVectors " : " tamo " } ) ) . await ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2024-06-10 18:26:12 +02:00
{
" message " : " Invalid value type at `.retrieveVectors`: expected a boolean, but found a string: ` \" tamo \" ` " ,
" code " : " invalid_document_retrieve_vectors " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_document_retrieve_vectors "
}
" ###);
let ( response , _code ) = index . get_document_by_filter ( json! ( { " retrieveVectors " : true } ) ) . await ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2024-06-10 18:26:12 +02:00
{
" message " : " Passing `retrieveVectors` as a parameter requires enabling the `vector store` experimental feature. See https://github.com/meilisearch/product/discussions/677 " ,
" code " : " feature_not_enabled " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#feature_not_enabled "
}
" ###);
// GET A SINGLE DOCUMENT
2024-06-05 23:40:29 +02:00
let ( response , _code ) = index . get_document ( 0 , Some ( json! ( { " retrieveVectors " : " tamo " } ) ) ) . await ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2024-06-05 23:40:29 +02:00
{
" message " : " Invalid value in parameter `retrieveVectors`: could not parse `tamo` as a boolean, expected either `true` or `false` " ,
" code " : " invalid_document_retrieve_vectors " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_document_retrieve_vectors "
}
" ###);
2024-06-10 18:26:12 +02:00
let ( response , _code ) = index . get_document ( 0 , Some ( json! ( { " retrieveVectors " : true } ) ) ) . await ;
2024-07-02 15:18:30 +02:00
snapshot! ( response , @ r ###"
2024-06-10 18:26:12 +02:00
{
" message " : " Passing `retrieveVectors` as a parameter requires enabling the `vector store` experimental feature. See https://github.com/meilisearch/product/discussions/677 " ,
" code " : " feature_not_enabled " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#feature_not_enabled "
}
" ###);
2024-06-05 23:40:29 +02:00
}