Skip to content

Commit

Permalink
Merge branch 'main' into log-event-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
PritishBudhiraja authored Oct 29, 2024
2 parents a0bfd8a + 1ff5e17 commit d12a4f4
Show file tree
Hide file tree
Showing 135 changed files with 9,156 additions and 4,645 deletions.
6 changes: 4 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- @akash-c-k @ArushKapoorJuspay @PritishBudhiraja @seekshiva @swamu
- @akash-c-k @ArushKapoorJuspay @PritishBudhiraja @seekshiva

docs/ @akash-c-k
LICENSE @akash-c-k
Expand All @@ -16,4 +16,6 @@ aws/ @seekshiva
webpack.dev.js @ArushKapoorJuspay @PritishBudhiraja @seekshiva
webpack.common.js @ArushKapoorJuspay @PritishBudhiraja @seekshiva

src/ @seekshiva @PritishBudhiraja @ArushKapoorJuspay @swamu
src/ @seekshiva @PritishBudhiraja @ArushKapoorJuspay
src/orca-log-catcher @Sanskar2001
cypress-tests/ @seekshiva @Sanskar2001
5 changes: 3 additions & 2 deletions .github/workflows/run-automation-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
runs-on: ubuntu-latest
environment: Testing
env:
HS_Pub_Key: ${{ secrets.HYPERSWITCH_PUBLISHABLE_KEY }}
HS_Sec_Key: ${{ secrets.HYPERSWITCH_SECRET_KEY }}
HS_Prof_Id: ${{ secrets.PROFILE_ID }}
HS_Server_Url: "https://sandbox.hyperswitch.io"
HS_Client_Url: "http://localhost:9050"
Expand Down Expand Up @@ -57,4 +55,7 @@ jobs:
uses: cypress-io/github-action@v6
with:
working-directory: ./cypress-tests
env:
CYPRESS_HYPERSWITCH_PUBLISHABLE_KEY: ${{ secrets.HYPERSWITCH_PUBLISHABLE_KEY }}
CYPRESS_HYPERSWITCH_SECRET_KEY: ${{ secrets.HYPERSWITCH_SECRET_KEY }}
# Runs Cypress tests located in the specified directory
386 changes: 386 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Hyperswitch-React-Demo-App/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.2",
"body-parser": "^1.19.0",
"body-parser": "^1.20.3",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"node-fetch": "2.7.0",
Expand Down
3 changes: 2 additions & 1 deletion Hyperswitch-React-Demo-App/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const paymentData = {
authentication_type: "three_ds",
customer_id: "hyperswitch_sdk_demo_id",
email: "[email protected]",
request_external_three_ds_authentication: false,
description: "Hello this is description",
shipping: {
address: {
Expand Down Expand Up @@ -97,7 +98,7 @@ const paymentData = {
}

const profileId = process.env.PROFILE_ID;
if(profileId) {
if (profileId) {
paymentData.profile_id = profileId;
}

Expand Down
70 changes: 44 additions & 26 deletions Hyperswitch-React-Demo-App/src/Payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,44 @@ function Payment() {
const [hyperPromise, setHyperPromise] = useState(null);
const [clientSecret, setClientSecret] = useState("");

useEffect(() => {
const fetchData = async () => {
try {
const url = SELF_SERVER_URL === "" ? ENDPOINT : SELF_SERVER_URL;
const queryParams = new URLSearchParams(window.location.search);
const isCypressTestMode = queryParams.get("isCypressTestMode");
const publishableKeyQueryParam = queryParams.get("publishableKey");
const clientSecretQueryParam = queryParams.get("clientSecret");
const url = SELF_SERVER_URL === "" ? ENDPOINT : SELF_SERVER_URL;

const getPaymentData = async () => {
try {
const [configResponse, urlsResponse] = await Promise.all([
fetch(`${url}/config`),
fetch(`${url}/urls`),
]);

const paymentIntentResponse = isCypressTestMode
? { clientSecret: clientSecretQueryParam }
: await fetch(`${url}/create-payment-intent`).then((res) => res.json());

const [configResponse, urlsResponse, paymentIntentResponse] =
await Promise.all([
fetch(`${url}/config`),
fetch(`${url}/urls`),
fetch(`${url}/create-payment-intent`),
]);
if (!configResponse.ok || !urlsResponse.ok) {
throw new Error("Network response was not ok");
}

const paymentDataArray = await Promise.all([
configResponse.json(),
urlsResponse.json(),
]);

if (
!configResponse.ok ||
!urlsResponse.ok ||
!paymentIntentResponse.ok
) {
throw new Error("Network response was not ok");
}
return [...paymentDataArray, paymentIntentResponse];
} catch (error) {
console.error("Error fetching data:", error);
}
};

const [configData, urlsData, paymentIntentData] = await Promise.all([
configResponse.json(),
urlsResponse.json(),
paymentIntentResponse.json(),
]);
useEffect(() => {
const fetchData = async () => {
try {
const [configData, urlsData, paymentIntentData] = await getPaymentData(
url
);

const { publishableKey } = configData;
const { serverUrl, clientUrl } = urlsData;
Expand All @@ -45,9 +58,12 @@ function Payment() {
setHyperPromise(
new Promise((resolve) => {
resolve(
window.Hyper(publishableKey, {
customBackendUrl: serverUrl,
})
window.Hyper(
isCypressTestMode ? publishableKeyQueryParam : publishableKey,
{
customBackendUrl: serverUrl,
}
)
);
})
);
Expand Down Expand Up @@ -81,7 +97,9 @@ function Payment() {
<HyperElements
hyper={hyperPromise}
options={{
clientSecret,
clientSecret: isCypressTestMode
? clientSecretQueryParam
: clientSecret,
appearance: {
labels: "floating",
},
Expand Down
Empty file removed cypress-tests/.env
Empty file.
4 changes: 4 additions & 0 deletions cypress-tests/cypress.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"HYPERSWITCH_PUBLISHABLE_KEY": "",
"HYPERSWITCH_SECRET_KEY": ""
}
47 changes: 28 additions & 19 deletions cypress-tests/cypress/e2e/card-flow-e2e-test.cy.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import * as testIds from "../../../src/Utilities/TestUtils.bs";
import { CLIENT_URL } from "../support/utils";
import { getClientURL } from "../support/utils";
import { createPaymentBody } from "../support/utils";
import { changeObjectKeyValue } from "../support/utils";

describe("Card payment flow test", () => {
let getIframeBody : () => Cypress.Chainable<JQuery<HTMLBodyElement>>;

const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY')
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY')
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
let iframeSelector =
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";

// changeObjectKeyValue(createPaymentBody,"profile_id","YOUR_PROFILE_ID")


beforeEach(() => {
getIframeBody = () => cy.iframe(iframeSelector);
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
cy.getGlobalState("clientSecret").then((clientSecret) => {

cy.visit(CLIENT_URL);
});
cy.visit(getClientURL(clientSecret, publishableKey));
});

it("page loaded successfully", () => {
cy.visit(CLIENT_URL);
})
});


it("title rendered correctly", () => {
cy.contains("Hyperswitch Unified Checkout").should("be.visible");
});
Expand All @@ -30,18 +41,16 @@ describe("Card payment flow test", () => {

it('should check if cards are saved', () => {
// Visit the page where the test will be performed
cy.visit(CLIENT_URL);

getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`)
.then($element => {
if ($element.length > 0) {
getIframeBody().find('[data-testid=cvvInput]').type('123');
getIframeBody().get("#submit").click();
cy.wait(2000);
cy.contains("Thanks for your order!").should("be.visible");
} else {
cy.log(' new card card flow');
}
});
.then($element => {
if ($element.length > 0) {
getIframeBody().find('[data-testid=cvvInput]').type('123');
getIframeBody().get("#submit").click();
cy.wait(2000);
cy.contains("Thanks for your order!").should("be.visible");
} else {
cy.log(' new card card flow');
}
});
});
});
84 changes: 84 additions & 0 deletions cypress-tests/cypress/e2e/cvc-checks-e2e-test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import * as testIds from "../../../src/Utilities/TestUtils.bs";
import { getClientURL, amexTestCard, visaTestCard, createPaymentBody } from "../support/utils";

describe("Card CVC Checks", () => {
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY')
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY')
let iframeSelector =
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";


beforeEach(() => {
getIframeBody = () => cy.iframe(iframeSelector);
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
cy.getGlobalState("clientSecret").then((clientSecret) => {

cy.visit(getClientURL(clientSecret, publishableKey));
});

})
});




it("title rendered correctly", () => {
cy.contains("Hyperswitch Unified Checkout").should("be.visible");
});

it("orca-payment-element iframe loaded", () => {
cy.get(
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"
)
.should("be.visible")
.its("0.contentDocument")
.its("body");
});


it('user can enter 4 digit cvc in card form', () => {
getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`).click()
getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(amexTestCard)
getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type("0444")
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type("1234").then(() => {
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).should('have.value', '1234');
})


})
it('user can enter 3 digit cvc on saved payment methods screen', () => {
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type('123').then(() => {
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).should('have.value', '123');
})

})

it('user can enter 3 digit cvc in card form', () => {
getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`).click()
getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(visaTestCard)
getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type("0444")
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type("123").then(() => {
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).should('have.value', '123');
})
})

it('user can enter 4 digit cvc on saved payment methods screen', () => {
cy.wait(2000)
getIframeBody()
.contains('div', '4 digit cvc test card')
.should('exist')
.trigger('click')
cy.wait(1000)

getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type("1234").then(() => {
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).should('have.value', '1234');
})

})

})




36 changes: 9 additions & 27 deletions cypress-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
import "cypress-iframe";
import { createPaymentBody } from "./utils"
import * as testIds from "../../../src/Utilities/TestUtils.bs";
// commands.js or your custom support file
const iframeSelector =
const iframeSelector =
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";

let globalState = {};
Expand Down Expand Up @@ -73,11 +74,11 @@ Cypress.Commands.add(
mapping[testIds.cardNoInputTestId] = customerData.threeDSCardNo;
}
let publishableKey = "pk_snd_3b33cd9404234113804aa1accaabe22f";
let clientSecret:string;
let clientSecret: string;
cy.request({
method: "GET",
url: "http://localhost:5252/create-payment-intent",
}).then((response: {body: { clientSecret: string }}) => {
}).then((response: { body: { clientSecret: string } }) => {
clientSecret = response.body.clientSecret;

cy.request({
Expand Down Expand Up @@ -145,37 +146,18 @@ Cypress.Commands.add(
}
);

const request = {
currency: "USD",
amount: 6500,
authentication_type: "three_ds",
description: "Joseph First Crypto",
email: "[email protected]",
connector_metadata: {
noon: {
order_category: "applepay",
},
},
metadata: {
udf1: "value1",
new_customer: "true",
login_date: "2019-09-10T10:11:12Z",
},
// customer_id: "hyperswitch_sdk_demo_test_id",
business_country: "US",
business_label: "default",
};
Cypress.Commands.add("createPaymentIntent", () => {

Cypress.Commands.add("createPaymentIntent", (secretKey: string, createPaymentBody: any) => {
return cy
.request({
method: "POST",
url: "https://sandbox.hyperswitch.io/payments",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"api-key": "snd_c691ade6995743bd88c166ba509ff5da",
"api-key": secretKey,
},
body: JSON.stringify(request),
body: JSON.stringify(createPaymentBody),
})
.then((response) => {
expect(response.headers["content-type"]).to.include("application/json");
Expand All @@ -188,6 +170,6 @@ Cypress.Commands.add("createPaymentIntent", () => {
});
});

Cypress.Commands.add("getGlobalState", (key: number) => {
Cypress.Commands.add("getGlobalState", (key: any) => {
return globalState[key];
});
Loading

0 comments on commit d12a4f4

Please sign in to comment.