fix for flaky change user email tests and refactor of plugins tests (#2302)

* fix for flaky chane user email tests and refactor of plugins tests

* adding an option to run plugin tests in pull_request_temple
This commit is contained in:
Ewa Czerniak 2022-09-15 07:34:31 +00:00 committed by GitHub
parent a4804e2f3d
commit 65388acb0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 44 deletions

View file

@ -48,5 +48,6 @@ Tests will be re-run only when the "run e2e" label is added.
16. [ ] orders
17. [ ] products
18. [ ] app
19. [ ] plugins
CONTAINERS=1

View file

@ -7,7 +7,6 @@ import { PLUGINS_DETAILS } from "../../../elements/plugins/pluginDetails";
import { PLUGINS_LIST } from "../../../elements/plugins/pluginsList";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { urlList } from "../../../fixtures/urlList";
import { createChannel } from "../../../support/api/requests/Channels";
import {
customerRegistration,
deleteCustomersStartsWith,
@ -18,20 +17,20 @@ import {
getDefaultChannel,
} from "../../../support/api/utils/channelsUtils";
import {
getMailActivationLinkForUserAndSubject,
getMailsForUser,
getMailWithResetPasswordLink,
} from "../../../support/api/utils/users";
describe("Plugins", () => {
describe("As an admin I want to manage plugins", () => {
const startsWith = "Plugins";
const randomName = `${startsWith}${faker.datatype.number()}`;
let defaultChannel;
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteCustomersStartsWith(startsWith);
deleteChannelsStartsWith(startsWith);
createChannel({ name: randomName });
getDefaultChannel().then(channel => (defaultChannel = channel));
});
@ -42,9 +41,15 @@ describe("Plugins", () => {
.expectSkeletonIsVisible();
});
it("should change user email", { tags: ["@plugins", "@stagedOnly"] }, () => {
it(
"should change user email. TC: SALEOR_3601",
{ tags: ["@plugins", "@stagedOnly", "@stable"] },
() => {
const customerEmail = `${randomName}@example.com`;
cy.contains(PLUGINS_LIST.pluginRow, "User emails").click();
cy.contains(PLUGINS_LIST.pluginRow, "User emails")
.click()
.waitForProgressBarToNotBeVisible();
cy.contains(PLUGINS_DETAILS.channel, defaultChannel.name)
.click()
.get(PLUGINS_DETAILS.accountConfirmationSubjectInput)
@ -55,39 +60,32 @@ describe("Plugins", () => {
customerRegistration({
email: customerEmail,
channel: defaultChannel.slug,
})
.then(() => {
getMailsForUser(customerEmail);
})
.then(mails => {
expect(mails[0].Content.Headers.Subject[0]).to.eq(randomName);
});
});
getMailsForUser(customerEmail)
.its("0.Content.Headers.Subject.0")
.should("eq", randomName);
},
);
it(
"should change admin email plugin",
{ tags: ["@plugins", "@stagedOnly"] },
"should change admin email plugin. TC: SALEOR_3602",
{ tags: ["@plugins", "@stagedOnly", "@stable"] },
() => {
const customerEmail = `${randomName}@example.com`;
const adminName = `Admin${randomName}`;
cy.contains(PLUGINS_LIST.pluginRow, "Admin emails")
.click()
.get(PLUGINS_DETAILS.staffPasswordResetInput)
.click()
.clear()
.clearAndType(randomName)
.clearAndType(adminName)
.get(BUTTON_SELECTORS.confirm)
.click()
.confirmationMessageShouldDisappear();
requestPasswordReset(Cypress.env("USER_NAME"), defaultChannel.slug)
.then(() => {
getMailActivationLinkForUserAndSubject(
Cypress.env("USER_NAME"),
randomName,
);
})
.then(link => {
expect(link).to.be.ok;
});
requestPasswordReset(Cypress.env("USER_NAME"), defaultChannel.slug);
getMailWithResetPasswordLink(Cypress.env("USER_NAME"), adminName)
.its("0.Content.Headers.Subject.0")
.should("contains", adminName);
},
);
});

View file

@ -5,7 +5,7 @@ export function inviteStaffMemberWithFirstPermission({
email,
isActive = true,
firstName = "",
lastName = ""
lastName = "",
}) {
return getPermissionsArray(1).then(permissions => {
inviteStaffMember({
@ -13,7 +13,7 @@ export function inviteStaffMemberWithFirstPermission({
lastName,
email,
isActive,
permissionId: permissions[0].node.id
permissionId: permissions[0].node.id,
});
});
}
@ -68,7 +68,7 @@ export function getMailActivationLinkForUserAndSubject(email, subject, i = 0) {
const urlRegex = /\[([^\]]*)\]/;
const bodyWithoutWhiteSpaces = body.replace(
/(\r\n|\n|\r|\s)/gm,
""
"",
);
return urlRegex.exec(bodyWithoutWhiteSpaces)[1];
});
@ -78,13 +78,28 @@ export function getMailActivationLinkForUserAndSubject(email, subject, i = 0) {
});
}
export function getMailWithResetPasswordLink(email, subject, i = 0) {
if (i > 5) {
throw new Error(`There is no email with reset password for user ${email}`);
}
return cy.mhGetMailsByRecipient(email).should(mails => {
if (!mails.length) {
cy.wait(3000);
getMailWithResetPasswordLink(email, subject, i + 1);
} else {
cy.mhGetMailsBySubject(subject);
return mails;
}
});
}
export function getMailsForUser(email, i = 0) {
if (i > 3) {
if (i > 5) {
throw new Error(`There is no email invitation for user ${email}`);
}
return cy.mhGetMailsByRecipient(email).should(mails => {
if (!mails.length) {
cy.wait(10000);
cy.wait(3000);
getMailsForUser(email, i + 1);
} else {
return mails;