mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
refactor: fix unit and documentation tests (#4754)
This commit is contained in:
@ -1001,15 +1001,10 @@ mod hashmap_deserialization_test {
|
||||
fn test_payment_method_and_payment_method_types() {
|
||||
use diesel_models::enums::{PaymentMethod, PaymentMethodType};
|
||||
|
||||
let input_map: HashMap<String, String> = serde_json::json!({
|
||||
"bank_transfer": "ach,bacs",
|
||||
"wallet": "paypal,venmo",
|
||||
})
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect();
|
||||
let input_map: HashMap<String, String> = HashMap::from([
|
||||
("bank_transfer".to_string(), "ach,bacs".to_string()),
|
||||
("wallet".to_string(), "paypal,venmo".to_string()),
|
||||
]);
|
||||
let deserializer: MapDeserializer<
|
||||
'_,
|
||||
std::collections::hash_map::IntoIter<String, String>,
|
||||
@ -1035,15 +1030,10 @@ mod hashmap_deserialization_test {
|
||||
fn test_payment_method_and_payment_method_types_with_spaces() {
|
||||
use diesel_models::enums::{PaymentMethod, PaymentMethodType};
|
||||
|
||||
let input_map: HashMap<String, String> = serde_json::json!({
|
||||
" bank_transfer ": " ach , bacs ",
|
||||
"wallet ": " paypal , pix , venmo ",
|
||||
})
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect();
|
||||
let input_map: HashMap<String, String> = HashMap::from([
|
||||
(" bank_transfer ".to_string(), " ach , bacs ".to_string()),
|
||||
("wallet ".to_string(), " paypal , pix , venmo ".to_string()),
|
||||
]);
|
||||
let deserializer: MapDeserializer<
|
||||
'_,
|
||||
std::collections::hash_map::IntoIter<String, String>,
|
||||
@ -1073,15 +1063,10 @@ mod hashmap_deserialization_test {
|
||||
fn test_payment_method_deserializer_error() {
|
||||
use diesel_models::enums::{PaymentMethod, PaymentMethodType};
|
||||
|
||||
let input_map: HashMap<String, String> = serde_json::json!({
|
||||
"unknown": "ach,bacs",
|
||||
"wallet": "paypal,unknown",
|
||||
})
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect();
|
||||
let input_map: HashMap<String, String> = HashMap::from([
|
||||
("unknown".to_string(), "ach,bacs".to_string()),
|
||||
("wallet".to_string(), "paypal,unknown".to_string()),
|
||||
]);
|
||||
let deserializer: MapDeserializer<
|
||||
'_,
|
||||
std::collections::hash_map::IntoIter<String, String>,
|
||||
|
||||
@ -118,8 +118,8 @@ pub struct ThreeDSRequestor {
|
||||
/// External IP address (i.e., the device public IP address) used by the 3DS Requestor App when it connects to the
|
||||
/// 3DS Requestor environment. The value length is maximum 45 characters. Accepted values are:
|
||||
///
|
||||
/// IPv4 address is represented in the dotted decimal f. Refer to RFC 791.
|
||||
/// IPv6 address. Refer to RFC 4291.
|
||||
/// - IPv4 address is represented in the dotted decimal f. Refer to RFC 791.
|
||||
/// - IPv6 address. Refer to RFC 4291.
|
||||
///
|
||||
/// This field is required when deviceChannel = 01 (APP) and unless market or regional mandate restricts sending
|
||||
/// this information.
|
||||
@ -1454,27 +1454,27 @@ pub struct Sdk {
|
||||
/// The Split-SDK Server:
|
||||
/// Creates a JSON object of the following data as the JWS payload to be signed:
|
||||
///
|
||||
/// SDK Reference Number -> Identifies the vendor and version of the 3DS SDK that is utilised for a specific
|
||||
/// transaction. The value is assigned by EMVCo when the Letter of Approval of the
|
||||
/// specific 3DS SDK is issued. The field is limited to 32 characters.
|
||||
/// SDK Signature Timestamp -> Date and time indicating when the 3DS SDK generated the Split-SDK Server Signed
|
||||
/// Content converted into UTC. The value is limited to 14 characters. Accepted
|
||||
/// format: YYYYMMDDHHMMSS.
|
||||
/// SDK Transaction ID -> Universally unique transaction identifier assigned by the 3DS SDK to identify a
|
||||
/// single transaction. The field is limited to 36 characters and it shall be in a
|
||||
/// canonical format as defined in IETF RFC 4122. This may utilize any of the specified
|
||||
/// versions as long as the output meets specific requirements.
|
||||
/// Split-SDK Server ID -> DS assigned Split-SDK Server identifier. Each DS can provide a unique ID to each
|
||||
/// Split-SDK Server on an individual basis. The field is limited to 32 characters.
|
||||
/// Any individual DS may impose specific formatting and character requirements on the
|
||||
/// contents of this field.
|
||||
/// - SDK Reference Number -> Identifies the vendor and version of the 3DS SDK that is utilised for a specific
|
||||
/// transaction. The value is assigned by EMVCo when the Letter of Approval of the
|
||||
/// specific 3DS SDK is issued. The field is limited to 32 characters.
|
||||
/// - SDK Signature Timestamp -> Date and time indicating when the 3DS SDK generated the Split-SDK Server Signed
|
||||
/// Content converted into UTC. The value is limited to 14 characters. Accepted
|
||||
/// format: YYYYMMDDHHMMSS.
|
||||
/// - SDK Transaction ID -> Universally unique transaction identifier assigned by the 3DS SDK to identify a
|
||||
/// single transaction. The field is limited to 36 characters and it shall be in a
|
||||
/// canonical format as defined in IETF RFC 4122. This may utilize any of the specified
|
||||
/// versions as long as the output meets specific requirements.
|
||||
/// - Split-SDK Server ID -> DS assigned Split-SDK Server identifier. Each DS can provide a unique ID to each
|
||||
/// Split-SDK Server on an individual basis. The field is limited to 32 characters.
|
||||
/// Any individual DS may impose specific formatting and character requirements on the
|
||||
/// contents of this field.
|
||||
///
|
||||
/// Generates a digital signature of the full JSON object according to JWS (RFC 7515) using JWS Compact
|
||||
/// Serialization. The parameter values for this version of the specification and to be included in the JWS
|
||||
/// header are:
|
||||
///
|
||||
/// "alg": PS2567 or ES256
|
||||
/// "x5c": X.5C v3: Cert (PbSDK) and chaining certificates if present
|
||||
/// - `alg`: PS2567 or ES256
|
||||
/// - `x5c`: X.5C v3: Cert (PbSDK) and chaining certificates if present
|
||||
///
|
||||
/// All other parameters: optional
|
||||
///
|
||||
|
||||
@ -3098,7 +3098,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_authenticate_client_secret_fulfillment_time_not_expired() {
|
||||
fn test_authenticate_client_secret_session_not_expired() {
|
||||
let payment_intent = PaymentIntent {
|
||||
payment_id: "23".to_string(),
|
||||
merchant_id: "22".to_string(),
|
||||
@ -3160,7 +3160,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_authenticate_client_secret_fulfillment_time_expired() {
|
||||
fn test_authenticate_client_secret_session_expired() {
|
||||
let created_at =
|
||||
common_utils::date_time::now().saturating_sub(time::Duration::seconds(20 * 60));
|
||||
let payment_intent = PaymentIntent {
|
||||
payment_id: "23".to_string(),
|
||||
merchant_id: "22".to_string(),
|
||||
@ -3177,7 +3179,7 @@ mod tests {
|
||||
billing_address_id: None,
|
||||
statement_descriptor_name: None,
|
||||
statement_descriptor_suffix: None,
|
||||
created_at: common_utils::date_time::now().saturating_sub(time::Duration::seconds(20)),
|
||||
created_at,
|
||||
modified_at: common_utils::date_time::now(),
|
||||
fingerprint_id: None,
|
||||
last_synced: None,
|
||||
@ -3206,8 +3208,7 @@ mod tests {
|
||||
incremental_authorization_allowed: None,
|
||||
authorization_count: None,
|
||||
session_expiry: Some(
|
||||
common_utils::date_time::now()
|
||||
.saturating_add(time::Duration::seconds(consts::DEFAULT_SESSION_EXPIRY)),
|
||||
created_at.saturating_add(time::Duration::seconds(consts::DEFAULT_SESSION_EXPIRY)),
|
||||
),
|
||||
request_external_three_ds_authentication: None,
|
||||
charges: None,
|
||||
|
||||
@ -754,7 +754,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
assert!(updated_event.is_webhook_notified);
|
||||
assert_eq!(updated_event.primary_object_id, "primary_object_tet");
|
||||
assert_eq!(updated_event.primary_object_id, payment_id);
|
||||
assert_eq!(updated_event.event_id, event_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,20 +99,28 @@ mod tests {
|
||||
types::{self, storage::enums},
|
||||
};
|
||||
|
||||
#[actix_rt::test]
|
||||
#[ignore]
|
||||
async fn test_payment_attempt_insert() {
|
||||
async fn create_single_connection_test_transaction_pool() -> routes::AppState {
|
||||
// Set pool size to 1 and minimum idle connection size to 0
|
||||
std::env::set_var("ROUTER__MASTER_DATABASE__POOL_SIZE", "1");
|
||||
std::env::set_var("ROUTER__MASTER_DATABASE__MIN_IDLE", "0");
|
||||
std::env::set_var("ROUTER__REPLICA_DATABASE__POOL_SIZE", "1");
|
||||
std::env::set_var("ROUTER__REPLICA_DATABASE__MIN_IDLE", "0");
|
||||
|
||||
let conf = Settings::new().expect("invalid settings");
|
||||
let tx: oneshot::Sender<()> = oneshot::channel().0;
|
||||
let api_client = Box::new(services::MockApiClient);
|
||||
let state = Box::pin(routes::AppState::with_storage(
|
||||
Box::pin(routes::AppState::with_storage(
|
||||
conf,
|
||||
StorageImpl::PostgresqlTest,
|
||||
tx,
|
||||
api_client,
|
||||
))
|
||||
.await;
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_payment_attempt_insert() {
|
||||
let state = create_single_connection_test_transaction_pool().await;
|
||||
let payment_id = Uuid::new_v4().to_string();
|
||||
let current_time = common_utils::date_time::now();
|
||||
let connector = types::Connector::DummyConnector1.to_string();
|
||||
@ -137,22 +145,11 @@ mod tests {
|
||||
assert_eq!(response.payment_id, payment_id.clone());
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
#[tokio::test]
|
||||
/// Example of unit test
|
||||
/// Kind of test: state-based testing
|
||||
async fn test_find_payment_attempt() {
|
||||
use crate::configs::settings::Settings;
|
||||
let conf = Settings::new().expect("invalid settings");
|
||||
let tx: oneshot::Sender<()> = oneshot::channel().0;
|
||||
let api_client = Box::new(services::MockApiClient);
|
||||
let state = Box::pin(routes::AppState::with_storage(
|
||||
conf,
|
||||
StorageImpl::PostgresqlTest,
|
||||
tx,
|
||||
api_client,
|
||||
))
|
||||
.await;
|
||||
|
||||
let state = create_single_connection_test_transaction_pool().await;
|
||||
let current_time = common_utils::date_time::now();
|
||||
let payment_id = Uuid::new_v4().to_string();
|
||||
let attempt_id = Uuid::new_v4().to_string();
|
||||
@ -192,23 +189,12 @@ mod tests {
|
||||
assert_eq!(response.payment_id, payment_id);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
#[tokio::test]
|
||||
/// Example of unit test
|
||||
/// Kind of test: state-based testing
|
||||
async fn test_payment_attempt_mandate_field() {
|
||||
use crate::configs::settings::Settings;
|
||||
let conf = Settings::new().expect("invalid settings");
|
||||
let state = create_single_connection_test_transaction_pool().await;
|
||||
let uuid = Uuid::new_v4().to_string();
|
||||
let tx: oneshot::Sender<()> = oneshot::channel().0;
|
||||
|
||||
let api_client = Box::new(services::MockApiClient);
|
||||
let state = Box::pin(routes::AppState::with_storage(
|
||||
conf,
|
||||
StorageImpl::PostgresqlTest,
|
||||
tx,
|
||||
api_client,
|
||||
))
|
||||
.await;
|
||||
let current_time = common_utils::date_time::now();
|
||||
let connector = types::Connector::DummyConnector1.to_string();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user