-
Notifications
You must be signed in to change notification settings - Fork 60
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
test: add test case for dynamic fields #839
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { getClientURL, createPaymentBodyWithoutBillingAddress } from "../support/utils"; | ||
|
||
describe("Dynamic Field Test", () => { | ||
let getIframeBody; | ||
let globalClientSecret; | ||
const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY'); | ||
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY'); | ||
const iframeSelector = "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; | ||
|
||
beforeEach(() => { | ||
getIframeBody = () => cy.iframe(iframeSelector); | ||
cy.createPaymentIntent(secretKey, createPaymentBodyWithoutBillingAddress).then(() => { | ||
cy.getGlobalState("clientSecret").then((clientSecret) => { | ||
globalClientSecret = clientSecret; | ||
cy.visit(getClientURL(clientSecret, publishableKey)); | ||
}); | ||
}); | ||
}); | ||
|
||
it("should check that required address fields are set null for 'payment_method_type' = 'debit'", () => { | ||
cy.intercept('GET', `https://sandbox.hyperswitch.io/account/payment_methods?client_secret=${globalClientSecret}`).as('getPaymentMethods'); | ||
|
||
cy.wait('@getPaymentMethods').then(({ response }) => { | ||
expect(response.statusCode).to.eq(200); | ||
|
||
const paymentMethods = response.body.payment_methods; | ||
|
||
const debitMethod = paymentMethods.find(method => | ||
method.payment_method_types.some(type => type.payment_method_type === 'debit') | ||
); | ||
|
||
expect(debitMethod).to.not.be.undefined; | ||
|
||
const requiredFields = debitMethod.payment_method_types.find(type => type.payment_method_type === 'debit').required_fields; | ||
|
||
expect(requiredFields).to.have.property('billing.address.state'); | ||
expect(requiredFields['billing.address.state'].value).to.be.null; | ||
|
||
expect(requiredFields).to.have.property('billing.address.country'); | ||
expect(requiredFields['billing.address.country'].value).to.be.null; | ||
|
||
expect(requiredFields).to.have.property('billing.address.line1'); | ||
expect(requiredFields['billing.address.line1'].value).to.be.null; | ||
|
||
expect(requiredFields).to.have.property('billing.address.zip'); | ||
expect(requiredFields['billing.address.zip'].value).to.be.null; | ||
|
||
expect(requiredFields).to.have.property('billing.address.last_name'); | ||
expect(requiredFields['billing.address.last_name'].value).to.be.null; | ||
|
||
expect(requiredFields).to.have.property('billing.address.city'); | ||
expect(requiredFields['billing.address.city'].value).to.be.null; | ||
|
||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,48 @@ export const createPaymentBody = { | |
|
||
} | ||
|
||
export const createPaymentBodyWithoutBillingAddress = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can reuse the exisiting create body and remove billing and shipping from that object. |
||
currency: "USD", | ||
amount: 2999, | ||
order_details: [ | ||
{ | ||
product_name: "Apple iPhone 15", | ||
quantity: 1, | ||
amount: 2999, | ||
}, | ||
], | ||
confirm: false, | ||
capture_method: "automatic", | ||
authentication_type: "no_three_ds", | ||
customer_id: "hyperswitch_sdk_demo_id", | ||
email: "[email protected]", | ||
request_external_three_ds_authentication: false, | ||
description: "Hello this is description", | ||
shipping: { | ||
address: { | ||
line1: "1467", | ||
line2: "Harrison Street", | ||
line3: "Harrison Street", | ||
city: "San Fransico", | ||
state: "California", | ||
zip: "94122", | ||
country: "US", | ||
first_name: "joseph", | ||
last_name: "Doe", | ||
}, | ||
phone: { | ||
number: "8056594427", | ||
country_code: "+91", | ||
}, | ||
}, | ||
metadata: { | ||
udf1: "value1", | ||
new_customer: "true", | ||
login_date: "2019-09-10T10:11:12Z", | ||
}, | ||
profile_id: "pro_5fVcCxU8MFTYozgtf0P8", | ||
} | ||
|
||
export const changeObjectKeyValue = (object: Record<string, any>, key: string, value: boolean | string) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to this function, create a function to delete a field from an object and use it to delete billing and shipping from existing create payment body object. |
||
object[key] = value | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove shipping also as mentioned in the below comment. And then please add assertions for shipping fields too.