Skip to content

Commit

Permalink
test(selenium): read config from CONNECTOR_AUTH_FILE_PATH environme…
Browse files Browse the repository at this point in the history
…nt variable and fix bugs in UI tests (#1225)

Co-authored-by: AkshayaFoiger <[email protected]>
Co-authored-by: Sanchith Hegde <[email protected]>
  • Loading branch information
3 people authored Jun 5, 2023
1 parent 10691c5 commit d9a16ed
Show file tree
Hide file tree
Showing 13 changed files with 738 additions and 118 deletions.
2 changes: 0 additions & 2 deletions crates/api_models/src/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub enum IncomingWebhookEvent {
EventNotSupported,
SourceChargeable,
SourceTransactionCreated,
ChargeSucceeded,
RefundFailure,
RefundSuccess,
DisputeOpened,
Expand Down Expand Up @@ -60,7 +59,6 @@ impl From<IncomingWebhookEvent> for WebhookFlow {
IncomingWebhookEvent::EndpointVerification => Self::ReturnResponse,
IncomingWebhookEvent::SourceChargeable
| IncomingWebhookEvent::SourceTransactionCreated => Self::BankTransfer,
IncomingWebhookEvent::ChargeSucceeded => Self::Payment,
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions crates/router/src/connector/nuvei/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ pub struct NuveiPaymentsRequest {
pub checksum: String,
pub billing_address: Option<BillingAddress>,
pub related_transaction_id: Option<String>,
pub url_details: Option<UrlDetails>,
}

#[derive(Debug, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct UrlDetails {
pub success_url: String,
pub failure_url: String,
pub pending_url: String,
}

#[derive(Debug, Serialize, Default)]
Expand Down Expand Up @@ -676,12 +685,18 @@ impl<F>
capture_method: item.request.capture_method,
..Default::default()
})?;
let return_url = item.request.get_return_url()?;
Ok(Self {
is_rebilling: request_data.is_rebilling,
user_token_id: request_data.user_token_id,
related_transaction_id: request_data.related_transaction_id,
payment_option: request_data.payment_option,
billing_address: request_data.billing_address,
url_details: Some(UrlDetails {
success_url: return_url.clone(),
failure_url: return_url.clone(),
pending_url: return_url,
}),
..request
})
}
Expand Down Expand Up @@ -1017,6 +1032,7 @@ pub enum NuveiTransactionStatus {
Declined,
Error,
Redirect,
Pending,
#[default]
Processing,
}
Expand Down Expand Up @@ -1100,7 +1116,9 @@ fn get_payment_status(response: &NuveiPaymentsResponse) -> enums::AttemptStatus
_ => enums::AttemptStatus::Failure,
}
}
NuveiTransactionStatus::Processing => enums::AttemptStatus::Pending,
NuveiTransactionStatus::Processing | NuveiTransactionStatus::Pending => {
enums::AttemptStatus::Pending
}
NuveiTransactionStatus::Redirect => enums::AttemptStatus::AuthenticationPending,
},
None => match response.status {
Expand Down Expand Up @@ -1253,7 +1271,9 @@ impl From<NuveiTransactionStatus> for enums::RefundStatus {
match item {
NuveiTransactionStatus::Approved => Self::Success,
NuveiTransactionStatus::Declined | NuveiTransactionStatus::Error => Self::Failure,
NuveiTransactionStatus::Processing | NuveiTransactionStatus::Redirect => Self::Pending,
NuveiTransactionStatus::Processing
| NuveiTransactionStatus::Pending
| NuveiTransactionStatus::Redirect => Self::Pending,
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions crates/router/src/connector/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1645,14 +1645,8 @@ impl api::IncomingWebhook for Stripe {

Ok(match details.event_data.event_object.object {
stripe::WebhookEventObjectType::PaymentIntent
| stripe::WebhookEventObjectType::Charge => {
api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::ConnectorTransactionId(
details.event_data.event_object.id,
),
)
}
stripe::WebhookEventObjectType::Dispute => {
| stripe::WebhookEventObjectType::Charge
| stripe::WebhookEventObjectType::Dispute => {
api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::ConnectorTransactionId(
details
Expand Down Expand Up @@ -1692,7 +1686,9 @@ impl api::IncomingWebhook for Stripe {
stripe::WebhookEventType::SourceChargeable => {
api::IncomingWebhookEvent::SourceChargeable
}
stripe::WebhookEventType::ChargeSucceeded => api::IncomingWebhookEvent::ChargeSucceeded,
stripe::WebhookEventType::ChargeSucceeded => {
api::IncomingWebhookEvent::PaymentIntentSuccess
}
stripe::WebhookEventType::DisputeCreated => api::IncomingWebhookEvent::DisputeOpened,
stripe::WebhookEventType::DisputeClosed => api::IncomingWebhookEvent::DisputeCancelled,
stripe::WebhookEventType::DisputeUpdated => api::IncomingWebhookEvent::try_from(
Expand Down
12 changes: 6 additions & 6 deletions crates/router/src/connector/stripe/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,11 +1399,11 @@ pub struct PaymentIntentResponse {
pub id: String,
pub object: String,
pub amount: i64,
pub amount_received: i64,
pub amount_capturable: i64,
pub amount_received: Option<i64>,
pub amount_capturable: Option<i64>,
pub currency: String,
pub status: StripePaymentStatus,
pub client_secret: Secret<String>,
pub client_secret: Option<Secret<String>>,
pub created: i32,
pub customer: Option<String>,
pub payment_method: Option<String>,
Expand Down Expand Up @@ -1519,7 +1519,7 @@ impl From<SetupIntentResponse> for PaymentIntentResponse {
id: value.id,
object: value.object,
status: value.status,
client_secret: value.client_secret,
client_secret: Some(value.client_secret),
customer: value.customer,
description: None,
statement_descriptor: value.statement_descriptor,
Expand Down Expand Up @@ -1619,7 +1619,7 @@ impl<F, T>
connector_metadata,
network_txn_id,
}),
amount_captured: Some(item.response.amount_received),
amount_captured: item.response.amount_received,
..item.data
})
}
Expand Down Expand Up @@ -1707,7 +1707,7 @@ impl<F, T>
Ok(Self {
status: enums::AttemptStatus::from(item.response.status.to_owned()),
response,
amount_captured: Some(item.response.amount_received),
amount_captured: item.response.amount_received,
..item.data
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@ use crate::{selenium::*, tester};

struct AdyenSeleniumTest;

impl SeleniumTest for AdyenSeleniumTest {}
impl SeleniumTest for AdyenSeleniumTest {
fn get_connector_name(&self) -> String {
"adyen_uk".to_string()
}
}

async fn should_make_adyen_gpay_payment(c: WebDriver) -> Result<(), WebDriverError> {
let conn = AdyenSeleniumTest {};
let pub_key = conn.get_configs().adyen_uk.unwrap().key1;
conn.make_gpay_payment(c,
&format!("{CHEKOUT_BASE_URL}/gpay?gatewayname=adyen&gatewaymerchantid=JuspayDEECOM&amount=70.00&country=US&currency=USD"),
&format!("{CHEKOUT_BASE_URL}/gpay?gatewayname=adyen&gatewaymerchantid={pub_key}&amount=70.00&country=US&currency=USD"),
vec![
Event::Assert(Assert::IsPresent("succeeded")),
Event::Assert(Assert::IsPresent("processing")),
]).await?;
Ok(())
}

async fn should_make_adyen_gpay_mandate_payment(c: WebDriver) -> Result<(), WebDriverError> {
let conn = AdyenSeleniumTest {};
let pub_key = conn.get_configs().adyen_uk.unwrap().key1;
conn.make_gpay_payment(c,
&format!("{CHEKOUT_BASE_URL}/gpay?gatewayname=adyen&gatewaymerchantid=JuspayDEECOM&amount=70.00&country=US&currency=USD&mandate_data[customer_acceptance][acceptance_type]=offline&mandate_data[customer_acceptance][accepted_at]=1963-05-03T04:07:52.723Z&mandate_data[customer_acceptance][online][ip_address]=127.0.0.1&mandate_data[customer_acceptance][online][user_agent]=amet%20irure%20esse&mandate_data[mandate_type][multi_use][amount]=7000&mandate_data[mandate_type][multi_use][currency]=USD"),
&format!("{CHEKOUT_BASE_URL}/gpay?gatewayname=adyen&gatewaymerchantid={pub_key}&amount=70.00&country=US&currency=USD&mandate_data[customer_acceptance][acceptance_type]=offline&mandate_data[customer_acceptance][accepted_at]=1963-05-03T04:07:52.723Z&mandate_data[customer_acceptance][online][ip_address]=127.0.0.1&mandate_data[customer_acceptance][online][user_agent]=amet%20irure%20esse&mandate_data[mandate_type][multi_use][amount]=7000&mandate_data[mandate_type][multi_use][currency]=USD"),
vec![
Event::Assert(Assert::IsPresent("succeeded")),
Event::Assert(Assert::IsPresent("processing")),
Event::Assert(Assert::IsPresent("Mandate ID")),
Event::Assert(Assert::IsPresent("man_")),// mandate id starting with man_
Event::Trigger(Trigger::Click(By::Id("pm-mandate-btn"))),
Event::Trigger(Trigger::Click(By::Css("#pm-mandate-btn a"))),
Event::Trigger(Trigger::Click(By::Id("pay-with-mandate-btn"))),
Event::Assert(Assert::IsPresent("succeeded")),
Event::Assert(Assert::IsPresent("processing")),
]).await?;
Ok(())
}
Expand All @@ -36,15 +42,16 @@ async fn should_make_adyen_gpay_zero_dollar_mandate_payment(
c: WebDriver,
) -> Result<(), WebDriverError> {
let conn = AdyenSeleniumTest {};
let pub_key = conn.get_configs().adyen_uk.unwrap().key1;
conn.make_gpay_payment(c,
&format!("{CHEKOUT_BASE_URL}/gpay?gatewayname=adyen&gatewaymerchantid=JuspayDEECOM&amount=0.00&country=US&currency=USD&mandate_data[customer_acceptance][acceptance_type]=offline&mandate_data[customer_acceptance][accepted_at]=1963-05-03T04:07:52.723Z&mandate_data[customer_acceptance][online][ip_address]=127.0.0.1&mandate_data[customer_acceptance][online][user_agent]=amet%20irure%20esse&mandate_data[mandate_type][multi_use][amount]=700&mandate_data[mandate_type][multi_use][currency]=USD"),
&format!("{CHEKOUT_BASE_URL}/gpay?gatewayname=adyen&gatewaymerchantid={pub_key}&amount=0.00&country=US&currency=USD&mandate_data[customer_acceptance][acceptance_type]=offline&mandate_data[customer_acceptance][accepted_at]=1963-05-03T04:07:52.723Z&mandate_data[customer_acceptance][online][ip_address]=127.0.0.1&mandate_data[customer_acceptance][online][user_agent]=amet%20irure%20esse&mandate_data[mandate_type][multi_use][amount]=700&mandate_data[mandate_type][multi_use][currency]=USD"),
vec![
Event::Assert(Assert::IsPresent("succeeded")),
Event::Assert(Assert::IsPresent("processing")),
Event::Assert(Assert::IsPresent("Mandate ID")),
Event::Assert(Assert::IsPresent("man_")),// mandate id starting with man_
Event::Trigger(Trigger::Click(By::Id("pm-mandate-btn"))),
Event::Trigger(Trigger::Click(By::Css("#pm-mandate-btn a"))),
Event::Trigger(Trigger::Click(By::Id("pay-with-mandate-btn"))),
Event::Assert(Assert::IsPresent("succeeded")),
Event::Assert(Assert::IsPresent("processing")),
]).await?;
Ok(())
}
Expand All @@ -67,12 +74,12 @@ async fn should_make_adyen_klarna_mandate_payment(c: WebDriver) -> Result<(), We
]
),
Event::Trigger(Trigger::SwitchTab(Position::Prev)),
Event::Assert(Assert::IsPresent("succeeded")),
Event::Assert(Assert::IsPresent("processing")),
Event::Assert(Assert::IsPresent("Mandate ID")),
Event::Assert(Assert::IsPresent("man_")),// mandate id starting with man_
Event::Trigger(Trigger::Click(By::Id("pm-mandate-btn"))),
Event::Trigger(Trigger::Click(By::Css("#pm-mandate-btn a"))),
Event::Trigger(Trigger::Click(By::Id("pay-with-mandate-btn"))),
Event::Assert(Assert::IsPresent("succeeded")),
Event::Assert(Assert::IsPresent("processing")),
]).await?;
Ok(())
}
Expand Down
43 changes: 32 additions & 11 deletions crates/router/tests/connectors/connector_auth.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::env;

use router::types::ConnectorAuthType;
use serde::Deserialize;
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Clone)]
pub(crate) struct ConnectorAuthentication {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ConnectorAuthentication {
pub aci: Option<BodyKey>,
pub adyen: Option<BodyKey>,
pub adyen_uk: Option<BodyKey>,
pub airwallex: Option<BodyKey>,
pub authorizedotnet: Option<BodyKey>,
pub bambora: Option<BodyKey>,
Expand Down Expand Up @@ -35,10 +36,13 @@ pub(crate) struct ConnectorAuthentication {
pub rapyd: Option<BodyKey>,
pub shift4: Option<HeaderKey>,
pub stripe: Option<HeaderKey>,
pub stripe_au: Option<HeaderKey>,
pub stripe_uk: Option<HeaderKey>,
pub trustpay: Option<SignatureKey>,
pub worldpay: Option<BodyKey>,
pub worldline: Option<SignatureKey>,
pub zen: Option<HeaderKey>,
pub automation_configs: Option<AutomationConfigs>,
}

impl ConnectorAuthentication {
Expand All @@ -55,8 +59,8 @@ impl ConnectorAuthentication {
}
}

#[derive(Debug, Deserialize, Clone)]
pub(crate) struct HeaderKey {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct HeaderKey {
pub api_key: String,
}

Expand All @@ -68,8 +72,8 @@ impl From<HeaderKey> for ConnectorAuthType {
}
}

#[derive(Debug, Deserialize, Clone)]
pub(crate) struct BodyKey {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BodyKey {
pub api_key: String,
pub key1: String,
}
Expand All @@ -83,8 +87,8 @@ impl From<BodyKey> for ConnectorAuthType {
}
}

#[derive(Debug, Deserialize, Clone)]
pub(crate) struct SignatureKey {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SignatureKey {
pub api_key: String,
pub key1: String,
pub api_secret: String,
Expand All @@ -100,8 +104,8 @@ impl From<SignatureKey> for ConnectorAuthType {
}
}

#[derive(Debug, Deserialize, Clone)]
pub(crate) struct MultiAuthKey {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct MultiAuthKey {
pub api_key: String,
pub key1: String,
pub api_secret: String,
Expand All @@ -118,3 +122,20 @@ impl From<MultiAuthKey> for ConnectorAuthType {
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AutomationConfigs {
pub hs_base_url: Option<String>,
pub hs_api_key: Option<String>,
pub hs_test_browser: Option<String>,
pub chrome_profile_path: Option<String>,
pub firefox_profile_path: Option<String>,
pub pypl_email: Option<String>,
pub pypl_pass: Option<String>,
pub gmail_email: Option<String>,
pub gmail_pass: Option<String>,
pub configs_url: Option<String>,
pub stripe_pub_key: Option<String>,
pub testcases_path: Option<String>,
pub run_minimum_steps: Option<bool>,
}
4 changes: 3 additions & 1 deletion crates/router/tests/connectors/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

mod aci;
mod adyen;
mod adyen_ui;
mod adyen_uk_ui;
mod airwallex;
mod authorizedotnet;
mod bambora;
Expand Down Expand Up @@ -35,6 +35,7 @@ mod opennode;
mod payeezy;
mod paypal;
mod payu;
mod payu_ui;
mod rapyd;
mod selenium;
mod shift4;
Expand All @@ -43,5 +44,6 @@ mod stripe_ui;
mod trustpay;
mod utils;
mod worldline;
mod worldline_ui;
mod worldpay;
mod zen;
Loading

0 comments on commit d9a16ed

Please sign in to comment.