package.cypress-utils.utils.organization.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
import { env } from "./common";
import { requestApis } from "../constants/routes";
import { commonSelectors } from "../constants/selectors/common";
import { signUpSelectors } from "../constants/selectors/signUp";
import { signUpTexts } from "../constants/texts/signUp";
var extractSubdomainFromError = function extractSubdomainFromError(inputString) {
var regex = /cpt[a-zA-Z0-9-]+/g;
var matches = inputString.match(regex);
return matches[1];
};
var _updateSubdomainIfExists = function updateSubdomainIfExists(appName) {
cy.ifExist(signUpSelectors.subdomainError, function () {
cy.get(signUpSelectors.subdomainError).invoke("text").then(function (text) {
cy.intercept({
url: requestApis.subdomainAvailability,
times: 1
}).as("subdomainRequest");
var newOrganizationName = extractSubdomainFromError(text);
cy.clearAndType(signUpSelectors.subdomainNameTextField, newOrganizationName);
cy.wait("@subdomainRequest");
cy.ifNotExist(signUpSelectors.subdomainError, function () {
cy.task("updateGlobalState", {
key: "subdomainName",
value: newOrganizationName
});
cy.task("updateGlobalState", {
key: "businessName",
value: newOrganizationName
});
var newBaseUrl = "https://".concat(newOrganizationName, ".").concat(appName, ".").concat(env.tld);
Cypress.config("baseUrl", newBaseUrl);
cy.clearAndType(signUpSelectors.organizationNameTextField, newOrganizationName);
});
});
cy.ifExist(signUpSelectors.subdomainError, function () {
return _updateSubdomainIfExists(appName);
});
});
};
export var createOrganization = function createOrganization(_ref) {
var email = _ref.email,
businessName = _ref.businessName,
subdomainName = _ref.subdomainName,
firstName = _ref.firstName,
lastName = _ref.lastName,
appName = _ref.appName;
var isMailosaurEmail = email.includes("mailosaur");
var defaultOtp = "123456";
var appNameInLowerCase = appName.toLowerCase();
var isNeetoAuth = appNameInLowerCase === "neetoauth";
var authUrl = "https://app.neetoauth.".concat(env.tld, "/signups/new");
isNeetoAuth ? cy.visit(authUrl) : cy.visit("".concat(authUrl, "?redirect_uri=").concat(appNameInLowerCase, ".").concat(env.tld));
cy.clearAndType(signUpSelectors.emailTextField, email);
cy.intercept({
url: requestApis.signUp,
times: 2
}).as("signupRequest");
cy.get(signUpSelectors.submitButton).click();
cy.wait("@signupRequest");
if (isMailosaurEmail) {
cy.getEmailContent({
sentTo: email,
subject: signUpTexts.loginCode
}).then(function (emailBody) {
var otp = emailBody.html.codes[0].value;
cy.get(signUpSelectors.otpTextBox).type(otp);
});
} else cy.get(signUpSelectors.otpTextBox).type(defaultOtp);
cy.wait("@signupRequest");
cy.intercept({
url: requestApis.subdomainAvailability,
times: 1
}).as("subdomainRequest");
cy.clearAndType(signUpSelectors.organizationNameTextField, businessName);
cy.clearAndType(signUpSelectors.subdomainNameTextField, subdomainName);
cy.wait("@subdomainRequest");
_updateSubdomainIfExists(appNameInLowerCase);
cy.intercept({
url: requestApis.signUp,
times: 1
}).as("signupRequest");
cy.intercept({
url: requestApis.countries,
times: 1
}).as("fetchCountries");
cy.get(signUpSelectors.organizationSubmitButton).click();
cy.wait("@signupRequest");
cy.url({
timeout: 15000
}).should("include", signUpTexts.profile);
cy.wait("@fetchCountries");
cy.clearAndType(signUpSelectors.firstNameTextField, firstName);
cy.clearAndType(signUpSelectors.lastNameTextField, lastName);
cy.get(commonSelectors.checkbox).click();
cy.intercept({
url: requestApis.signUp,
times: 1
}).as("setupProfile");
cy.get(signUpSelectors.profileSubmitButton).click();
cy.wait("@setupProfile");
};
//# sourceMappingURL=organization.js.map