Skip to content
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

[FEAT] Multiple credential support for a connector in Cypress #6645

Open
pixincreate opened this issue Nov 22, 2024 · 0 comments · May be fixed by #6588
Open

[FEAT] Multiple credential support for a connector in Cypress #6645

pixincreate opened this issue Nov 22, 2024 · 0 comments · May be fixed by #6588
Assignees
Labels
A-CI-CD Area: Continuous Integration/Deployment

Comments

@pixincreate
Copy link
Member

pixincreate commented Nov 22, 2024

Requirement

Execute cypress tests for a connector having multiple credentials which can be used for different scenarios (one api key for cards, another for bank redirects and etc.,).

Implementation

Introduce new format for creds.json

creds.json should include both the formats. if a connector requires us passing multiple credentials, then that connector api key object should include multiple connector_account_details object all named under a generic name connector_<number> where number is an integer.

Refer example given below for more clarity:

// connector having multiple credentials
<connector_name_1>: {
    "connector_1": {
        "connector_account_details": {
            "auth_type": "KeyType",
            "api_key": "",
            "api_secret": "",
            "key1": "",
            "key2": ""
        },
        "metadata": {}
    },
    "connector_2": {
        "connector_account_details": {
            "auth_type": "KeyType",
            "api_key": "",
            "api_secret": "",
            "key1": "",
            "key2": ""
        },
        "metadata": {}
    },
},
// connector with a single credential
<connector_name_2>: {
	"connector_account_details": {
		"auth_type": "KeyType",
		"api_key": "",
		"api_secret": "",
		"key1": "",
		"key2": ""
	}
}

Introduce new object (Configs) for connector.js

Within connector.js, introduce new object called as Configs alongside to Request and Response where user can define flags to achieve granular control over what test is being run.

An example implementation given below for reference:

getCustomExchange({
	Configs: {
		TRIGGER_SKIP: true, // skips redirection flow from running. takes in a boolean
		DELAY: {
			STATUS: true, // flag to turn delay feature on or off. takes in a boolean
			TIMEOUT: 5000, // timeout in milliseconds
		},
		CONNECTOR_CREDENTIAL: connector_1 / connector_2 // flag to route tests to a specific profile
		// etc.,
	},
	Requst: {},
	Response: {}
}),

Modify getValueByKey function in Utils.js

Validate if connector_account_details dot exist within <connector> object in creds.
If it does not, start a loop and see if connector_account_details exist within every object. If true, return the connector_account_details while setting an object as a Cypress environment flag (MULTIPLE_CONNECTORS) with status true and length. If any validation fails, directly return the object (data[key]).

An example implementation given below for reference:

if (data && typeof data === "object" && key in data) {
	// Connector object has multiple keys
	if (typeof data[key].connector_account_details === "undefined") {
		const keys = Object.keys(data[key]);

		for (let i = 0; i < keys.length; i++) {
			const currentItem = data[key][keys[i]];

			if (currentItem.hasOwnProperty("connector_account_details")) {
				Cypress.env("MULTIPLE_CONNECTORS", {
					status: true,
					count: keys.length,
				});

				return currentItem;
			}
		}
	}

	return data[key];
} else {
	return null;
}

Add a new test to MCA create call

If MULTIPLE_CONNECTORS.status is TRUE. Check MULTIPLE_CONNECTORS.count and create profile and mca beneath that profile based on the number of count.

An example of possible implementation given below for reference:

if (Cypress.env("MULTIPLE_CONNECTORS")?.status) {
	for (let i = 0; i < Cypress.env("MULTIPLE_CONNECTORS").count; i++) {
		cy.createBusinessProfileTest(
			createBusinessProfileBody,
			globalState,
			"profile" + i // new optional fields
		);
		cy.createConnectorCallTest(
			"payment_processor",
			createConnectorBody,
			payment_methods_enabled,
			globalState,
			"profile" + i, // new optional fields
			"merchantConnector" + i // new optional fields
		);
	}
}

Store these created profile_ids and mcas in globalState for future usage.
Pass CONNECTOR_CREDENTIAL value as connector_1 or connector_2 in <connector>.js
In commands.js, execute these configs before a request has been made.
execute here means to make these configs work.

Preferably, make this execution of configs a function and pass the values accordingly along with trace to find from where the function has been called.

Limitations

  • Cypress cannot call itself unless a wrapper around Cypress is written (Rustpress?)
    • This stops us from running the entire test suite against every credentials
    • One possible work around for this is to have multiple keys (cybersource_1, cybersource_2) but this will result in a lot of confusion
  • Current implementation requires the user to mandatorily pass a CONNECTOR_CREDENTIAL config to pass a different profileId
    • Hence, the tests will only run once but, specific tests like incremental auth will be forced to run against different credential
  • 00025-IncrementalAuth.cy.js can be stopped from execution based on MULTIPLE_CONNECTORS environment variable as it is set during run time and the file is read asynchronously when the execution starts (to address this, we will have to make a function call to see if it is set during run time and it is, then skip)
@pixincreate pixincreate added the A-CI-CD Area: Continuous Integration/Deployment label Nov 22, 2024
@pixincreate pixincreate added this to the November 2024 Release milestone Nov 22, 2024
@pixincreate pixincreate self-assigned this Nov 22, 2024
@pixincreate pixincreate linked a pull request Nov 22, 2024 that will close this issue
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CI-CD Area: Continuous Integration/Deployment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant