chore: address Rust 1.75 clippy lints (#3231)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Chethan Rao
2024-01-05 16:22:31 +05:30
committed by GitHub
parent f30ba89884
commit c8279b110e
25 changed files with 141 additions and 142 deletions

View File

@ -556,7 +556,7 @@ impl From<Database> for storage_impl::config::Database {
dbname: val.dbname,
pool_size: val.pool_size,
connection_timeout: val.connection_timeout,
queue_strategy: val.queue_strategy.into(),
queue_strategy: val.queue_strategy,
min_idle: val.min_idle,
max_lifetime: val.max_lifetime,
}

View File

@ -297,11 +297,11 @@ fn build_error_response<T>(
get_error_response(
response
.get(0)
.first()
.and_then(|err_details| err_details.extensions.as_ref())
.and_then(|extensions| extensions.legacy_code.clone()),
response
.get(0)
.first()
.map(|err_details| err_details.message.clone()),
reason,
http_code,

View File

@ -1026,10 +1026,7 @@ impl utils::MultipleCaptureSyncResponse for Box<PaymentsResponse> {
self.status == CheckoutPaymentStatus::Captured
}
fn get_amount_captured(&self) -> Option<i64> {
match self.amount {
Some(amount) => amount.try_into().ok(),
None => None,
}
self.amount.map(Into::into)
}
}

View File

@ -2336,7 +2336,7 @@ pub fn get_connector_metadata(
let next_action_response = next_action
.and_then(|next_action_response| match next_action_response {
StripeNextActionResponse::DisplayBankTransferInstructions(response) => {
let bank_instructions = response.financial_addresses.get(0);
let bank_instructions = response.financial_addresses.first();
let (sepa_bank_instructions, bacs_bank_instructions) =
bank_instructions.map_or((None, None), |financial_address| {
(

View File

@ -1512,86 +1512,6 @@ pub fn get_error_code_error_message_based_on_priority(
.cloned()
}
#[cfg(test)]
mod error_code_error_message_tests {
#![allow(clippy::unwrap_used)]
use super::*;
struct TestConnector;
impl ConnectorErrorTypeMapping for TestConnector {
fn get_connector_error_type(
&self,
error_code: String,
error_message: String,
) -> ConnectorErrorType {
match (error_code.as_str(), error_message.as_str()) {
("01", "INVALID_MERCHANT") => ConnectorErrorType::BusinessError,
("03", "INVALID_CVV") => ConnectorErrorType::UserError,
("04", "04") => ConnectorErrorType::TechnicalError,
_ => ConnectorErrorType::UnknownError,
}
}
}
#[test]
fn test_get_error_code_error_message_based_on_priority() {
let error_code_message_list_unknown = vec![
ErrorCodeAndMessage {
error_code: "01".to_string(),
error_message: "INVALID_MERCHANT".to_string(),
},
ErrorCodeAndMessage {
error_code: "05".to_string(),
error_message: "05".to_string(),
},
ErrorCodeAndMessage {
error_code: "03".to_string(),
error_message: "INVALID_CVV".to_string(),
},
ErrorCodeAndMessage {
error_code: "04".to_string(),
error_message: "04".to_string(),
},
];
let error_code_message_list_user = vec![
ErrorCodeAndMessage {
error_code: "01".to_string(),
error_message: "INVALID_MERCHANT".to_string(),
},
ErrorCodeAndMessage {
error_code: "03".to_string(),
error_message: "INVALID_CVV".to_string(),
},
];
let error_code_error_message_unknown = get_error_code_error_message_based_on_priority(
TestConnector,
error_code_message_list_unknown,
);
let error_code_error_message_user = get_error_code_error_message_based_on_priority(
TestConnector,
error_code_message_list_user,
);
let error_code_error_message_none =
get_error_code_error_message_based_on_priority(TestConnector, vec![]);
assert_eq!(
error_code_error_message_unknown,
Some(ErrorCodeAndMessage {
error_code: "05".to_string(),
error_message: "05".to_string(),
})
);
assert_eq!(
error_code_error_message_user,
Some(ErrorCodeAndMessage {
error_code: "03".to_string(),
error_message: "INVALID_CVV".to_string(),
})
);
assert_eq!(error_code_error_message_none, None);
}
}
pub trait MultipleCaptureSyncResponse {
fn get_connector_capture_id(&self) -> String;
fn get_capture_attempt_status(&self) -> enums::AttemptStatus;
@ -1785,3 +1705,83 @@ impl FrmTransactionRouterDataRequest for fraud_check::FrmTransactionRouterData {
}
}
}
#[cfg(test)]
mod error_code_error_message_tests {
#![allow(clippy::unwrap_used)]
use super::*;
struct TestConnector;
impl ConnectorErrorTypeMapping for TestConnector {
fn get_connector_error_type(
&self,
error_code: String,
error_message: String,
) -> ConnectorErrorType {
match (error_code.as_str(), error_message.as_str()) {
("01", "INVALID_MERCHANT") => ConnectorErrorType::BusinessError,
("03", "INVALID_CVV") => ConnectorErrorType::UserError,
("04", "04") => ConnectorErrorType::TechnicalError,
_ => ConnectorErrorType::UnknownError,
}
}
}
#[test]
fn test_get_error_code_error_message_based_on_priority() {
let error_code_message_list_unknown = vec![
ErrorCodeAndMessage {
error_code: "01".to_string(),
error_message: "INVALID_MERCHANT".to_string(),
},
ErrorCodeAndMessage {
error_code: "05".to_string(),
error_message: "05".to_string(),
},
ErrorCodeAndMessage {
error_code: "03".to_string(),
error_message: "INVALID_CVV".to_string(),
},
ErrorCodeAndMessage {
error_code: "04".to_string(),
error_message: "04".to_string(),
},
];
let error_code_message_list_user = vec![
ErrorCodeAndMessage {
error_code: "01".to_string(),
error_message: "INVALID_MERCHANT".to_string(),
},
ErrorCodeAndMessage {
error_code: "03".to_string(),
error_message: "INVALID_CVV".to_string(),
},
];
let error_code_error_message_unknown = get_error_code_error_message_based_on_priority(
TestConnector,
error_code_message_list_unknown,
);
let error_code_error_message_user = get_error_code_error_message_based_on_priority(
TestConnector,
error_code_message_list_user,
);
let error_code_error_message_none =
get_error_code_error_message_based_on_priority(TestConnector, vec![]);
assert_eq!(
error_code_error_message_unknown,
Some(ErrorCodeAndMessage {
error_code: "05".to_string(),
error_message: "05".to_string(),
})
);
assert_eq!(
error_code_error_message_user,
Some(ErrorCodeAndMessage {
error_code: "03".to_string(),
error_message: "INVALID_CVV".to_string(),
})
);
assert_eq!(error_code_error_message_none, None);
}
}

View File

@ -90,7 +90,7 @@ impl ConnectorCommon for Wise {
let default_status = response.status.unwrap_or_default().to_string();
match response.errors {
Some(errs) => {
if let Some(e) = errs.get(0) {
if let Some(e) = errs.first() {
Ok(types::ErrorResponse {
status_code: res.status_code,
code: e.code.clone(),
@ -301,7 +301,7 @@ impl services::ConnectorIntegration<api::PoCancel, types::PayoutsData, types::Pa
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
let def_res = response.status.unwrap_or_default().to_string();
let errors = response.errors.unwrap_or_default();
let (code, message) = if let Some(e) = errors.get(0) {
let (code, message) = if let Some(e) = errors.first() {
(e.code.clone(), e.message.clone())
} else {
(def_res, response.message.unwrap_or_default())

View File

@ -306,21 +306,21 @@ where
// Panic Safety: we are first checking if the object is present... only if present, we try to fetch index 0
let frm_configs_object = FrmConfigsObject {
frm_enabled_gateway: filtered_frm_config
.get(0)
.first()
.and_then(|c| c.gateway),
frm_enabled_pm: filtered_payment_methods
.get(0)
.first()
.and_then(|pm| pm.payment_method),
frm_enabled_pm_type: filtered_payment_method_types
.get(0)
.first()
.and_then(|pmt| pmt.payment_method_type),
frm_action: filtered_payment_method_types
// .clone()
.get(0)
.first()
.map(|pmt| pmt.action.clone())
.unwrap_or(api_enums::FrmAction::ManualReview),
frm_preferred_flow_type: filtered_payment_method_types
.get(0)
.first()
.map(|pmt| pmt.flow.clone())
.unwrap_or(api_enums::FrmPreferredFlowTypes::Pre),
};

View File

@ -2158,10 +2158,7 @@ pub async fn apply_filters_on_payments(
merchant.storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?
.into_iter()
.map(|(pi, pa)| (pi, pa))
.collect();
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
let data: Vec<api::PaymentsResponse> =
list.into_iter().map(ForeignFrom::foreign_from).collect();

View File

@ -547,7 +547,7 @@ where
if third_party_sdk_session_next_action(&payment_attempt, operation) {
next_action_response = Some(
api_models::payments::NextActionData::ThirdPartySdkSessionToken {
session_token: payment_data.sessions_token.get(0).cloned(),
session_token: payment_data.sessions_token.first().cloned(),
},
)
}

View File

@ -572,7 +572,7 @@ mod tests {
assert_eq!(1, found_disputes.len());
assert_eq!(created_dispute, found_disputes.get(0).unwrap().clone());
assert_eq!(created_dispute, found_disputes.first().unwrap().clone());
}
#[tokio::test]
@ -611,7 +611,7 @@ mod tests {
assert_eq!(1, found_disputes.len());
assert_eq!(created_dispute, found_disputes.get(0).unwrap().clone());
assert_eq!(created_dispute, found_disputes.first().unwrap().clone());
}
mod update_dispute {

View File

@ -1,4 +1 @@
pub use common_utils::{
async_spawn, collect_missing_value_keys, fallback_reverse_lookup_not_found, newtype,
newtype_impl,
};
pub use common_utils::{collect_missing_value_keys, newtype};

View File

@ -1539,16 +1539,16 @@ pub fn build_redirection_form(
var responseForm = document.createElement('form');
responseForm.action=window.location.pathname.replace(/payments\\/redirect\\/(\\w+)\\/(\\w+)\\/\\w+/, \"payments/$1/$2/redirect/complete/nmi\");
responseForm.method='POST';
const threeDSsecureInterface = threeDS.createUI(options);
threeDSsecureInterface.start('body');
threeDSsecureInterface.on('challenge', function(e) {{
console.log('Challenged');
}});
threeDSsecureInterface.on('complete', function(e) {{
var item1=document.createElement('input');
item1.type='hidden';
item1.name='cavv';
@ -1582,11 +1582,11 @@ pub fn build_redirection_form(
document.body.appendChild(responseForm);
responseForm.submit();
}});
threeDSsecureInterface.on('failure', function(e) {{
responseForm.submit();
}});
</script>"
)))
}
@ -1594,14 +1594,6 @@ pub fn build_redirection_form(
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_mime_essence() {
assert_eq!(mime::APPLICATION_JSON.essence_str(), "application/json");
}
}
pub fn build_payment_link_html(
payment_link_data: PaymentLinkFormData,
) -> CustomResult<String, errors::ApiErrorResponse> {
@ -1631,3 +1623,11 @@ pub fn build_payment_link_html(
fn get_hyper_loader_sdk(sdk_url: &str) -> String {
format!("<script src=\"{sdk_url}\"></script>")
}
#[cfg(test)]
mod tests {
#[test]
fn test_mime_essence() {
assert_eq!(mime::APPLICATION_JSON.essence_str(), "application/json");
}
}

View File

@ -177,7 +177,7 @@ pub enum VettingStatus {
impl SellerStatusResponse {
pub fn extract_merchant_details_url(self, paypal_base_url: &str) -> RouterResult<String> {
self.links
.get(0)
.first()
.and_then(|link| link.href.strip_prefix('/'))
.map(|link| format!("{}{}", paypal_base_url, link))
.ok_or(ApiErrorResponse::InternalServerError)

View File

@ -26,7 +26,6 @@ pub mod payment_link;
pub mod payment_method;
pub mod payout_attempt;
pub mod payouts;
mod query;
pub mod refund;
pub mod reverse_lookup;
pub mod routing_algorithm;

View File

@ -1 +0,0 @@
pub use diesel_models::query::*;

View File

@ -196,16 +196,6 @@ impl QrImage {
}
}
#[cfg(test)]
mod tests {
use crate::utils;
#[test]
fn test_image_data_source_url() {
let qr_image_data_source_url = utils::QrImage::new_from_data("Hyperswitch".to_string());
assert!(qr_image_data_source_url.is_ok());
}
}
pub async fn find_payment_intent_from_payment_id_type(
db: &dyn StorageInterface,
payment_id_type: payments::PaymentIdType,
@ -804,3 +794,13 @@ pub async fn flatten_join_error<T>(handle: Handle<T>) -> RouterResult<T> {
.attach_printable("Join Error"),
}
}
#[cfg(test)]
mod tests {
use crate::utils;
#[test]
fn test_image_data_source_url() {
let qr_image_data_source_url = utils::QrImage::new_from_data("Hyperswitch".to_string());
assert!(qr_image_data_source_url.is_ok());
}
}

View File

@ -48,9 +48,9 @@ pub async fn generate_sample_data(
.change_context(SampleDataError::InternalServerError)
.attach_printable("Error while parsing primary business details")?;
let business_country_default = merchant_parsed_details.get(0).map(|x| x.country);
let business_country_default = merchant_parsed_details.first().map(|x| x.country);
let business_label_default = merchant_parsed_details.get(0).map(|x| x.business.clone());
let business_label_default = merchant_parsed_details.first().map(|x| x.business.clone());
let profile_id = crate::core::utils::get_profile_id_from_business_details(
business_country_default,