Skip to content

Commit

Permalink
feat: add payout test flows
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakilmostak committed May 23, 2024
1 parent d45f064 commit 85b147e
Show file tree
Hide file tree
Showing 5 changed files with 356 additions and 2 deletions.
104 changes: 104 additions & 0 deletions cypress-tests/cypress/e2e/PayoutTest/00003-CardTest.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import createPayoutBody from "../../fixtures/create-payout-confirm-body.json";
import State from "../../utils/State";
import * as utils from "../PayoutUtils/utils";

let globalState;

describe("Card - Auto Fulfill", () => {
let should_continue = true; // variable that will be used to skip tests if a previous test fails

beforeEach(function () {
if(!should_continue) {
this.skip();
}
});

before("seed global state", () => {

cy.task('getGlobalState').then((state) => {
globalState = new State(state);
console.log("seeding globalState -> " + JSON.stringify(globalState));
cy.task('cli_log', "SEEDING GLOBAL STATE -> " + JSON.stringify(globalState));
})

})

afterEach("flush global state", () => {
console.log("flushing globalState -> " + JSON.stringify(globalState));
cy.task('setGlobalState', globalState.data);
cy.task('cli_log', " FLUSHING GLOBAL STATE -> " + JSON.stringify(globalState));
})

context("Payout Card with Auto Fulfill", () => {

it("confirm-payout-call-with-auto-fulfill-test", () => {
let data = utils.getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Fulfill"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.createConfirmPayoutTest(createPayoutBody, req_data, res_data, true, true, globalState);
if(should_continue) should_continue = utils.should_continue_further(res_data);
});

it("retrieve-payout-call-test", () => {
cy.retrievePayoutCallTest(globalState);
});

});

context("Payout Card with Manual Fulfill - Create Confirm", () => {

it("confirm-payout-call-with-manual-fulfill-test", () => {
let data = utils.getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Confirm"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.createConfirmPayoutTest(createPayoutBody, req_data, res_data, true, false, globalState);
if(should_continue) should_continue = utils.should_continue_further(res_data);
});

it("fulfill-payout-call-test", () => {
let data = utils.getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Fulfill"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.fulfillPayoutCallTest({}, req_data, res_data, globalState);
if(should_continue) should_continue = utils.should_continue_further(res_data);
});

it("retrieve-payout-call-test", () => {
cy.retrievePayoutCallTest(globalState);
});

});

context("Payout Card with Manual Fulfill - Create Intent + Confirm", () => {

it("create-payout-call", () => {
let data = utils.getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Create"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.createConfirmPayoutTest(createPayoutBody, req_data, res_data, false, false, globalState);
if(should_continue) should_continue = utils.should_continue_further(res_data);
});

it("confirm-payout-call", () => {
let data = utils.getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Confirm"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.updatePayoutCallTest({}, req_data, res_data, false, globalState);
if(should_continue) should_continue = utils.should_continue_further(res_data);
});

it("fulfill-payout-call-test", () => {
let data = utils.getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Fulfill"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.fulfillPayoutCallTest({}, req_data, res_data, globalState);
if(should_continue) should_continue = utils.should_continue_further(res_data);
});

it("retrieve-payout-call-test", () => {
cy.retrievePayoutCallTest(globalState);
});

});

});
60 changes: 60 additions & 0 deletions cypress-tests/cypress/e2e/PayoutUtils/Adyen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

const card_data = {
"card_number": "4111111111111111",
"expiry_month": "3",
"expiry_year": "2030",
"card_holder_name": "John Smith"
};

export const connectorDetails = {
card_pm:{
"Create": {
"Request": {
"payout_method_data": {
"card": card_data,
},
"currency": "EUR",
"payout_type": "card",
},
"Response": {
"status": 200,
"body": {
"status": "requires_creation",
"payout_type": "card"
}
}
},
"Confirm": {
"Request": {
"payout_method_data": {
"card": card_data,
},
"currency": "EUR",
"payout_type": "card",
},
"Response": {
"status": 200,
"body": {
"status": "requires_fulfillment",
"payout_type": "card"
}
}
},
"Fulfill": {
"Request": {
"payout_method_data": {
"card": card_data,
},
"currency": "EUR",
"payout_type": "card",
},
"Response": {
"status": 200,
"body": {
"status": "success",
"payout_type": "card"
}
}
}
}
};
30 changes: 30 additions & 0 deletions cypress-tests/cypress/e2e/PayoutUtils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { connectorDetails as adyenConnectorDetails } from "./Adyen.js";

const connectorDetails = {
"adyen": adyenConnectorDetails,
}


