{"size": 655, "ext": "js", "max_stars_repo_path": "cypress/support/commands/stubJSONResponses.js", "max_stars_repo_name": "AptoPayments/apto-pci-sdk-web", "max_stars_repo_stars_event_min_datetime": "2020-06-03T14:18:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-03T14:18:48.000Z", "max_issues_repo_path": "cypress/support/commands/stubJSONResponses.js", "max_issues_repo_name": "AptoPayments/apto-pci-sdk-web", "max_issues_repo_issues_event_min_datetime": "2020-09-10T17:39:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-22T09:33:28.000Z", "max_forks_repo_path": "cypress/support/commands/stubJSONResponses.js", "max_forks_repo_name": "AptoPayments/apto-pci-sdk-web", "max_forks_repo_forks_event_min_datetime": "2022-01-20T04:06:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-20T04:06:59.000Z"}
{"max_stars_count": 1, "max_issues_count": 49, "max_forks_count": 1, "avg_line_length": 24.2592592593, "max_line_length": 77, "alphanum_fraction": 0.6992366412}
Cypress.Commands.add("stubJSONResponse", stubJSONResponse);

function stubJSONResponse(options) {
	const { httpStatus, body } = options;
	cy.intercept("*", {
		statusCode: httpStatus,
		body: JSON.stringify(body),
	});
}

Cypress.Commands.add("stubMultipleJSONResponses", stubMultipleJSONResponses);

function stubMultipleJSONResponses(optsArray) {
	let requestIndex = 0;
	cy.intercept("*", (req) => {
		const options = optsArray[requestIndex]
			? optsArray[requestIndex]
			: { httpStatus: 400, body: {} };
		const { httpStatus, body } = options;
		req.reply({
			statusCode: httpStatus,
			body: JSON.stringify(body),
		});
		requestIndex += 1;
	});
}
