Fix tests for customer registration and reset password (#2560)

This commit is contained in:
Karolina Rakoczy 2022-11-16 13:44:34 +01:00 committed by GitHub
parent a64ea3609d
commit 2bbb458f56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 5 deletions

View file

@ -31,7 +31,8 @@ describe("Tests for customer registration", () => {
it("should register customer", { tags: ["@customer", "@stagedOnly"] }, () => { it("should register customer", { tags: ["@customer", "@stagedOnly"] }, () => {
const email = `${startsWith}${faker.datatype.number()}@example.com`; const email = `${startsWith}${faker.datatype.number()}@example.com`;
customerRegistration({ email, channel: defaultChannel.slug }); customerRegistration({ email, channel: defaultChannel.slug });
getMailActivationLinkForUser(email) const registrationLinkRegex = /\[(\s*http[^\]]*)\]/;
getMailActivationLinkForUser(email, registrationLinkRegex)
.then(urlLink => { .then(urlLink => {
const tokenRegex = /token=(.*)/; const tokenRegex = /token=(.*)/;
const token = urlLink.match(tokenRegex)[1]; const token = urlLink.match(tokenRegex)[1];

View file

@ -9,7 +9,7 @@ import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
import { STAFF_MEMBER_DETAILS } from "../elements/staffMembers/staffMemberDetails"; import { STAFF_MEMBER_DETAILS } from "../elements/staffMembers/staffMemberDetails";
import { STAFF_MEMBERS_LIST } from "../elements/staffMembers/staffMembersList"; import { STAFF_MEMBERS_LIST } from "../elements/staffMembers/staffMembersList";
import { urlList, userDetailsUrl } from "../fixtures/urlList"; import { urlList, userDetailsUrl } from "../fixtures/urlList";
import { updatePlugin } from "../support/api/requests/Plugins"; import { activatePlugin, updatePlugin } from "../support/api/requests/Plugins";
import { import {
deleteStaffMembersStartsWith, deleteStaffMembersStartsWith,
updateStaffMember, updateStaffMember,
@ -37,6 +37,7 @@ describe("Staff members", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
deleteStaffMembersStartsWith(startsWith); deleteStaffMembersStartsWith(startsWith);
activatePlugin({ id: "mirumee.notifications.admin_email" });
inviteStaffMemberWithFirstPermission({ email }) inviteStaffMemberWithFirstPermission({ email })
.then(({ user: userResp }) => { .then(({ user: userResp }) => {

View file

@ -35,6 +35,7 @@ module.exports = async (on, config) => {
config.env.SECOND_USER_NAME = process.env.CYPRESS_SECOND_USER_NAME; config.env.SECOND_USER_NAME = process.env.CYPRESS_SECOND_USER_NAME;
config.env.PERMISSIONS_USERS_PASSWORD = config.env.PERMISSIONS_USERS_PASSWORD =
process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD; process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD;
config.env.mailHogUrl = process.env.CYPRESS_mailHogUrl;
config.env.grepTags = process.env.CYPRESS_grepTags; config.env.grepTags = process.env.CYPRESS_grepTags;
on("before:browser:launch", ({}, launchOptions) => { on("before:browser:launch", ({}, launchOptions) => {

View file

@ -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. * 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. * 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) { if (i > 3) {
throw new Error(`There is no email invitation for user ${email}`); throw new Error(`There is no email invitation for user ${email}`);
} }
return cy.mhGetMailsByRecipient(email).should(mails => { return cy.mhGetMailsByRecipient(email).should(mails => {
if (!mails.length) { if (!mails.length) {
cy.wait(10000); cy.wait(10000);
getMailActivationLinkForUser(email, i + 1); getMailActivationLinkForUser(email, regex, i + 1);
} else { } else {
cy.wrap(mails) cy.wrap(mails)
.mhFirst() .mhFirst()
.should("not.eq", undefined) .should("not.eq", undefined)
.mhGetBody() .mhGetBody()
.then(body => { .then(body => {
const urlRegex = /\[\w*password\w*\]\(([^\)]*)/;
const bodyWithoutWhiteSpaces = body.replace(/(\r\n|\n|\r|\s)/gm, ""); const bodyWithoutWhiteSpaces = body.replace(/(\r\n|\n|\r|\s)/gm, "");
return urlRegex.exec(bodyWithoutWhiteSpaces)[1]; return urlRegex.exec(bodyWithoutWhiteSpaces)[1];
}); });