Repository: juspay/hyperswitch
File: cypress-tests/cypress/support/commands.js (JavaScript)

Code before:
    cy.wrap(response).then(() => {
      if (response.status === 200) {
        expect(response.body.amount_capturable, "amount_capturable").to.equal(
          resData.body.amount_capturable
        );
        expect(
          response.body.authorization_count,
          "authorization_count"
        ).to.be.a("number").and.not.be.null;
        expect(
          response.body.incremental_authorization_allowed,
          "incremental_authorization_allowed"
        ).to.be.true;
        expect(
          response.body.incremental_authorizations,
          "incremental_authorizations"
        ).to.be.an("array").and.not.be.empty;
        expect(response.body.payment_id, "payment_id").to.equal(paymentId);
        expect(response.body.status, "status").to.equal(resData.body.status);

        for (const key in response.body.incremental_authorizations) {
          expect(response.body.incremental_authorizations[key], "amount")
            .to.have.property("amount")
            .to.be.a("number")
            .to.equal(resData.body.amount).and.not.be.null;
          if (!resData.body.is_error_code_expected) {
            expect(
              response.body.incremental_authorizations[key],
              "error_code"
            ).to.have.property("error_code").to.be.null;
            expect(
              response.body.incremental_authorizations[key],
              "error_message"
            ).to.have.property("error_message").to.be.null;
          }
          expect(
            response.body.incremental_authorizations[key],
            "previously_authorized_amount"
          )
            .to.have.property("previously_authorized_amount")
            .to.be.a("number")
            .to.equal(
              response.body.incremental_authorizations[key]
                .previously_authorized_amount
            ).and.not.be.null;
          if (resData.body.is_error_code_expected) {
            expect(response.body.incremental_authorizations[key], "status")
              .to.have.property("status")
              .to.equal("failure");
          } else {
            expect(response.body.incremental_authorizations[key], "status")

Review comment (security):
`is_error_code_expected` has been used from the cypress connector configs to use it as a flag over here, which is not how it should work.

I would rather suggest you check what `response.body.incremental_authorizations[key].status` is, and map it accordingly.

Code after:
    cy.wrap(response).then(() => {
      if (response.status === 200) {
        expect(response.body.amount_capturable, "amount_capturable").to.equal(
          resData.body.amount_capturable
        );
        expect(
          response.body.authorization_count,
          "authorization_count"
        ).to.be.a("number").and.not.be.null;
        expect(
          response.body.incremental_authorization_allowed,
          "incremental_authorization_allowed"
        ).to.be.true;
        expect(
          response.body.incremental_authorizations,
          "incremental_authorizations"
        ).to.be.an("array").and.not.be.empty;
        expect(response.body.payment_id, "payment_id").to.equal(paymentId);
        expect(response.body.status, "status").to.equal(resData.body.status);

        for (const key in response.body.incremental_authorizations) {
          expect(response.body.incremental_authorizations[key], "amount")
            .to.have.property("amount")
            .to.be.a("number")
            .to.equal(resData.body.amount).and.not.be.null;
          if (
            response.body.incremental_authorizations[key].status === "failure"
          ) {
            expect(response.body.incremental_authorizations[key], "error_code")
              .to.have.property("error_code")
              .to.be.equal(
                resData.body.incremental_authorizations[key].error_code
              );
            expect(
              response.body.incremental_authorizations[key],
              "error_message"
            )
              .to.have.property("error_message")
              .to.be.equal(
                resData.body.incremental_authorizations[key].error_message
              );
            expect(response.body.incremental_authorizations[key], "status")
              .to.have.property("status")
              .to.equal("failure");
          } else {
            expect(
              response.body.incremental_authorizations[key],
              "error_code"
            ).to.have.property("error_code").to.be.null;
            expect(
              response.body.incremental_authorizations[key],