Apply review suggestions

This commit is contained in:
Loïc Lecrenier 2023-01-11 14:31:34 +01:00 committed by Tamo
parent c91ffec72e
commit b0b7ad7caf
No known key found for this signature in database
GPG key ID: 20CD8020AFA88D69
12 changed files with 236 additions and 251 deletions

View file

@ -19,7 +19,7 @@ byte-unit = { version = "4.0.14", default-features = false, features = ["std", "
bytes = "1.2.1"
clap = { version = "4.0.9", features = ["derive", "env"] }
crossbeam-channel = "0.5.6"
deserr = { path = "/Users/meilisearch/Documents/deserr", features = ["serde-json"] }
deserr = { version = "0.1.4", features = ["serde-json"] }
dump = { path = "../dump" }
either = "1.8.0"
env_logger = "0.9.1"

View file

@ -3,7 +3,7 @@ use actix_web::{web, HttpRequest, HttpResponse};
use deserr::DeserializeFromValue;
use index_scheduler::IndexScheduler;
use log::debug;
use meilisearch_types::error::deserr_codes::*;
use meilisearch_types::error::{deserr_codes::*, TakeErrorMessage};
use meilisearch_types::error::{DeserrError, ResponseError};
use meilisearch_types::index_uid::IndexUid;
use meilisearch_types::milli::{self, FieldDistribution, Index};
@ -12,7 +12,9 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use time::OffsetDateTime;
use super::{ListIndexes, SummarizedTaskView};
use self::search::parse_usize_take_error_message;
use super::{Pagination, SummarizedTaskView, PAGINATION_DEFAULT_LIMIT};
use crate::analytics::Analytics;
use crate::extractors::authentication::policies::*;
use crate::extractors::authentication::{AuthenticationError, GuardedData};
@ -68,6 +70,23 @@ impl IndexView {
}
}
#[derive(DeserializeFromValue, Deserialize, Debug, Clone, Copy)]
#[deserr(error = DeserrError, rename_all = camelCase, deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ListIndexes {
#[serde(default)]
#[deserr(error = DeserrError<InvalidIndexOffset>, default, from(&String) = parse_usize_take_error_message -> TakeErrorMessage<std::num::ParseIntError>)]
pub offset: usize,
#[serde(default = "PAGINATION_DEFAULT_LIMIT")]
#[deserr(error = DeserrError<InvalidIndexLimit>, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage<std::num::ParseIntError>)]
pub limit: usize,
}
impl ListIndexes {
fn as_pagination(self) -> Pagination {
Pagination { offset: self.offset, limit: self.limit }
}
}
pub async fn list_indexes(
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_GET }>, Data<IndexScheduler>>,
paginate: QueryParameter<ListIndexes, DeserrError>,

View file

