From b0b7ad7caff484c1105e04278f70ef9fe0f11727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 11 Jan 2023 14:31:34 +0100 Subject: [PATCH] Apply review suggestions --- Cargo.lock | 45 ++-- meilisearch-auth/src/lib.rs | 3 +- meilisearch-types/Cargo.toml | 2 +- meilisearch-types/src/error.rs | 4 +- meilisearch-types/src/keys.rs | 36 +-- meilisearch/Cargo.toml | 2 +- meilisearch/src/routes/indexes/mod.rs | 23 +- meilisearch/src/routes/indexes/settings.rs | 37 ++- meilisearch/src/routes/mod.rs | 31 +-- meilisearch/tests/auth/api_keys.rs | 256 ++++++++++----------- meilisearch/tests/settings/get_settings.rs | 22 +- meilisearch/tests/tasks/mod.rs | 26 +-- 12 files changed, 236 insertions(+), 251 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5f0293cb..a35ff82a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1022,36 +1022,17 @@ dependencies = [ "syn 1.0.107", ] -[[package]] -name = "deserr" -version = "0.1.2" -dependencies = [ - "deserr-internal 0.1.2", - "serde-cs", - "serde_json", -] - [[package]] name = "deserr" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86290491a2b5c21a1a5083da8dae831006761258fabd5617309c3eebc5f89468" dependencies = [ - "deserr-internal 0.1.4", + "deserr-internal", "serde-cs", "serde_json", ] -[[package]] -name = "deserr-internal" -version = "0.1.2" -dependencies = [ - "convert_case 0.5.0", - "proc-macro2 1.0.49", - "quote 1.0.23", - "syn 1.0.107", -] - [[package]] name = "deserr-internal" version = "0.1.4" @@ -2326,7 +2307,7 @@ dependencies = [ "cargo_toml", "clap 4.0.32", "crossbeam-channel", - "deserr 0.1.2", + "deserr", "dump", "either", "env_logger", @@ -2418,7 +2399,7 @@ dependencies = [ "anyhow", "convert_case 0.6.0", "csv", - "deserr 0.1.2", + "deserr", "either", "enum-iterator", "file-store", @@ -2478,7 +2459,7 @@ dependencies = [ "concat-arrays", "crossbeam-channel", "csv", - "deserr 0.1.4", + "deserr", "either", "filter-parser", "flatten-serde-json", @@ -2793,9 +2774,9 @@ dependencies = [ [[package]] name = "pest" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" +checksum = "4257b4a04d91f7e9e6290be5d3da4804dd5784fafde3a497d73eb2b4a158c30a" dependencies = [ "thiserror", "ucd-trie", @@ -2803,9 +2784,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603" +checksum = "241cda393b0cdd65e62e07e12454f1f25d57017dcc514b1514cd3c4645e3a0a6" dependencies = [ "pest", "pest_generator", @@ -2813,9 +2794,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" +checksum = "46b53634d8c8196302953c74d5352f33d0c512a9499bd2ce468fc9f4128fa27c" dependencies = [ "pest", "pest_meta", @@ -2826,13 +2807,13 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" +checksum = "0ef4f1332a8d4678b41966bb4cc1d0676880e84183a1ecc3f4b69f03e99c7a51" dependencies = [ "once_cell", "pest", - "sha1", + "sha2", ] [[package]] diff --git a/meilisearch-auth/src/lib.rs b/meilisearch-auth/src/lib.rs index aae71f55f..8d4a7f2b7 100644 --- a/meilisearch-auth/src/lib.rs +++ b/meilisearch-auth/src/lib.rs @@ -33,8 +33,7 @@ impl AuthController { Ok(Self { store: Arc::new(store), master_key: master_key.clone() }) } - pub fn create_key(&self, value: CreateApiKey) -> Result { - let create_key = value; + pub fn create_key(&self, create_key: CreateApiKey) -> Result { match self.store.get_api_key(create_key.uid)? { Some(_) => Err(AuthControllerError::ApiKeyAlreadyExists(create_key.uid.to_string())), None => self.store.put_api_key(create_key.to_key()), diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index 7cb123daa..f7e935c10 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -9,7 +9,7 @@ actix-web = { version = "4.2.1", default-features = false } anyhow = "1.0.65" convert_case = "0.6.0" csv = "1.1.6" -deserr = { path = "/Users/meilisearch/Documents/deserr", features = ["serde-json"] } +deserr = { version = "0.1.4", features = ["serde-json"] } either = { version = "1.6.1", features = ["serde"] } enum-iterator = "1.1.3" file-store = { path = "../file-store" } diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index 436857b90..b4a8b786e 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -118,7 +118,6 @@ impl fmt::Display for ErrorType { macro_rules! make_error_codes { ($($code_ident:ident, $err_type:ident, $status:ident);*) => { - #[repr(u32)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Code { $($code_ident),* @@ -210,7 +209,6 @@ InvalidIndexOffset , invalid , BAD_REQUEST ; InvalidIndexPrimaryKey , invalid , BAD_REQUEST ; InvalidIndexUid , invalid , BAD_REQUEST ; InvalidMinWordLengthForTypo , invalid , BAD_REQUEST ; -InvalidRankingRule , invalid , BAD_REQUEST ; InvalidSearchAttributesToCrop , invalid , BAD_REQUEST ; InvalidSearchAttributesToHighlight , invalid , BAD_REQUEST ; InvalidSearchAttributesToRetrieve , invalid , BAD_REQUEST ; @@ -340,7 +338,7 @@ impl ErrorCode for milli::Error { UserError::SortRankingRuleMissing => Code::InvalidSearchSort, UserError::InvalidFacetsDistribution { .. } => Code::BadRequest, UserError::InvalidSortableAttribute { .. } => Code::InvalidSearchSort, - UserError::CriterionError(_) => Code::InvalidRankingRule, + UserError::CriterionError(_) => Code::InvalidSettingsRankingRules, UserError::InvalidGeoField { .. } => Code::InvalidDocumentGeoField, UserError::SortError(_) => Code::InvalidSearchSort, UserError::InvalidMinTypoWordLenSetting(_, _) => { diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index 9b11c3317..00d1a33eb 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -2,7 +2,7 @@ use std::convert::Infallible; use std::fmt::Display; use std::hash::Hash; -use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValueKind, ValuePointerRef}; +use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValuePointerRef}; use enum_iterator::Sequence; use serde::{Deserialize, Serialize}; use time::format_description::well_known::Rfc3339; @@ -17,31 +17,6 @@ use crate::star_or::StarOr; pub type KeyId = Uuid; -impl DeserializeFromValue> for Uuid { - fn deserialize_from_value( - value: deserr::Value, - location: deserr::ValuePointerRef, - ) -> std::result::Result> { - match value { - deserr::Value::String(s) => match Uuid::parse_str(&s) { - Ok(x) => Ok(x), - Err(e) => Err(unwrap_any(DeserrError::::error::( - None, - deserr::ErrorKind::Unexpected { msg: e.to_string() }, - location, - ))), - }, - _ => Err(unwrap_any(DeserrError::::error( - None, - deserr::ErrorKind::IncorrectValueKind { - actual: value, - accepted: &[ValueKind::String], - }, - location, - ))), - } - } -} impl MergeWithError for DeserrError { fn merge( _self_: Option, @@ -56,6 +31,10 @@ impl MergeWithError for DeserrError } } +fn parse_uuid_from_str(s: &str) -> Result> { + Uuid::parse_str(s).map_err(TakeErrorMessage) +} + #[derive(Debug, DeserializeFromValue)] #[deserr(error = DeserrError, rename_all = camelCase, deny_unknown_fields)] pub struct CreateApiKey { @@ -63,12 +42,9 @@ pub struct CreateApiKey { pub description: Option, #[deserr(error = DeserrError)] pub name: Option, - #[deserr(default = Uuid::new_v4(), error = DeserrError)] + #[deserr(default = Uuid::new_v4(), error = DeserrError, from(&String) = parse_uuid_from_str -> TakeErrorMessage)] pub uid: KeyId, - // Value at `.name` is invalid. It is a dictionary, but is expected to be an array of strings containing action names. - // Value `indeex.create` at `.name[1]` is invalid. It is expected to be one of: .... #[deserr(error = DeserrError)] - //, expected = "an array of string containing action names.")] pub actions: Vec, #[deserr(error = DeserrError)] pub indexes: Vec>, diff --git a/meilisearch/Cargo.toml b/meilisearch/Cargo.toml index 1d1f21677..4ed1843db 100644 --- a/meilisearch/Cargo.toml +++ b/meilisearch/Cargo.toml @@ -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" diff --git a/meilisearch/src/routes/indexes/mod.rs b/meilisearch/src/routes/indexes/mod.rs index c6f39bce6..03289e62e 100644 --- a/meilisearch/src/routes/indexes/mod.rs +++ b/meilisearch/src/routes/indexes/mod.rs @@ -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, default, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] + pub offset: usize, + #[serde(default = "PAGINATION_DEFAULT_LIMIT")] + #[deserr(error = DeserrError, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] + 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, Data>, paginate: QueryParameter, diff --git a/meilisearch/src/routes/indexes/settings.rs b/meilisearch/src/routes/indexes/settings.rs index c64eefd9c..13c280d63 100644 --- a/meilisearch/src/routes/indexes/settings.rs +++ b/meilisearch/src/routes/indexes/settings.rs @@ -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, >, index_uid: actix_web::web::Path, - body: actix_web::web::Json>, + body: $crate::routes::indexes::ValidatedJson, $err_ty>, req: HttpRequest, $analytics_var: web::Data, ) -> std::result::Result { @@ -130,6 +130,9 @@ make_setting_route!( "/filterable-attributes", put, std::collections::BTreeSet, + 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, + 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, + 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, + 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, + 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>, + 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::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, diff --git a/meilisearch/src/routes/mod.rs b/meilisearch/src/routes/mod.rs index f271467ba..28d3e997e 100644 --- a/meilisearch/src/routes/mod.rs +++ b/meilisearch/src/routes/mod.rs @@ -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, default, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] - pub offset: usize, - #[serde(default = "PAGINATION_DEFAULT_LIMIT")] - #[deserr(error = DeserrError, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] - pub limit: usize, -} -impl ListIndexes { - fn as_pagination(self) -> Pagination { - Pagination { offset: self.offset, limit: self.limit } - } -} - #[derive(Debug, Clone, Serialize)] pub struct PaginationView { pub results: Vec, diff --git a/meilisearch/tests/auth/api_keys.rs b/meilisearch/tests/auth/api_keys.rs index 7b49c65b9..485d1b551 100644 --- a/meilisearch/tests/auth/api_keys.rs +++ b/meilisearch/tests/auth/api_keys.rs @@ -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"); } diff --git a/meilisearch/tests/settings/get_settings.rs b/meilisearch/tests/settings/get_settings.rs index 1146fc013..3ac7d3801 100644 --- a/meilisearch/tests/settings/get_settings.rs +++ b/meilisearch/tests/settings/get_settings.rs @@ -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", diff --git a/meilisearch/tests/tasks/mod.rs b/meilisearch/tests/tasks/mod.rs index 9516770fa..a47c1ad9a 100644 --- a/meilisearch/tests/tasks/mod.rs +++ b/meilisearch/tests/tasks/mod.rs @@ -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",