export const getConnectorDetails = (connectorId) => {
let x = getValueByKey(connectorDetails, connectorId);
return x;
}

function getValueByKey(jsonObject, key) {
const data = typeof jsonObject === 'string' ? JSON.parse(jsonObject) : jsonObject;

if (data && typeof data === 'object' && key in data) {
return data[key];
} else {
return null;
}
}

export const should_continue_further = (res_data) => {
if(res_data.body.error !== undefined || res_data.body.error_code !== undefined || res_data.body.error_message !== undefined){
return false;
}
else {
return true;
}
}
36 changes: 36 additions & 0 deletions cypress-tests/cypress/fixtures/create-payout-confirm-body.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"amount": 1,
"currency": "EUR",
"customer_id": "payout_customer",
"email": "[email protected]",
"name": "John Doe",
"phone": "999999999",
"phone_country_code": "+65",
"description": "Its my first payout request",
"payout_type": "card",
"payout_method_data": {},
"billing": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "NY",
"zip": "94122",
"country": "US",
"first_name": "John",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
}
},
"entity_type": "Individual",
"recurring": false,
"metadata": {
"ref": "123"
},
"auto_fulfill": true,
"confirm": true
}
128 changes: 126 additions & 2 deletions cypress-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,131 @@ Cypress.Commands.add("listRefundCallTest", (requestBody, globalState) => {
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body.data).to.be.an('array').and.not.empty;

});
});
});


Cypress.Commands.add("createConfirmPayoutTest", (createConfirmPayoutBody, req_data, res_data, confirm, auto_fulfill, globalState) => {
for(const key in req_data) {
createConfirmPayoutBody[key] = req_data[key];
}
createConfirmPayoutBody.auto_fulfill = auto_fulfill;
createConfirmPayoutBody.confirm = confirm;
createConfirmPayoutBody.customer_id = globalState.get("customerId");

cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/payouts/create`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
body: createConfirmPayoutBody,
}).then((response) => {
logRequestId(response.headers['x-request-id']);

expect(res_data.status).to.equal(response.status);
expect(response.headers["content-type"]).to.include("application/json");

if(response.status === 200){
globalState.set("payoutAmount", createConfirmPayoutBody.amount);
globalState.set("payoutID", response.body.payout_id);
for(const key in res_data.body) {
expect(res_data.body[key]).to.equal(response.body[key]);
}
}
else{
expect(response.body).to.have.property("error");
for(const key in res_data.body.error) {
expect(res_data.body.error[key]).to.equal(response.body.error[key]);
}
}
});
});

Cypress.Commands.add("fulfillPayoutCallTest", (payoutFulfillBody, req_data, res_data, globalState) => {
payoutFulfillBody.payout_id = globalState.get("payoutID");

cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}/fulfill`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
body: payoutFulfillBody,
}).then((response) => {
logRequestId(response.headers['x-request-id']);

expect(res_data.status).to.equal(response.status);
expect(response.headers["content-type"]).to.include("application/json");

if(response.status === 200){
for(const key in res_data.body) {
expect(res_data.body[key]).to.equal(response.body[key]);
}
}
else{
expect(response.body).to.have.property("error");
for(const key in res_data.body.error) {
expect(res_data.body.error[key]).to.equal(response.body.error[key]);
}
}
});
});

Cypress.Commands.add("updatePayoutCallTest", (payoutConfirmBody, req_data, res_data, auto_fulfill, globalState) => {
payoutConfirmBody.confirm = true;
payoutConfirmBody.auto_fulfill = auto_fulfill;



cy.request({
method: "PUT",
url: `${globalState.get("baseUrl")}/payouts/${globalState.get("payoutID")}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
body: payoutConfirmBody,
}).then((response) => {
logRequestId(response.headers['x-request-id']);

expect(res_data.status).to.equal(response.status);
expect(response.headers["content-type"]).to.include("application/json");

if(response.status === 200){
for(const key in res_data.body) {
expect(res_data.body[key]).to.equal(response.body[key]);
}
}
else{

expect(response.body).to.have.property("error");
for(const key in res_data.body.error) {
expect(res_data.body.error[key]).to.equal(response.body.error[key]);
}
}
});
});

Cypress.Commands.add("retrievePayoutCallTest", (globalState) => {
const payout_id = globalState.get("payoutID");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/payouts/${payout_id}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers['x-request-id']);

expect(response.headers["content-type"]).to.include("application/json");
expect(response.body.payout_id).to.equal(payout_id);
expect(response.body.amount).to.equal(globalState.get("payoutAmount"));
});
});

0 comments on commit 85b147e

Please sign in to comment.