Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/advanced item test #98

Merged
merged 10 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ Cargo.lock
.vscode/
/**/results/
docker/query.sh

src/tests/output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
26 changes: 21 additions & 5 deletions src/model/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

// Order by stats
pub created_at_ts: String,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -146,19 +149,32 @@ pub struct AdvancedItem {
pub package_size_standard: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub related_catalogs_enabled: Option<bool>,
// More flags, just in i32
#[serde(skip_serializing_if = "Option::is_none")]
pub is_hidden: Option<i32>,
pub is_hidden: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_reserved: Option<i32>,
pub is_reserved: Option<bool>,
// More flags, just in i32
#[serde(skip_serializing_if = "Option::is_none")]
pub reserved_for_user_id: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_visible: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_visible_new: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_unisex: Option<i32>,

/*
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<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_closed_new: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_delayed_publication: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_closed: Option<i32>,
pub can_be_sold: Option<bool>,
}

impl fmt::Display for AdvancedItem {
Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 11 additions & 1 deletion src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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?;
0xCAB0 marked this conversation as resolved.
Show resolved Hide resolved
let result: Result<AdvancedItems, serde_json::Error> =
serde_json::from_str(&response_text);

if result.is_err() {
log::error!("{}", &response_text)
}

let items = result?;
Ok(items.item)
}
code => {
Expand Down
13 changes: 13 additions & 0 deletions src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,7 @@ async fn test_get_item_query_text() {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::CookiesError(_) => (),
VintedWrapperError::SerdeError(_) => (),
},
};
}
Expand All @@ -67,6 +69,7 @@ async fn test_get_item_brands() {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::CookiesError(_) => (),
VintedWrapperError::SerdeError(_) => (),
},
};
}
Expand All @@ -90,6 +93,7 @@ async fn test_get_items_brands() {
Err(err) => match err {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::SerdeError(_) => (),
VintedWrapperError::CookiesError(_) => (),
},
};
Expand Down Expand Up @@ -126,6 +130,7 @@ async fn test_get_items_catalogs_no_db() {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::CookiesError(_) => (),
VintedWrapperError::SerdeError(_) => (),
},
};
}
Expand Down Expand Up @@ -155,6 +160,7 @@ async fn test_get_items_by_price() {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::CookiesError(_) => (),
VintedWrapperError::SerdeError(_) => (),
},
};
}
Expand All @@ -178,6 +184,7 @@ async fn test_get_items_by_size_no_db() {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::CookiesError(_) => (),
VintedWrapperError::SerdeError(_) => (),
},
};
}
Expand Down Expand Up @@ -213,6 +220,7 @@ async fn test_get_items_by_size() {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::CookiesError(_) => (),
VintedWrapperError::SerdeError(_) => (),
},
};
}
Expand All @@ -236,6 +244,7 @@ async fn test_get_items_by_material() {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::CookiesError(_) => (),
VintedWrapperError::SerdeError(_) => (),
},
};
}
Expand Down Expand Up @@ -263,6 +272,7 @@ async fn test_get_items_by_color() {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::ItemError(_, _, _) => unreachable!(),
VintedWrapperError::CookiesError(_) => (),
VintedWrapperError::SerdeError(_) => (),
},
};
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -329,6 +341,7 @@ async fn test_get_advanced_items() {
}
Err(err) => match err {
VintedWrapperError::ItemNumberError => unreachable!(),
VintedWrapperError::SerdeError(_) => (),
VintedWrapperError::ItemError(_, _, _) => (),
VintedWrapperError::CookiesError(_) => (),
},
Expand Down
Loading