cargo clippy
This commit is contained in:
@@ -187,7 +187,7 @@ async fn show_listing_details(
|
|||||||
target: impl Into<MessageTarget>,
|
target: impl Into<MessageTarget>,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let response = format!(
|
let response = format!(
|
||||||
"🔍 <b>Viewing Listing Details</b>\n\n\
|
"🔍 <b>Listing Details</b>\n\n\
|
||||||
<b>Title:</b> {}\n\
|
<b>Title:</b> {}\n\
|
||||||
<b>Description:</b> {}\n",
|
<b>Description:</b> {}\n",
|
||||||
listing.base.title,
|
listing.base.title,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ fn test_complete_field_processing_workflow() {
|
|||||||
|
|
||||||
for (field, input) in workflow {
|
for (field, input) in workflow {
|
||||||
let result = process_field_update(field, &mut draft, input);
|
let result = process_field_update(field, &mut draft, input);
|
||||||
assert!(result.is_ok(), "Processing {:?} should succeed", field);
|
assert!(result.is_ok(), "Processing {field:?} should succeed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify realistic final state
|
// Verify realistic final state
|
||||||
@@ -130,8 +130,7 @@ fn test_natural_language_duration_conversion() {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
fields.end_delay,
|
fields.end_delay,
|
||||||
ListingDuration::hours(expected_hours),
|
ListingDuration::hours(expected_hours),
|
||||||
"Business duration '{}' should convert correctly",
|
"Business duration '{input}' should convert correctly"
|
||||||
input
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,14 +43,11 @@ pub async fn display_listing_summary(
|
|||||||
.unwrap_or("<i>No description</i>")
|
.unwrap_or("<i>No description</i>")
|
||||||
));
|
));
|
||||||
|
|
||||||
match &draft.fields {
|
if let ListingFields::FixedPriceListing(fields) = &draft.fields {
|
||||||
ListingFields::FixedPriceListing(fields) => {
|
response_lines.push(format!(
|
||||||
response_lines.push(format!(
|
"💰 <b>Buy it Now Price:</b> ${}",
|
||||||
"💰 <b>Buy it Now Price:</b> ${}",
|
fields.buy_now_price
|
||||||
fields.buy_now_price
|
));
|
||||||
));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match &draft.persisted {
|
match &draft.persisted {
|
||||||
@@ -73,7 +70,7 @@ pub async fn display_listing_summary(
|
|||||||
response_lines.push("".to_string());
|
response_lines.push("".to_string());
|
||||||
response_lines.push("Please review your listing and choose an action:".to_string());
|
response_lines.push("Please review your listing and choose an action:".to_string());
|
||||||
|
|
||||||
send_message(&bot, target, response_lines.join("\n"), keyboard).await?;
|
send_message(bot, target, response_lines.join("\n"), keyboard).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use std::iter::repeat;
|
|
||||||
|
|
||||||
use sqlx::{prelude::*, query::Query, sqlite::SqliteArguments, Encode, Sqlite};
|
use sqlx::{prelude::*, query::Query, sqlite::SqliteArguments, Encode, Sqlite};
|
||||||
|
|
||||||
@@ -16,15 +15,11 @@ where
|
|||||||
Box::new(move |query| query.bind(value))
|
Box::new(move |query| query.bind(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct BindFields {
|
pub struct BindFields {
|
||||||
binds: Vec<(&'static str, BindFn)>,
|
binds: Vec<(&'static str, BindFn)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BindFields {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self { binds: vec![] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BindFields {
|
impl BindFields {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
@@ -59,6 +54,6 @@ impl BindFields {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_placeholders(&self) -> impl Iterator<Item = &'static str> + '_ {
|
pub fn bind_placeholders(&self) -> impl Iterator<Item = &'static str> + '_ {
|
||||||
repeat("?").take(self.binds.len())
|
std::iter::repeat_n("?", self.binds.len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ impl UserDAO {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let user = FromRow::from_row(&row)?;
|
let user = FromRow::from_row(&row)?;
|
||||||
log::info!("load user from db: {:?}", user);
|
log::info!("load user from db: {user:?}");
|
||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ mod tests {
|
|||||||
assert_eq!(inserted_user.telegram_id, 12345.into());
|
assert_eq!(inserted_user.telegram_id, 12345.into());
|
||||||
assert_eq!(inserted_user.username, Some("testuser".to_string()));
|
assert_eq!(inserted_user.username, Some("testuser".to_string()));
|
||||||
assert_eq!(inserted_user.first_name, "Test User".to_string());
|
assert_eq!(inserted_user.first_name, "Test User".to_string());
|
||||||
assert_eq!(inserted_user.is_banned, false);
|
assert!(!inserted_user.is_banned);
|
||||||
|
|
||||||
// Find by ID
|
// Find by ID
|
||||||
let found_user = UserDAO::find_by_id(&pool, inserted_user.persisted.id)
|
let found_user = UserDAO::find_by_id(&pool, inserted_user.persisted.id)
|
||||||
@@ -323,7 +323,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(updated_user.username, Some("newname".to_string()));
|
assert_eq!(updated_user.username, Some("newname".to_string()));
|
||||||
assert_eq!(updated_user.first_name, "New Name".to_string());
|
assert_eq!(updated_user.first_name, "New Name".to_string());
|
||||||
assert_eq!(updated_user.is_banned, true);
|
assert!(updated_user.is_banned);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ mod tests {
|
|||||||
|
|
||||||
// Insert test data
|
// Insert test data
|
||||||
sqlx::query("INSERT INTO test_money (amount, currency) VALUES (?, ?)")
|
sqlx::query("INSERT INTO test_money (amount, currency) VALUES (?, ?)")
|
||||||
.bind(&amount)
|
.bind(amount)
|
||||||
.bind(CurrencyType::Usd)
|
.bind(CurrencyType::Usd)
|
||||||
.execute(&pool)
|
.execute(&pool)
|
||||||
.await
|
.await
|
||||||
@@ -245,7 +245,7 @@ mod tests {
|
|||||||
sqlx::query("INSERT INTO test_money (amount, currency, optional_amount) VALUES (?, ?, ?)")
|
sqlx::query("INSERT INTO test_money (amount, currency, optional_amount) VALUES (?, ?, ?)")
|
||||||
.bind(MoneyAmount::from_str("100.00").unwrap())
|
.bind(MoneyAmount::from_str("100.00").unwrap())
|
||||||
.bind(CurrencyType::Usd)
|
.bind(CurrencyType::Usd)
|
||||||
.bind(&optional_amount)
|
.bind(optional_amount)
|
||||||
.execute(&pool)
|
.execute(&pool)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to insert some optional amount");
|
.expect("Failed to insert some optional amount");
|
||||||
@@ -290,7 +290,7 @@ mod tests {
|
|||||||
|
|
||||||
// Insert into database
|
// Insert into database
|
||||||
sqlx::query("INSERT INTO test_money (amount, currency) VALUES (?, ?)")
|
sqlx::query("INSERT INTO test_money (amount, currency) VALUES (?, ?)")
|
||||||
.bind(&amount)
|
.bind(amount)
|
||||||
.bind(CurrencyType::Usd)
|
.bind(CurrencyType::Usd)
|
||||||
.execute(&pool)
|
.execute(&pool)
|
||||||
.await
|
.await
|
||||||
@@ -308,10 +308,7 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
retrieved_amount.to_string(),
|
retrieved_amount.to_string(),
|
||||||
expected_str,
|
expected_str,
|
||||||
"Cent-level precision not correct for input: {} (expected: {}, got: {})",
|
"Cent-level precision not correct for input: {input_str} (expected: {expected_str}, got: {retrieved_amount})"
|
||||||
input_str,
|
|
||||||
expected_str,
|
|
||||||
retrieved_amount.to_string()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,8 +476,7 @@ mod tests {
|
|||||||
|
|
||||||
let threshold_amount = MoneyAmount::from_str(threshold).unwrap();
|
let threshold_amount = MoneyAmount::from_str(threshold).unwrap();
|
||||||
let query = format!(
|
let query = format!(
|
||||||
"SELECT COUNT(*) as count FROM test_bids WHERE bid_amount {} ?",
|
"SELECT COUNT(*) as count FROM test_bids WHERE bid_amount {operator} ?"
|
||||||
operator
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let count_row = sqlx::query(&query)
|
let count_row = sqlx::query(&query)
|
||||||
@@ -492,8 +488,7 @@ mod tests {
|
|||||||
let count: i64 = count_row.get("count");
|
let count: i64 = count_row.get("count");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
count as usize, expected_count,
|
count as usize, expected_count,
|
||||||
"Comparison {} {} failed",
|
"Comparison {operator} {threshold} failed"
|
||||||
operator, threshold
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,8 +519,7 @@ mod tests {
|
|||||||
let count: i64 = count_row.get("count");
|
let count: i64 = count_row.get("count");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
count as usize, expected_count,
|
count as usize, expected_count,
|
||||||
"BETWEEN {} AND {} failed",
|
"BETWEEN {min_amount} AND {max_amount} failed"
|
||||||
min_amount, max_amount
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,11 +94,11 @@ mod tests {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
enum InnerEnum {
|
enum InnerEnum {
|
||||||
InnerSimple,
|
Simple,
|
||||||
InnerWithParam(&'static str),
|
WithParam(&'static str),
|
||||||
InnerWithMultiple(&'static str, i32),
|
WithMultiple(&'static str, i32),
|
||||||
InnerWithStruct { field: &'static str },
|
WithStruct { field: &'static str },
|
||||||
InnerWithMultiStruct { field: &'static str, number: i32 },
|
WithMultiStruct { field: &'static str, number: i32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function for testing handlers with expected results
|
// Helper function for testing handlers with expected results
|
||||||
@@ -144,29 +144,29 @@ mod tests {
|
|||||||
)]
|
)]
|
||||||
// Single parameter extraction from nested enum
|
// Single parameter extraction from nested enum
|
||||||
#[case::nested_single_match(
|
#[case::nested_single_match(
|
||||||
case![TestEnum::NestedVariant(InnerEnum::InnerWithParam(p))].endpoint(|p: &'static str| async move { p }),
|
case![TestEnum::NestedVariant(InnerEnum::WithParam(p))].endpoint(|p: &'static str| async move { p }),
|
||||||
TestEnum::NestedVariant(InnerEnum::InnerWithParam("nested")),
|
TestEnum::NestedVariant(InnerEnum::WithParam("nested")),
|
||||||
Some("nested")
|
Some("nested")
|
||||||
)]
|
)]
|
||||||
#[case::nested_single_wrong_inner_variant(
|
#[case::nested_single_wrong_inner_variant(
|
||||||
case![TestEnum::NestedVariant(InnerEnum::InnerWithParam(p))].endpoint(|p: &'static str| async move { p }),
|
case![TestEnum::NestedVariant(InnerEnum::WithParam(p))].endpoint(|p: &'static str| async move { p }),
|
||||||
TestEnum::NestedVariant(InnerEnum::InnerSimple),
|
TestEnum::NestedVariant(InnerEnum::Simple),
|
||||||
None
|
None
|
||||||
)]
|
)]
|
||||||
#[case::nested_single_wrong_outer_variant(
|
#[case::nested_single_wrong_outer_variant(
|
||||||
case![TestEnum::NestedVariant(InnerEnum::InnerWithParam(p))].endpoint(|p: &'static str| async move { p }),
|
case![TestEnum::NestedVariant(InnerEnum::WithParam(p))].endpoint(|p: &'static str| async move { p }),
|
||||||
TestEnum::DefaultVariant,
|
TestEnum::DefaultVariant,
|
||||||
None
|
None
|
||||||
)]
|
)]
|
||||||
// Single field extraction from nested struct
|
// Single field extraction from nested struct
|
||||||
#[case::struct_field_match(
|
#[case::struct_field_match(
|
||||||
case![TestEnum::NestedVariant(InnerEnum::InnerWithStruct { field })].endpoint(|field: &'static str| async move { field }),
|
case![TestEnum::NestedVariant(InnerEnum::WithStruct { field })].endpoint(|field: &'static str| async move { field }),
|
||||||
TestEnum::NestedVariant(InnerEnum::InnerWithStruct { field: "struct_value" }),
|
TestEnum::NestedVariant(InnerEnum::WithStruct { field: "struct_value" }),
|
||||||
Some("struct_value")
|
Some("struct_value")
|
||||||
)]
|
)]
|
||||||
#[case::struct_field_no_match(
|
#[case::struct_field_no_match(
|
||||||
case![TestEnum::NestedVariant(InnerEnum::InnerWithStruct { field })].endpoint(|field: &'static str| async move { field }),
|
case![TestEnum::NestedVariant(InnerEnum::WithStruct { field })].endpoint(|field: &'static str| async move { field }),
|
||||||
TestEnum::NestedVariant(InnerEnum::InnerSimple),
|
TestEnum::NestedVariant(InnerEnum::Simple),
|
||||||
None
|
None
|
||||||
)]
|
)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -202,8 +202,8 @@ mod tests {
|
|||||||
|
|
||||||
// Test cases for nested multiple parameter extraction
|
// Test cases for nested multiple parameter extraction
|
||||||
#[rstest::rstest]
|
#[rstest::rstest]
|
||||||
#[case(TestEnum::NestedVariant(InnerEnum::InnerWithMultiple("nested", 123)), Some(("nested", 123)))]
|
#[case(TestEnum::NestedVariant(InnerEnum::WithMultiple("nested", 123)), Some(("nested", 123)))]
|
||||||
#[case(TestEnum::NestedVariant(InnerEnum::InnerSimple), None)]
|
#[case(TestEnum::NestedVariant(InnerEnum::Simple), None)]
|
||||||
#[case(TestEnum::DefaultVariant, None)]
|
#[case(TestEnum::DefaultVariant, None)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_nested_multiple_parameter_extraction(
|
async fn test_nested_multiple_parameter_extraction(
|
||||||
@@ -211,7 +211,7 @@ mod tests {
|
|||||||
#[case] expected_params: Option<(&'static str, i32)>,
|
#[case] expected_params: Option<(&'static str, i32)>,
|
||||||
) {
|
) {
|
||||||
let handler: Handler<'static, (&str, i32), DpHandlerDescription> =
|
let handler: Handler<'static, (&str, i32), DpHandlerDescription> =
|
||||||
case![TestEnum::NestedVariant(InnerEnum::InnerWithMultiple(s, n))]
|
case![TestEnum::NestedVariant(InnerEnum::WithMultiple(s, n))]
|
||||||
.endpoint(|params: (&'static str, i32)| async move { params });
|
.endpoint(|params: (&'static str, i32)| async move { params });
|
||||||
|
|
||||||
let input = deps![input_variant];
|
let input = deps![input_variant];
|
||||||
@@ -225,8 +225,8 @@ mod tests {
|
|||||||
|
|
||||||
// Test cases for struct pattern extraction
|
// Test cases for struct pattern extraction
|
||||||
#[rstest::rstest]
|
#[rstest::rstest]
|
||||||
#[case(TestEnum::NestedVariant(InnerEnum::InnerWithStruct { field: "struct_field" }), Some("struct_field"))]
|
#[case(TestEnum::NestedVariant(InnerEnum::WithStruct { field: "struct_field" }), Some("struct_field"))]
|
||||||
#[case(TestEnum::NestedVariant(InnerEnum::InnerSimple), None)]
|
#[case(TestEnum::NestedVariant(InnerEnum::Simple), None)]
|
||||||
#[case(TestEnum::DefaultVariant, None)]
|
#[case(TestEnum::DefaultVariant, None)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_struct_pattern_extraction(
|
async fn test_struct_pattern_extraction(
|
||||||
@@ -234,10 +234,8 @@ mod tests {
|
|||||||
#[case] expected_field: Option<&'static str>,
|
#[case] expected_field: Option<&'static str>,
|
||||||
) {
|
) {
|
||||||
let handler: Handler<'static, &str, DpHandlerDescription> =
|
let handler: Handler<'static, &str, DpHandlerDescription> =
|
||||||
case![TestEnum::NestedVariant(InnerEnum::InnerWithStruct {
|
case![TestEnum::NestedVariant(InnerEnum::WithStruct { field })]
|
||||||
field
|
.endpoint(|field: &'static str| async move { field });
|
||||||
})]
|
|
||||||
.endpoint(|field: &'static str| async move { field });
|
|
||||||
|
|
||||||
let input = deps![input_variant];
|
let input = deps![input_variant];
|
||||||
let result = handler.dispatch(input).await;
|
let result = handler.dispatch(input).await;
|
||||||
@@ -250,8 +248,8 @@ mod tests {
|
|||||||
|
|
||||||
// Test cases for multi-field struct pattern extraction
|
// Test cases for multi-field struct pattern extraction
|
||||||
#[rstest::rstest]
|
#[rstest::rstest]
|
||||||
#[case(TestEnum::NestedVariant(InnerEnum::InnerWithMultiStruct { field: "multi_field", number: 42 }), Some(("multi_field", 42)))]
|
#[case(TestEnum::NestedVariant(InnerEnum::WithMultiStruct { field: "multi_field", number: 42 }), Some(("multi_field", 42)))]
|
||||||
#[case(TestEnum::NestedVariant(InnerEnum::InnerSimple), None)]
|
#[case(TestEnum::NestedVariant(InnerEnum::Simple), None)]
|
||||||
#[case(TestEnum::DefaultVariant, None)]
|
#[case(TestEnum::DefaultVariant, None)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_multi_struct_pattern_extraction(
|
async fn test_multi_struct_pattern_extraction(
|
||||||
@@ -259,7 +257,7 @@ mod tests {
|
|||||||
#[case] expected_fields: Option<(&'static str, i32)>,
|
#[case] expected_fields: Option<(&'static str, i32)>,
|
||||||
) {
|
) {
|
||||||
let handler: Handler<'static, (&str, i32), DpHandlerDescription> =
|
let handler: Handler<'static, (&str, i32), DpHandlerDescription> =
|
||||||
case![TestEnum::NestedVariant(InnerEnum::InnerWithMultiStruct {
|
case![TestEnum::NestedVariant(InnerEnum::WithMultiStruct {
|
||||||
field,
|
field,
|
||||||
number
|
number
|
||||||
})]
|
})]
|
||||||
|
|||||||
@@ -143,15 +143,6 @@ pub fn create_single_button_keyboard(text: &str, callback_data: &str) -> InlineK
|
|||||||
InlineKeyboardMarkup::new([[InlineKeyboardButton::callback(text, callback_data)]])
|
InlineKeyboardMarkup::new([[InlineKeyboardButton::callback(text, callback_data)]])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a keyboard with multiple buttons in a single row
|
|
||||||
pub fn create_single_row_keyboard(buttons: &[(&str, &str)]) -> InlineKeyboardMarkup {
|
|
||||||
let keyboard_buttons: Vec<InlineKeyboardButton> = buttons
|
|
||||||
.iter()
|
|
||||||
.map(|(text, callback_data)| InlineKeyboardButton::callback(*text, *callback_data))
|
|
||||||
.collect();
|
|
||||||
InlineKeyboardMarkup::new([keyboard_buttons])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a keyboard with multiple rows
|
// Create a keyboard with multiple rows
|
||||||
pub fn create_multi_row_keyboard(rows: &[&[(&str, &str)]]) -> InlineKeyboardMarkup {
|
pub fn create_multi_row_keyboard(rows: &[&[(&str, &str)]]) -> InlineKeyboardMarkup {
|
||||||
let mut keyboard = InlineKeyboardMarkup::default();
|
let mut keyboard = InlineKeyboardMarkup::default();
|
||||||
|
|||||||
Reference in New Issue
Block a user