@ -16,7 +16,7 @@ use crate::routes::SummarizedTaskView;
#[macro_export]
macro_rules! make_setting_route {
($route:literal, $update_verb:ident, $type:ty, $attr:ident, $camelcase_attr:literal, $analytics_var:ident, $analytics:expr) => {
($route:literal, $update_verb:ident, $type:ty, $err_ty:ty, $attr:ident, $camelcase_attr:literal, $analytics_var:ident, $analytics:expr) => {
pub mod $attr {
use actix_web::web::Data;
use actix_web::{web, HttpRequest, HttpResponse, Resource};
@ -65,7 +65,7 @@ macro_rules! make_setting_route {
Data<IndexScheduler>,
>,
index_uid: actix_web::web::Path<String>,
body: actix_web::web::Json<Option<$type>>,
body: $crate::routes::indexes::ValidatedJson<Option<$type>, $err_ty>,
req: HttpRequest,
$analytics_var: web::Data<dyn Analytics>,
) -> std::result::Result<HttpResponse, ResponseError> {
@ -130,6 +130,9 @@ make_setting_route!(
"/filterable-attributes",
put,
std::collections::BTreeSet<String>,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsFilterableAttributes,
>,
filterable_attributes,
"filterableAttributes",
analytics,
@ -153,6 +156,9 @@ make_setting_route!(
"/sortable-attributes",
put,
std::collections::BTreeSet<String>,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsSortableAttributes,
>,
sortable_attributes,
"sortableAttributes",
analytics,
@ -176,6 +182,9 @@ make_setting_route!(
"/displayed-attributes",
put,
Vec<String>,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsDisplayedAttributes,
>,
displayed_attributes,
"displayedAttributes",
analytics,
@ -199,6 +208,9 @@ make_setting_route!(
"/typo-tolerance",
patch,
meilisearch_types::settings::TypoSettings,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsTypoTolerance,
>,
typo_tolerance,
"typoTolerance",
analytics,
@ -241,6 +253,9 @@ make_setting_route!(
"/searchable-attributes",
put,
Vec<String>,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsSearchableAttributes,
>,
searchable_attributes,
"searchableAttributes",
analytics,
@ -264,6 +279,9 @@ make_setting_route!(
"/stop-words",
put,
std::collections::BTreeSet<String>,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsStopWords,
>,
stop_words,
"stopWords",
analytics,
@ -286,6 +304,9 @@ make_setting_route!(
"/synonyms",
put,
std::collections::BTreeMap<String, Vec<String>>,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsSynonyms,
>,
synonyms,
"synonyms",
analytics,
@ -308,6 +329,9 @@ make_setting_route!(
"/distinct-attribute",
put,
String,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsDistinctAttribute,
>,
distinct_attribute,
"distinctAttribute",
analytics,
@ -329,6 +353,9 @@ make_setting_route!(
"/ranking-rules",
put,
Vec<meilisearch_types::settings::RankingRuleView>,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsRankingRules,
>,
ranking_rules,
"rankingRules",
analytics,
@ -357,6 +384,9 @@ make_setting_route!(
"/faceting",
patch,
meilisearch_types::settings::FacetingSettings,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsFaceting,
>,
faceting,
"faceting",
analytics,
@ -379,6 +409,9 @@ make_setting_route!(
"/pagination",
patch,
meilisearch_types::settings::PaginationSettings,
meilisearch_types::error::DeserrError<
meilisearch_types::error::deserr_codes::InvalidSettingsPagination,
>,
pagination,
"pagination",
analytics,

View file

@ -1,13 +1,15 @@
use std::collections::BTreeMap;
use std::str::FromStr;
use self::indexes::IndexStats;
use crate::analytics::Analytics;
use crate::extractors::authentication::policies::*;
use crate::extractors::authentication::GuardedData;
use actix_web::web::Data;
use actix_web::{web, HttpRequest, HttpResponse};
use deserr::DeserializeFromValue;
use index_scheduler::{IndexScheduler, Query};
use log::debug;
use meilisearch_types::error::deserr_codes::*;
use meilisearch_types::error::{DeserrError, ResponseError, TakeErrorMessage};
use meilisearch_types::error::{ResponseError, TakeErrorMessage};
use meilisearch_types::settings::{Settings, Unchecked};
use meilisearch_types::star_or::StarOr;
use meilisearch_types::tasks::{Kind, Status, Task, TaskId};
@ -15,12 +17,6 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use time::OffsetDateTime;
use self::indexes::search::parse_usize_take_error_message;
use self::indexes::IndexStats;
use crate::analytics::Analytics;
use crate::extractors::authentication::policies::*;
use crate::extractors::authentication::GuardedData;
mod api_key;
mod dump;
pub mod indexes;
@ -98,23 +94,6 @@ pub struct Pagination {
pub limit: usize,
}
#[derive(DeserializeFromValue, Deserialize, Debug, Clone, Copy)]
#[deserr(error = DeserrError, rename_all = camelCase, deny_unknown_fields)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ListIndexes {
#[serde(default)]
#[deserr(error = DeserrError<InvalidIndexOffset>, default, from(&String) = parse_usize_take_error_message -> TakeErrorMessage<std::num::ParseIntError>)]
pub offset: usize,
#[serde(default = "PAGINATION_DEFAULT_LIMIT")]
#[deserr(error = DeserrError<InvalidIndexLimit>, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage<std::num::ParseIntError>)]
pub limit: usize,
}
impl ListIndexes {
fn as_pagination(self) -> Pagination {
Pagination { offset: self.offset, limit: self.limit }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct PaginationView<T> {
pub results: Vec<T>,

View file

@ -33,8 +33,8 @@ async fn add_valid_api_key() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"201 Created");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"name": "indexing-key",
"description": "Indexing API key",
@ -92,8 +92,8 @@ async fn add_valid_api_key_expired_at() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"201 Created");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -136,8 +136,8 @@ async fn add_valid_api_key_no_description() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"201 Created");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": null,
@ -169,8 +169,8 @@ async fn add_valid_api_key_null_description() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"201 Created");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": null,
@ -199,8 +199,8 @@ async fn error_add_api_key_no_header() {
"expiresAt": "2050-11-13T00:00:00Z"
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"401 Unauthorized");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
@ -222,8 +222,8 @@ async fn error_add_api_key_bad_key() {
"expiresAt": "2050-11-13T00:00:00Z"
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"403");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"403 Forbidden");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The provided API key is invalid.",
"code": "invalid_api_key",
@ -245,8 +245,8 @@ async fn error_add_api_key_missing_parameter() {
"expiresAt": "2050-11-13T00:00:00Z"
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Json deserialize error: missing field `indexes` at ``",
"code": "bad_request",
@ -262,8 +262,8 @@ async fn error_add_api_key_missing_parameter() {
"expiresAt": "2050-11-13T00:00:00Z"
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Json deserialize error: missing field `actions` at ``",
"code": "bad_request",
@ -279,8 +279,8 @@ async fn error_add_api_key_missing_parameter() {
"actions": ["documents.add"],
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"201 Created");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -311,8 +311,8 @@ async fn error_add_api_key_invalid_parameters_description() {
"expiresAt": "2050-11-13T00:00:00Z"
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "invalid type: Map `{\"name\":\"products\"}`, expected a String at `.description`.",
"code": "invalid_api_key_description",
@ -334,8 +334,8 @@ async fn error_add_api_key_invalid_parameters_name() {
"expiresAt": "2050-11-13T00:00:00Z"
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "invalid type: Map `{\"name\":\"products\"}`, expected a String at `.name`.",
"code": "invalid_api_key_name",
@ -357,8 +357,8 @@ async fn error_add_api_key_invalid_parameters_indexes() {
"expiresAt": "2050-11-13T00:00:00Z"
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "invalid type: Map `{\"name\":\"products\"}`, expected a Sequence at `.indexes`.",
"code": "invalid_api_key_indexes",
@ -383,8 +383,8 @@ async fn error_add_api_key_invalid_index_uids() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "`invalid index # / \\name with spaces` is not a valid index uid. Index uid can be an integer or a string containing only alphanumeric characters, hyphens (-) and underscores (_). at `.indexes[0]`.",
"code": "invalid_api_key_indexes",
@ -408,8 +408,8 @@ async fn error_add_api_key_invalid_parameters_actions() {
let (response, code) = server.add_api_key(content).await;
assert_eq!(400, code, "{:?}", &response);
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "invalid type: Map `{\"name\":\"products\"}`, expected a Sequence at `.actions`.",
"code": "invalid_api_key_actions",
@ -428,8 +428,8 @@ async fn error_add_api_key_invalid_parameters_actions() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Json deserialize error: unknown value `doc.add`, expected one of `*`, `search`, `documents.*`, `documents.add`, `documents.get`, `documents.delete`, `indexes.*`, `indexes.create`, `indexes.get`, `indexes.update`, `indexes.delete`, `indexes.swap`, `tasks.*`, `tasks.cancel`, `tasks.delete`, `tasks.get`, `settings.*`, `settings.get`, `settings.update`, `stats.*`, `stats.get`, `metrics.*`, `metrics.get`, `dumps.*`, `dumps.create`, `version`, `keys.create`, `keys.get`, `keys.update`, `keys.delete` at `.actions[0]`.",
"code": "invalid_api_key_actions",
@ -452,8 +452,8 @@ async fn error_add_api_key_invalid_parameters_expires_at() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "invalid type: Map `{\"name\":\"products\"}`, expected a String at `.expiresAt`.",
"code": "invalid_api_key_expires_at",
@ -476,7 +476,7 @@ async fn error_add_api_key_invalid_parameters_expires_at_in_the_past() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "`2010-11-13T00:00:00Z` is not a valid date. It should follow the RFC 3339 format to represents a date or datetime in the future or specified as a null value. e.g. 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'.\n at `.expiresAt`.",
"code": "invalid_api_key_expires_at",
@ -484,7 +484,7 @@ async fn error_add_api_key_invalid_parameters_expires_at_in_the_past() {
"link": "https://docs.meilisearch.com/errors#invalid-api-key-expires-at"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::snapshot!(code, @"400 Bad Request");
}
#[actix_rt::test]
@ -501,7 +501,7 @@ async fn error_add_api_key_invalid_parameters_uid() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "invalid length: expected length 32 for simple format, found 13 at `.uid`.",
"code": "invalid_api_key_uid",
@ -509,7 +509,7 @@ async fn error_add_api_key_invalid_parameters_uid() {
"link": "https://docs.meilisearch.com/errors#invalid-api-key-uid"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::snapshot!(code, @"400 Bad Request");
}
#[actix_rt::test]
@ -525,7 +525,7 @@ async fn error_add_api_key_parameters_uid_already_exist() {
// first creation is valid.
let (response, code) = server.add_api_key(content.clone()).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"name": null,
"description": null,
@ -542,11 +542,11 @@ async fn error_add_api_key_parameters_uid_already_exist() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
// uid already exist.
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "`uid` field value `4bc0887a-0e41-4f3b-935d-0c451dcee9c8` is already an existing API key.",
"code": "api_key_already_exists",
@ -554,7 +554,7 @@ async fn error_add_api_key_parameters_uid_already_exist() {
"link": "https://docs.meilisearch.com/errors#api-key-already-exists"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"409");
meili_snap::snapshot!(code, @"409 Conflict");
}
#[actix_rt::test]
@ -586,7 +586,7 @@ async fn get_api_key() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -615,13 +615,13 @@ async fn get_api_key() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let key = response["key"].as_str().unwrap();
// get with uid
let (response, code) = server.get_api_key(&uid).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -650,10 +650,10 @@ async fn get_api_key() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
// get with key
let (response, code) = server.get_api_key(&key).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -682,7 +682,7 @@ async fn get_api_key() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
}
#[actix_rt::test]
@ -692,7 +692,7 @@ async fn error_get_api_key_no_header() {
let (response, code) = server
.get_api_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
@ -700,7 +700,7 @@ async fn error_get_api_key_no_header() {
"link": "https://docs.meilisearch.com/errors#missing-authorization-header"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
}
#[actix_rt::test]
@ -711,7 +711,7 @@ async fn error_get_api_key_bad_key() {
let (response, code) = server
.get_api_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The provided API key is invalid.",
"code": "invalid_api_key",
@ -719,7 +719,7 @@ async fn error_get_api_key_bad_key() {
"link": "https://docs.meilisearch.com/errors#invalid-api-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"403");
meili_snap::snapshot!(code, @"403 Forbidden");
}
#[actix_rt::test]
@ -730,7 +730,7 @@ async fn error_get_api_key_not_found() {
let (response, code) = server
.get_api_key("d0552b41d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "API key `d0552b41d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4` not found.",
"code": "api_key_not_found",
@ -738,7 +738,7 @@ async fn error_get_api_key_not_found() {
"link": "https://docs.meilisearch.com/errors#api-key-not-found"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"404");
meili_snap::snapshot!(code, @"404 Not Found");
}
#[actix_rt::test]
@ -768,7 +768,7 @@ async fn list_api_keys() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -797,10 +797,10 @@ async fn list_api_keys() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let (response, code) = server.list_api_keys().await;
meili_snap::insta::assert_json_snapshot!(response, { ".results[].createdAt" => "[ignored]", ".results[].updatedAt" => "[ignored]", ".results[].uid" => "[ignored]", ".results[].key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".results[].createdAt" => "[ignored]", ".results[].updatedAt" => "[ignored]", ".results[].uid" => "[ignored]", ".results[].key" => "[ignored]" }), @r###"
{
"results": [
{
@ -866,7 +866,7 @@ async fn list_api_keys() {
"total": 3
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
}
#[actix_rt::test]
@ -874,7 +874,7 @@ async fn error_list_api_keys_no_header() {
let server = Server::new_auth().await;
let (response, code) = server.list_api_keys().await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
@ -882,7 +882,7 @@ async fn error_list_api_keys_no_header() {
"link": "https://docs.meilisearch.com/errors#missing-authorization-header"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
}
#[actix_rt::test]
@ -891,7 +891,7 @@ async fn error_list_api_keys_bad_key() {
server.use_api_key("d4000bd7225f77d1eb22cc706ed36772bbc36767c016a27f76def7537b68600d");
let (response, code) = server.list_api_keys().await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The provided API key is invalid.",
"code": "invalid_api_key",
@ -899,7 +899,7 @@ async fn error_list_api_keys_bad_key() {
"link": "https://docs.meilisearch.com/errors#invalid-api-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"403");
meili_snap::snapshot!(code, @"403 Forbidden");
}
#[actix_rt::test]
@ -929,7 +929,7 @@ async fn delete_api_key() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -958,17 +958,17 @@ async fn delete_api_key() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let uid = response["uid"].as_str().unwrap();
let (response, code) = server.delete_api_key(&uid).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @"null");
meili_snap::insta::assert_debug_snapshot!(code, @"204");
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @"null");
meili_snap::snapshot!(code, @"204 No Content");
// check if API key no longer exist.
let (response, code) = server.get_api_key(&uid).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".message" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".message" => "[ignored]" }), @r###"
{
"message": "[ignored]",
"code": "api_key_not_found",
@ -976,7 +976,7 @@ async fn delete_api_key() {
"link": "https://docs.meilisearch.com/errors#api-key-not-found"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"404");
meili_snap::snapshot!(code, @"404 Not Found");
}
#[actix_rt::test]
@ -987,7 +987,7 @@ async fn error_delete_api_key_no_header() {
.delete_api_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
@ -995,7 +995,7 @@ async fn error_delete_api_key_no_header() {
"link": "https://docs.meilisearch.com/errors#missing-authorization-header"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
}
#[actix_rt::test]
@ -1006,7 +1006,7 @@ async fn error_delete_api_key_bad_key() {
let (response, code) = server
.delete_api_key("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The provided API key is invalid.",
"code": "invalid_api_key",
@ -1014,7 +1014,7 @@ async fn error_delete_api_key_bad_key() {
"link": "https://docs.meilisearch.com/errors#invalid-api-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"403");
meili_snap::snapshot!(code, @"403 Forbidden");
}
#[actix_rt::test]
@ -1025,7 +1025,7 @@ async fn error_delete_api_key_not_found() {
let (response, code) = server
.delete_api_key("d0552b41d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4")
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "API key `d0552b41d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4` not found.",
"code": "api_key_not_found",
@ -1033,7 +1033,7 @@ async fn error_delete_api_key_not_found() {
"link": "https://docs.meilisearch.com/errors#api-key-not-found"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"404");
meili_snap::snapshot!(code, @"404 Not Found");
}
#[actix_rt::test]
@ -1059,7 +1059,7 @@ async fn patch_api_key_description() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": null,
@ -1085,7 +1085,7 @@ async fn patch_api_key_description() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let uid = response["uid"].as_str().unwrap();
@ -1094,7 +1094,7 @@ async fn patch_api_key_description() {
thread::sleep(time::Duration::new(1, 0));
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -1120,13 +1120,13 @@ async fn patch_api_key_description() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
// Change the description
let content = json!({ "description": "Product API key" });
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Product API key",
@ -1152,13 +1152,13 @@ async fn patch_api_key_description() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
// Remove the description
let content = json!({ "description": serde_json::Value::Null });
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": null,
@ -1184,7 +1184,7 @@ async fn patch_api_key_description() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
}
#[actix_rt::test]
@ -1210,7 +1210,7 @@ async fn patch_api_key_name() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": null,
@ -1236,7 +1236,7 @@ async fn patch_api_key_name() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let uid = response["uid"].as_str().unwrap();
let created_at = response["createdAt"].as_str().unwrap();
@ -1247,7 +1247,7 @@ async fn patch_api_key_name() {
thread::sleep(time::Duration::new(1, 0));
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": "Indexing API key",
"description": null,
@ -1273,7 +1273,7 @@ async fn patch_api_key_name() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
assert_ne!(response["updatedAt"].as_str().unwrap(), updated_at);
assert_eq!(response["createdAt"].as_str().unwrap(), created_at);
@ -1282,7 +1282,7 @@ async fn patch_api_key_name() {
let content = json!({ "name": "Product API key" });
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": "Product API key",
"description": null,
@ -1308,13 +1308,13 @@ async fn patch_api_key_name() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
// Remove the name
let content = json!({ "name": serde_json::Value::Null });
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": null,
@ -1340,7 +1340,7 @@ async fn patch_api_key_name() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"200");
meili_snap::snapshot!(code, @"200 OK");
}
#[actix_rt::test]
@ -1367,7 +1367,7 @@ async fn error_patch_api_key_indexes() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -1393,7 +1393,7 @@ async fn error_patch_api_key_indexes() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let uid = response["uid"].as_str().unwrap();
@ -1401,7 +1401,7 @@ async fn error_patch_api_key_indexes() {
thread::sleep(time::Duration::new(1, 0));
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Json deserialize error: unknown field `indexes`, expected one of `description`, `name` at ``.",
"code": "immutable_field",
@ -1409,7 +1409,7 @@ async fn error_patch_api_key_indexes() {
"link": "https://docs.meilisearch.com/errors#immutable-field"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::snapshot!(code, @"400 Bad Request");
}
#[actix_rt::test]
@ -1436,7 +1436,7 @@ async fn error_patch_api_key_actions() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -1462,7 +1462,7 @@ async fn error_patch_api_key_actions() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let uid = response["uid"].as_str().unwrap();
@ -1478,7 +1478,7 @@ async fn error_patch_api_key_actions() {
thread::sleep(time::Duration::new(1, 0));
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Json deserialize error: unknown field `actions`, expected one of `description`, `name` at ``.",
"code": "immutable_field",
@ -1486,7 +1486,7 @@ async fn error_patch_api_key_actions() {
"link": "https://docs.meilisearch.com/errors#immutable-field"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::snapshot!(code, @"400 Bad Request");
}
#[actix_rt::test]
@ -1513,7 +1513,7 @@ async fn error_patch_api_key_expiration_date() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -1539,7 +1539,7 @@ async fn error_patch_api_key_expiration_date() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let uid = response["uid"].as_str().unwrap();
@ -1547,7 +1547,7 @@ async fn error_patch_api_key_expiration_date() {
thread::sleep(time::Duration::new(1, 0));
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Json deserialize error: unknown field `expiresAt`, expected one of `description`, `name` at ``.",
"code": "immutable_field",
@ -1555,7 +1555,7 @@ async fn error_patch_api_key_expiration_date() {
"link": "https://docs.meilisearch.com/errors#immutable-field"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::snapshot!(code, @"400 Bad Request");
}
#[actix_rt::test]
@ -1569,7 +1569,7 @@ async fn error_patch_api_key_no_header() {
)
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
@ -1577,7 +1577,7 @@ async fn error_patch_api_key_no_header() {
"link": "https://docs.meilisearch.com/errors#missing-authorization-header"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
}
#[actix_rt::test]
@ -1592,7 +1592,7 @@ async fn error_patch_api_key_bad_key() {
)
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "The provided API key is invalid.",
"code": "invalid_api_key",
@ -1600,7 +1600,7 @@ async fn error_patch_api_key_bad_key() {
"link": "https://docs.meilisearch.com/errors#invalid-api-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"403");
meili_snap::snapshot!(code, @"403 Forbidden");
}
#[actix_rt::test]
@ -1615,7 +1615,7 @@ async fn error_patch_api_key_not_found() {
)
.await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "API key `d0552b41d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4` not found.",
"code": "api_key_not_found",
@ -1623,7 +1623,7 @@ async fn error_patch_api_key_not_found() {
"link": "https://docs.meilisearch.com/errors#api-key-not-found"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"404");
meili_snap::snapshot!(code, @"404 Not Found");
}
#[actix_rt::test]
@ -1641,7 +1641,7 @@ async fn error_patch_api_key_indexes_invalid_parameters() {
});
let (response, code) = server.add_api_key(content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
{
"name": null,
"description": "Indexing API key",
@ -1658,7 +1658,7 @@ async fn error_patch_api_key_indexes_invalid_parameters() {
"updatedAt": "[ignored]"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"201");
meili_snap::snapshot!(code, @"201 Created");
let uid = response["uid"].as_str().unwrap();
@ -1668,7 +1668,7 @@ async fn error_patch_api_key_indexes_invalid_parameters() {
});
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "invalid type: Integer `13`, expected a String at `.description`.",
"code": "invalid_api_key_description",
@ -1676,7 +1676,7 @@ async fn error_patch_api_key_indexes_invalid_parameters() {
"link": "https://docs.meilisearch.com/errors#invalid-api-key-description"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::snapshot!(code, @"400 Bad Request");
// invalid name
let content = json!({
@ -1684,7 +1684,7 @@ async fn error_patch_api_key_indexes_invalid_parameters() {
});
let (response, code) = server.patch_api_key(&uid, content).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "invalid type: Integer `13`, expected a String at `.name`.",
"code": "invalid_api_key_name",
@ -1692,7 +1692,7 @@ async fn error_patch_api_key_indexes_invalid_parameters() {
"link": "https://docs.meilisearch.com/errors#invalid-api-key-name"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::snapshot!(code, @"400 Bad Request");
}
#[actix_rt::test]
@ -1700,7 +1700,7 @@ async fn error_access_api_key_routes_no_master_key_set() {
let mut server = Server::new().await;
let (response, code) = server.add_api_key(json!({})).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.",
"code": "missing_master_key",
@ -1708,10 +1708,10 @@ async fn error_access_api_key_routes_no_master_key_set() {
"link": "https://docs.meilisearch.com/errors#missing-master-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
let (response, code) = server.patch_api_key("content", json!({})).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.",
"code": "missing_master_key",
@ -1719,10 +1719,10 @@ async fn error_access_api_key_routes_no_master_key_set() {
"link": "https://docs.meilisearch.com/errors#missing-master-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
let (response, code) = server.get_api_key("content").await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.",
"code": "missing_master_key",
@ -1730,10 +1730,10 @@ async fn error_access_api_key_routes_no_master_key_set() {
"link": "https://docs.meilisearch.com/errors#missing-master-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
let (response, code) = server.list_api_keys().await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.",
"code": "missing_master_key",
@ -1741,12 +1741,12 @@ async fn error_access_api_key_routes_no_master_key_set() {
"link": "https://docs.meilisearch.com/errors#missing-master-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
server.use_api_key("MASTER_KEY");
let (response, code) = server.add_api_key(json!({})).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.",
"code": "missing_master_key",
@ -1754,10 +1754,10 @@ async fn error_access_api_key_routes_no_master_key_set() {
"link": "https://docs.meilisearch.com/errors#missing-master-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
let (response, code) = server.patch_api_key("content", json!({})).await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.",
"code": "missing_master_key",
@ -1765,10 +1765,10 @@ async fn error_access_api_key_routes_no_master_key_set() {
"link": "https://docs.meilisearch.com/errors#missing-master-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
let (response, code) = server.get_api_key("content").await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.",
"code": "missing_master_key",
@ -1776,10 +1776,10 @@ async fn error_access_api_key_routes_no_master_key_set() {
"link": "https://docs.meilisearch.com/errors#missing-master-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
let (response, code) = server.list_api_keys().await;
meili_snap::insta::assert_json_snapshot!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###"
{
"message": "Meilisearch is running without a master key. To access this API endpoint, you must have set a master key at launch.",
"code": "missing_master_key",
@ -1787,5 +1787,5 @@ async fn error_access_api_key_routes_no_master_key_set() {
"link": "https://docs.meilisearch.com/errors#missing-master-key"
}
"###);
meili_snap::insta::assert_debug_snapshot!(code, @"401");
meili_snap::snapshot!(code, @"401 Unauthorized");
}

View file

@ -179,15 +179,15 @@ async fn error_update_setting_unexisting_index_invalid_uid() {
let server = Server::new().await;
let index = server.index("test##! ");
let (response, code) = index.update_settings(json!({})).await;
assert_eq!(code, 400);
let expected = json!({
"message": "`test##! ` is not a valid index uid. Index uid can be an integer or a string containing only alphanumeric characters, hyphens (-) and underscores (_).",
"code": "invalid_index_uid",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-index-uid"});
assert_eq!(response, expected);
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "`test##! ` is not a valid index uid. Index uid can be an integer or a string containing only alphanumeric characters, hyphens (-) and underscores (_).",
"code": "invalid_index_uid",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-index-uid"
}
"###);
}
macro_rules! test_setting_routes {
@ -279,8 +279,8 @@ async fn error_set_invalid_ranking_rules() {
index.create(None).await;
let (response, code) = index.update_settings(json!({ "rankingRules": [ "manyTheFish"]})).await;
meili_snap::insta::assert_debug_snapshot!(code, @"400");
meili_snap::insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "`manyTheFish` ranking rule is invalid. Valid ranking rules are words, typo, sort, proximity, attribute, exactness and custom ranking rules. at `.rankingRules[0]`.",
"code": "invalid_settings_ranking_rules",

View file

@ -1,4 +1,4 @@
use meili_snap::insta::{self, assert_debug_snapshot, assert_json_snapshot};
use meili_snap::insta::assert_json_snapshot;
use serde_json::json;
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;
@ -179,7 +179,7 @@ async fn get_task_filter_error() {
let (response, code) = server.tasks_filter(json!( { "lol": "pied" })).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Query deserialize error: unknown field `lol`",
"code": "bad_request",
@ -190,7 +190,7 @@ async fn get_task_filter_error() {
let (response, code) = server.tasks_filter(json!( { "uids": "pied" })).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Task uid `pied` is invalid. It should only contain numeric characters.",
"code": "invalid_task_uids",
@ -201,7 +201,7 @@ async fn get_task_filter_error() {
let (response, code) = server.tasks_filter(json!( { "from": "pied" })).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Query deserialize error: invalid digit found in string",
"code": "bad_request",
@ -212,7 +212,7 @@ async fn get_task_filter_error() {
let (response, code) = server.tasks_filter(json!( { "beforeStartedAt": "pied" })).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Task `beforeStartedAt` `pied` is invalid. It should follow the YYYY-MM-DD or RFC 3339 date-time format.",
"code": "invalid_task_before_started_at",
@ -228,7 +228,7 @@ async fn delete_task_filter_error() {
let (response, code) = server.delete_tasks(json!(null)).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Query parameters to filter the tasks to delete are missing. Available query parameters are: `uids`, `indexUids`, `statuses`, `types`, `beforeEnqueuedAt`, `afterEnqueuedAt`, `beforeStartedAt`, `afterStartedAt`, `beforeFinishedAt`, `afterFinishedAt`.",
"code": "missing_task_filters",
@ -239,7 +239,7 @@ async fn delete_task_filter_error() {
let (response, code) = server.delete_tasks(json!({ "lol": "pied" })).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Query deserialize error: unknown field `lol`",
"code": "bad_request",
@ -250,7 +250,7 @@ async fn delete_task_filter_error() {
let (response, code) = server.delete_tasks(json!({ "uids": "pied" })).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Task uid `pied` is invalid. It should only contain numeric characters.",
"code": "invalid_task_uids",
@ -266,7 +266,7 @@ async fn cancel_task_filter_error() {
let (response, code) = server.cancel_tasks(json!(null)).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Query parameters to filter the tasks to cancel are missing. Available query parameters are: `uids`, `indexUids`, `statuses`, `types`, `beforeEnqueuedAt`, `afterEnqueuedAt`, `beforeStartedAt`, `afterStartedAt`, `beforeFinishedAt`, `afterFinishedAt`.",
"code": "missing_task_filters",
@ -277,7 +277,7 @@ async fn cancel_task_filter_error() {
let (response, code) = server.cancel_tasks(json!({ "lol": "pied" })).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Query deserialize error: unknown field `lol`",
"code": "bad_request",
@ -288,7 +288,7 @@ async fn cancel_task_filter_error() {
let (response, code) = server.cancel_tasks(json!({ "uids": "pied" })).await;
assert_eq!(code, 400, "{}", response);
insta::assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "Task uid `pied` is invalid. It should only contain numeric characters.",
"code": "invalid_task_uids",
@ -518,8 +518,8 @@ async fn test_summarized_settings_update() {
let index = server.index("test");
// here we should find my payload even in the failed task.
let (response, code) = index.update_settings(json!({ "rankingRules": ["custom"] })).await;
assert_debug_snapshot!(code, @"400");
assert_json_snapshot!(response, @r###"
meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{
"message": "`custom` ranking rule is invalid. Valid ranking rules are words, typo, sort, proximity, attribute, exactness and custom ranking rules. at `.rankingRules[0]`.",
"code": "invalid_settings_ranking_rules",