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 16. [ ] orders
17. [ ] products 17. [ ] products
18. [ ] app 18. [ ] app
19. [ ] plugins
CONTAINERS=1 CONTAINERS=1

View file

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

View file

@ -5,7 +5,7 @@ export function inviteStaffMemberWithFirstPermission({
email, email,
isActive = true, isActive = true,
firstName = "", firstName = "",
lastName = "" lastName = "",
}) { }) {
return getPermissionsArray(1).then(permissions => { return getPermissionsArray(1).then(permissions => {
inviteStaffMember({ inviteStaffMember({
@ -13,7 +13,7 @@ export function inviteStaffMemberWithFirstPermission({
lastName, lastName,
email, email,
isActive, 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 urlRegex = /\[([^\]]*)\]/;
const bodyWithoutWhiteSpaces = body.replace( const bodyWithoutWhiteSpaces = body.replace(
/(\r\n|\n|\r|\s)/gm, /(\r\n|\n|\r|\s)/gm,
"" "",
); );
return urlRegex.exec(bodyWithoutWhiteSpaces)[1]; 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) { export function getMailsForUser(email, i = 0) {
if (i > 3) { if (i > 5) {
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(3000);
getMailsForUser(email, i + 1); getMailsForUser(email, i + 1);
} else { } else {
return mails; return mails;