Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
test(cypress): add outgoing webhook custom headers coverage for stripe (#12195)
HS-QUALIBOTbc6e1f5e5373
diff --git a/cypress-tests/cypress/e2e/spec/Payment/28-BusinessProfileConfigs.cy.js b/cypress-tests/cypress/e2e/spec/Payment/28-BusinessProfileConfigs.cy.jsindex e6e6030d1b..d5e92669d2 100644--- a/cypress-tests/cypress/e2e/spec/Payment/28-BusinessProfileConfigs.cy.js+++ b/cypress-tests/cypress/e2e/spec/Payment/28-BusinessProfileConfigs.cy.js@@ -376,4 +376,67 @@ describe("Config Tests", () => {});});++ // Connector-agnostic: webhook headers are Business Profile config, not connector-specific+ context("Outgoing Webhook Custom HTTP Headers", () => {+ const shouldContinue = true;++ beforeEach(function () {+ if (!shouldContinue) {+ this.skip();+ }+ });++ it("Create Business Profile", () => {+ cy.createBusinessProfileTest(+ fixtures.businessProfile.bpCreate,+ globalState,+ "webhookProfile"+ );+ });++ it("Update business profile with custom webhook headers and verify masked response", () => {+ const webhookHeadersBody = {+ outgoing_webhook_custom_http_headers: {+ "X-Custom-Header": "long-custom-value-six-chars",+ "X-Short": "secret",+ "X-Tiny": "xy",+ },+ };+ cy.updateBusinessProfileWebhookCustomHeadersTest(+ webhookHeadersBody,+ globalState,+ "webhookProfile"+ );+ });++ it("Update business profile with new custom webhook headers and verify updated masked response", () => {+ const previousHeaderKeys = Object.keys(+ globalState.get("lastResponseHeaders") ?? {}+ );+ const webhookHeadersBody = {+ outgoing_webhook_custom_http_headers: {+ "X-Updated-Header": "updated-secret-value-long",+ "X-Another-Header": "another-long-value-string",+ },+ };+ cy.updateBusinessProfileWebhookCustomHeadersTest(+ webhookHeadersBody,+ globalState,+ "webhookProfile",+ previousHeaderKeys+ );+ });++ it("Clear custom webhook headers with empty object", () => {+ const webhookHeadersBody = {+ outgoing_webhook_custom_http_headers: {},+ };+ cy.updateBusinessProfileWebhookCustomHeadersTest(+ webhookHeadersBody,+ globalState,+ "webhookProfile"+ );+ });+ });});diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 355a1db9f1..d110a1db22 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -827,6 +827,69 @@ Cypress.Commands.add(});});++function maskValue(value) {+ if (value.length > 4) {+ return value.slice(0, 2) + "*".repeat(value.length - 4) + value.slice(-2);+ }+ return "*".repeat(value.length);+}++Cypress.Commands.add(+ "updateBusinessProfileWebhookCustomHeadersTest",+ (+ webhookHeadersBody,+ globalState,+ profilePrefix = "profile",+ previousHeaderKeys = null+ ) => {+ const apiKey = globalState.get("apiKey");+ const merchantId = globalState.get("merchantId");+ const profileId = globalState.get(`${profilePrefix}Id`);+ expect(+ profileId,+ "profileId must be set in globalState before calling this command"+ ).to.not.be.undefined;++ return cy+ .request({+ method: "POST",+ url: `${globalState.get("baseUrl")}/account/${merchantId}/business_profile/${profileId}`,+ headers: {+ Accept: "application/json",+ "Content-Type": "application/json",+ "api-key": apiKey,+ },+ body: webhookHeadersBody,+ failOnStatusCode: false,+ })+ .then((response) => {+ logRequestId(response.headers["x-request-id"]);+ expect(response.status).to.equal(200);+ const responseHeaders =+ response.body.outgoing_webhook_custom_http_headers;+ const requestHeaders =+ webhookHeadersBody.outgoing_webhook_custom_http_headers;++ if (Object.keys(requestHeaders).length === 0) {+ expect(responseHeaders ?? {}).to.deep.equal({});+ } else {+ expect(responseHeaders).to.not.be.undefined;+ for (const [key, value] of Object.entries(requestHeaders)) {+ const masked = maskValue(value);+ expect(responseHeaders).to.have.property(key, masked);+ }+ if (previousHeaderKeys) {+ previousHeaderKeys.forEach((key) => {+ expect(responseHeaders).to.not.have.property(key);+ });+ }+ }+ globalState.set("lastResponseHeaders", responseHeaders);+ });+ }+);+// API Key API callsCypress.Commands.add("apiKeyCreateTest", (apiKeyCreateBody, globalState) => {// Define the necessary variables and constant