All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.cjs.cypress-utils.utils.organization.js Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createOrganization = void 0;
var _common = require("./common");
var _routes = require("../constants/routes");
var _common2 = require("../constants/selectors/common");
var _signUp = require("../constants/selectors/signUp");
var _signUp2 = require("../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(_signUp.signUpSelectors.subdomainError, function () {
    cy.get(_signUp.signUpSelectors.subdomainError).invoke("text").then(function (text) {
      cy.intercept({
        url: _routes.requestApis.subdomainAvailability,
        times: 1
      }).as("subdomainRequest");
      var newOrganizationName = extractSubdomainFromError(text);
      cy.clearAndType(_signUp.signUpSelectors.subdomainNameTextField, newOrganizationName);
      cy.wait("@subdomainRequest");
      cy.ifNotExist(_signUp.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(_common.env.tld);
        Cypress.config("baseUrl", newBaseUrl);
        cy.clearAndType(_signUp.signUpSelectors.organizationNameTextField, newOrganizationName);
      });
    });
    cy.ifExist(_signUp.signUpSelectors.subdomainError, function () {
      return updateSubdomainIfExists(appName);
    });
  });
};
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(_common.env.tld, "/signups/new");
  isNeetoAuth ? cy.visit(authUrl) : cy.visit("".concat(authUrl, "?redirect_uri=").concat(appNameInLowerCase, ".").concat(_common.env.tld));
  cy.clearAndType(_signUp.signUpSelectors.emailTextField, email);
  cy.intercept({
    url: _routes.requestApis.signUp,
    times: 2
  }).as("signupRequest");
  cy.get(_signUp.signUpSelectors.submitButton).click();
  cy.wait("@signupRequest");
  if (isMailosaurEmail) {
    cy.getEmailContent({
      sentTo: email,
      subject: _signUp2.signUpTexts.loginCode
    }).then(function (emailBody) {
      var otp = emailBody.html.codes[0].value;
      cy.get(_signUp.signUpSelectors.otpTextBox).type(otp);
    });
  } else cy.get(_signUp.signUpSelectors.otpTextBox).type(defaultOtp);
  cy.wait("@signupRequest");
  cy.intercept({
    url: _routes.requestApis.subdomainAvailability,
    times: 1
  }).as("subdomainRequest");
  cy.clearAndType(_signUp.signUpSelectors.organizationNameTextField, businessName);
  cy.clearAndType(_signUp.signUpSelectors.subdomainNameTextField, subdomainName);
  cy.wait("@subdomainRequest");
  updateSubdomainIfExists(appNameInLowerCase);
  cy.intercept({
    url: _routes.requestApis.signUp,
    times: 1
  }).as("signupRequest");
  cy.intercept({
    url: _routes.requestApis.countries,
    times: 1
  }).as("fetchCountries");
  cy.get(_signUp.signUpSelectors.organizationSubmitButton).click();
  cy.wait("@signupRequest");
  cy.url({
    timeout: 15000
  }).should("include", _signUp2.signUpTexts.profile);
  cy.wait("@fetchCountries");
  cy.clearAndType(_signUp.signUpSelectors.firstNameTextField, firstName);
  cy.clearAndType(_signUp.signUpSelectors.lastNameTextField, lastName);
  cy.get(_common2.commonSelectors.checkbox).click();
  cy.intercept({
    url: _routes.requestApis.signUp,
    times: 1
  }).as("setupProfile");
  cy.get(_signUp.signUpSelectors.profileSubmitButton).click();
  cy.wait("@setupProfile");
};
exports.createOrganization = createOrganization;
//# sourceMappingURL=organization.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy