From 2bbb458f56da217380ae73b0a651fe849c4459b5 Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Wed, 16 Nov 2022 13:44:34 +0100 Subject: [PATCH] Fix tests for customer registration and reset password (#2560) --- cypress/e2e/customerRegistration.js | 3 ++- cypress/e2e/staffMembers.js | 3 ++- cypress/plugins/index.js | 1 + cypress/support/api/utils/users.js | 6 +++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/customerRegistration.js b/cypress/e2e/customerRegistration.js index b24c61279..9f99245c9 100644 --- a/cypress/e2e/customerRegistration.js +++ b/cypress/e2e/customerRegistration.js @@ -31,7 +31,8 @@ describe("Tests for customer registration", () => { it("should register customer", { tags: ["@customer", "@stagedOnly"] }, () => { const email = `${startsWith}${faker.datatype.number()}@example.com`; customerRegistration({ email, channel: defaultChannel.slug }); - getMailActivationLinkForUser(email) + const registrationLinkRegex = /\[(\s*http[^\]]*)\]/; + getMailActivationLinkForUser(email, registrationLinkRegex) .then(urlLink => { const tokenRegex = /token=(.*)/; const token = urlLink.match(tokenRegex)[1]; diff --git a/cypress/e2e/staffMembers.js b/cypress/e2e/staffMembers.js index e1692af4c..caec8b870 100644 --- a/cypress/e2e/staffMembers.js +++ b/cypress/e2e/staffMembers.js @@ -9,7 +9,7 @@ import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; import { STAFF_MEMBER_DETAILS } from "../elements/staffMembers/staffMemberDetails"; import { STAFF_MEMBERS_LIST } from "../elements/staffMembers/staffMembersList"; import { urlList, userDetailsUrl } from "../fixtures/urlList"; -import { updatePlugin } from "../support/api/requests/Plugins"; +import { activatePlugin, updatePlugin } from "../support/api/requests/Plugins"; import { deleteStaffMembersStartsWith, updateStaffMember, @@ -37,6 +37,7 @@ describe("Staff members", () => { before(() => { cy.clearSessionData().loginUserViaRequest(); deleteStaffMembersStartsWith(startsWith); + activatePlugin({ id: "mirumee.notifications.admin_email" }); inviteStaffMemberWithFirstPermission({ email }) .then(({ user: userResp }) => { diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index 96582551e..314386b06 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -35,6 +35,7 @@ module.exports = async (on, config) => { config.env.SECOND_USER_NAME = process.env.CYPRESS_SECOND_USER_NAME; config.env.PERMISSIONS_USERS_PASSWORD = process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD; + config.env.mailHogUrl = process.env.CYPRESS_mailHogUrl; config.env.grepTags = process.env.CYPRESS_grepTags; on("before:browser:launch", ({}, launchOptions) => { diff --git a/cypress/support/api/utils/users.js b/cypress/support/api/utils/users.js index 8aa2e3c51..709fc950b 100644 --- a/cypress/support/api/utils/users.js +++ b/cypress/support/api/utils/users.js @@ -22,21 +22,21 @@ export function inviteStaffMemberWithFirstPermission({ * Function mhGetMailsByRecipient first get all emails from mailhog with a timeout, and after that it finds email from recipient. * It cloud happened that invite email from saleor has not been received yet, so in this case the action should be retried. */ -export function getMailActivationLinkForUser(email, i = 0) { +export function getMailActivationLinkForUser(email, regex, i = 0) { + const urlRegex = regex ? regex : /\[\w*password\w*\]\(([^\)]*)/; if (i > 3) { throw new Error(`There is no email invitation for user ${email}`); } return cy.mhGetMailsByRecipient(email).should(mails => { if (!mails.length) { cy.wait(10000); - getMailActivationLinkForUser(email, i + 1); + getMailActivationLinkForUser(email, regex, i + 1); } else { cy.wrap(mails) .mhFirst() .should("not.eq", undefined) .mhGetBody() .then(body => { - const urlRegex = /\[\w*password\w*\]\(([^\)]*)/; const bodyWithoutWhiteSpaces = body.replace(/(\r\n|\n|\r|\s)/gm, ""); return urlRegex.exec(bodyWithoutWhiteSpaces)[1]; });