diff --git a/.gitignore b/.gitignore index ca7bac7..53b9c8c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ Cargo.lock .vscode/ /**/results/ docker/query.sh + +src/tests/output \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index dc1e36d..a00e801 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ serde_json = { version = "1.0.91" } log = "0.4.20" lazy_static = "1.4.0" [dev-dependencies] +env_logger = "0.11.5" redis-macros = { version = "0.3.0" } redis = { version = "0.24.0" } diff --git a/src/model/item.rs b/src/model/item.rs index c501a3c..36abf20 100644 --- a/src/model/item.rs +++ b/src/model/item.rs @@ -115,6 +115,9 @@ pub struct AdvancedItem { /// Current valid price of the item pub price_numeric: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub service_fee: Option, + // Order by stats pub created_at_ts: String, #[serde(skip_serializing_if = "Option::is_none")] @@ -146,19 +149,32 @@ pub struct AdvancedItem { pub package_size_standard: Option, #[serde(skip_serializing_if = "Option::is_none")] pub related_catalogs_enabled: Option, - // More flags, just in i32 #[serde(skip_serializing_if = "Option::is_none")] - pub is_hidden: Option, + pub is_hidden: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub is_reserved: Option, + pub is_reserved: Option, + // More flags, just in i32 #[serde(skip_serializing_if = "Option::is_none")] pub reserved_for_user_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub is_visible: Option, #[serde(skip_serializing_if = "Option::is_none")] + pub is_visible_new: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub is_unisex: Option, + + /* + WARN:Leaving is_closed commented, since its type [i32, bool] + is not stable and could cause issues + */ + // #[serde(skip_serializing_if = "Option::is_none")] + // pub is_closed: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub is_closed_new: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub is_delayed_publication: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub is_closed: Option, + pub can_be_sold: Option, } impl fmt::Display for AdvancedItem { @@ -225,7 +241,7 @@ impl fmt::Display for AdvancedItem { writeln!(f, " is_reserved: {}", display_option(self.is_reserved))?; writeln!(f, " is_visible: {}", display_option(self.is_visible))?; writeln!(f, " is_unisex: {}", display_option(self.is_unisex))?; - writeln!(f, " is_closed: {}", display_option(self.is_closed))?; + // writeln!(f, " is_closed: {}", display_option(self.is_closed))?; writeln!(f, "}}\n")?; for (num, photo) in self.photos.iter().enumerate() { diff --git a/src/queries.rs b/src/queries.rs index c7051ed..43f635f 100644 --- a/src/queries.rs +++ b/src/queries.rs @@ -61,6 +61,8 @@ pub enum CookieError { #[derive(Error, Debug)] pub enum VintedWrapperError { + #[error(transparent)] + SerdeError(#[from] serde_json::Error), #[error(transparent)] CookiesError(#[from] CookieError), #[error("Number of items must be non-zero value")] @@ -756,7 +758,15 @@ impl<'a> VintedWrapper<'a> { match json.status() { StatusCode::OK => { - let items: AdvancedItems = json.json().await?; + let response_text = json.text().await?; + let result: Result = + serde_json::from_str(&response_text); + + if result.is_err() { + log::error!("{}", &response_text) + } + + let items = result?; Ok(items.item) } code => { diff --git a/src/tests/queries.rs b/src/tests/queries.rs index b806efa..cd59f9a 100644 --- a/src/tests/queries.rs +++ b/src/tests/queries.rs @@ -3,6 +3,7 @@ use crate::model::filter::{Currency, Filter}; use crate::queries::VintedWrapperError; use crate::VintedWrapper; use bb8_postgres::tokio_postgres::NoTls; +use env_logger; const DB_URL: &str = "postgres://postgres:postgres@localhost/vinted-rs"; const POOL_SIZE: u32 = 5; @@ -44,6 +45,7 @@ async fn test_get_item_query_text() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } @@ -67,6 +69,7 @@ async fn test_get_item_brands() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } @@ -90,6 +93,7 @@ async fn test_get_items_brands() { Err(err) => match err { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), + VintedWrapperError::SerdeError(_) => (), VintedWrapperError::CookiesError(_) => (), }, }; @@ -126,6 +130,7 @@ async fn test_get_items_catalogs_no_db() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } @@ -155,6 +160,7 @@ async fn test_get_items_by_price() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } @@ -178,6 +184,7 @@ async fn test_get_items_by_size_no_db() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } @@ -213,6 +220,7 @@ async fn test_get_items_by_size() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } @@ -236,6 +244,7 @@ async fn test_get_items_by_material() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } @@ -263,6 +272,7 @@ async fn test_get_items_by_color() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } @@ -292,12 +302,14 @@ async fn test_get_items_by_currency() { VintedWrapperError::ItemNumberError => unreachable!(), VintedWrapperError::ItemError(_, _, _) => unreachable!(), VintedWrapperError::CookiesError(_) => (), + VintedWrapperError::SerdeError(_) => (), }, }; } #[tokio::test] async fn test_get_advanced_items() { + env_logger::builder().is_test(true).init(); let db = DbController::new("postgres://postgres:postgres@localhost/vinted-rs", 5, NoTls) .await .unwrap(); @@ -329,6 +341,7 @@ async fn test_get_advanced_items() { } Err(err) => match err { VintedWrapperError::ItemNumberError => unreachable!(), + VintedWrapperError::SerdeError(_) => (), VintedWrapperError::ItemError(_, _, _) => (), VintedWrapperError::CookiesError(_) => (), },