expect email to lowercase in test assertions (#2796)

This commit is contained in:
Anna Szczęch 2022-12-07 10:52:39 +01:00 committed by GitHub
parent 20d79dce71
commit 443a94834e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 22 deletions

View file

@ -71,7 +71,9 @@ describe("Tests for customer", () => {
expect(customer.lastName, "Expect correct last name").to.eq( expect(customer.lastName, "Expect correct last name").to.eq(
randomName, randomName,
); );
expect(customer.email, "Expect correct email").to.eq(email); expect(customer.email, "Expect correct email").to.eq(
email.toLowerCase(),
);
expect(customer.note, "Expect correct note").to.eq(note); expect(customer.note, "Expect correct note").to.eq(note);
cy.expectCorrectFullAddress(customer.addresses[0], address); cy.expectCorrectFullAddress(customer.addresses[0], address);
}); });
@ -277,7 +279,7 @@ describe("Tests for customer", () => {
); );
expect(user.lastName, "Expect correct last name").to.eq(updatedName); expect(user.lastName, "Expect correct last name").to.eq(updatedName);
expect(user.email, "Expect correct email").to.eq( expect(user.email, "Expect correct email").to.eq(
`${updatedName}@example.com`, `${updatedName}@example.com`.toLowerCase(),
); );
expect(user.note, "Expect correct note").to.eq(updatedName); expect(user.note, "Expect correct note").to.eq(updatedName);
}); });

View file

@ -91,18 +91,22 @@ describe("Staff members", () => {
); );
it("should activate user", { tags: ["@staffMembers", "@stagedOnly"] }, () => { it("should activate user", { tags: ["@staffMembers", "@stagedOnly"] }, () => {
const serverStoredEmail = email.toLowerCase();
updateStaffMember({ userId: user.id, isActive: false }); updateStaffMember({ userId: user.id, isActive: false });
updateUserActiveFlag(user.id); updateUserActiveFlag(user.id);
cy.clearSessionData() cy.clearSessionData()
.loginUserViaRequest("auth", { email, password }) .loginUserViaRequest("auth", { email, password })
.visit(urlList.homePage); .visit(urlList.homePage);
expectWelcomeMessageIncludes(email); expectWelcomeMessageIncludes(serverStoredEmail);
}); });
it( it(
"should remove user permissions", "should remove user permissions",
{ tags: ["@staffMembers", "@stagedOnly"] }, { tags: ["@staffMembers", "@stagedOnly"] },
() => { () => {
const serverStoredEmail = email.toLowerCase();
cy.visit(userDetailsUrl(user.id)) cy.visit(userDetailsUrl(user.id))
.get(STAFF_MEMBER_DETAILS.removePermissionButton) .get(STAFF_MEMBER_DETAILS.removePermissionButton)
.click() .click()
@ -114,7 +118,7 @@ describe("Staff members", () => {
.clearSessionData() .clearSessionData()
.loginUserViaRequest("auth", { email, password }) .loginUserViaRequest("auth", { email, password })
.visit(urlList.homePage); .visit(urlList.homePage);
expectWelcomeMessageIncludes(email); expectWelcomeMessageIncludes(serverStoredEmail);
getDisplayedSelectors().then(displayedSelectors => { getDisplayedSelectors().then(displayedSelectors => {
expect(Object.values(displayedSelectors)).to.have.length(1); expect(Object.values(displayedSelectors)).to.have.length(1);
expect(Object.values(displayedSelectors)[0]).to.eq( expect(Object.values(displayedSelectors)[0]).to.eq(

View file

@ -1,14 +1,14 @@
import { import {
getDefaultAddress, getDefaultAddress,
getDefaultAddressWithoutType, getDefaultAddressWithoutType,
getValueWithDefault getValueWithDefault,
} from "./utils/Utils"; } from "./utils/Utils";
export function createCustomer(email, customerName, address, isActive = false) { export function createCustomer(email, customerName, address, isActive = false) {
const addressesLines = getValueWithDefault( const addressesLines = getValueWithDefault(
address, address,
`${getDefaultAddress(address, "defaultBillingAddress")} `${getDefaultAddress(address, "defaultBillingAddress")}
${getDefaultAddress(address, "defaultShippingAddress")}` ${getDefaultAddress(address, "defaultShippingAddress")}`,
); );
const mutation = ` const mutation = `
mutation{ mutation{
@ -76,7 +76,7 @@ export function getCustomers(startsWith) {
export function customerRegistration({ export function customerRegistration({
email, email,
password = Cypress.env("USER_PASSWORD"), password = Cypress.env("USER_PASSWORD"),
channel channel,
}) { }) {
const mutation = `mutation{ const mutation = `mutation{
accountRegister(input:{ accountRegister(input:{
@ -113,8 +113,10 @@ export function requestPasswordReset(email, channel) {
} }
export function confirmAccount(email, token) { export function confirmAccount(email, token) {
const serverStoredEmail = email.toLowerCase();
const mutation = `mutation{ const mutation = `mutation{
confirmAccount(email:"${email}", token:"${token}"){ confirmAccount(email:"${serverStoredEmail}", token:"${token}"){
user{ user{
email email
} }

View file

@ -23,14 +23,18 @@ export function inviteStaffMemberWithFirstPermission({
* 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, regex, i = 0) { export function getMailActivationLinkForUser(email, regex, i = 0) {
const serverStoredEmail = email.toLowerCase();
const urlRegex = regex ? regex : /\[\w*password\w*\]\(([^\)]*)/; 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 ${serverStoredEmail}`,
);
} }
return cy.mhGetMailsByRecipient(email).should(mails => { return cy.mhGetMailsByRecipient(serverStoredEmail).should(mails => {
if (!mails.length) { if (!mails.length) {
cy.wait(10000); cy.wait(10000);
getMailActivationLinkForUser(email, regex, i + 1); getMailActivationLinkForUser(serverStoredEmail, regex, i + 1);
} else { } else {
cy.wrap(mails) cy.wrap(mails)
.mhFirst() .mhFirst()
@ -45,20 +49,28 @@ export function getMailActivationLinkForUser(email, regex, i = 0) {
} }
export function getMailActivationLinkForUserAndSubject(email, subject, i = 0) { export function getMailActivationLinkForUserAndSubject(email, subject, i = 0) {
const serverStoredEmail = email.toLowerCase();
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 ${serverStoredEmail}`,
);
} }
return cy.mhGetMailsByRecipient(email).should(mails => { return cy.mhGetMailsByRecipient(serverStoredEmail).should(mails => {
if (!mails.length) { if (!mails.length) {
cy.wait(10000); cy.wait(10000);
getMailActivationLinkForUserAndSubject(email, subject, i + 1); getMailActivationLinkForUserAndSubject(serverStoredEmail, subject, i + 1);
} else { } else {
cy.wrap(mails) cy.wrap(mails)
.mhGetMailsBySubject(subject) .mhGetMailsBySubject(subject)
.should(mailsWithSubject => { .should(mailsWithSubject => {
if (!mailsWithSubject.length) { if (!mailsWithSubject.length) {
cy.wait(10000); cy.wait(10000);
getMailActivationLinkForUserAndSubject(email, subject, i + 1); getMailActivationLinkForUserAndSubject(
serverStoredEmail,
subject,
i + 1,
);
} else { } else {
cy.wrap(mailsWithSubject) cy.wrap(mailsWithSubject)
.mhFirst() .mhFirst()
@ -79,13 +91,17 @@ export function getMailActivationLinkForUserAndSubject(email, subject, i = 0) {
} }
export function getMailWithResetPasswordLink(email, subject, i = 0) { export function getMailWithResetPasswordLink(email, subject, i = 0) {
const serverStoredEmail = email.toLowerCase();
if (i > 5) { if (i > 5) {
throw new Error(`There is no email with reset password for user ${email}`); throw new Error(
`There is no email with reset password for user ${serverStoredEmail}`,
);
} }
return cy.mhGetMailsByRecipient(email).should(mails => { return cy.mhGetMailsByRecipient(serverStoredEmail).should(mails => {
if (!mails.length) { if (!mails.length) {
cy.wait(3000); cy.wait(3000);
getMailWithResetPasswordLink(email, subject, i + 1); getMailWithResetPasswordLink(serverStoredEmail, subject, i + 1);
} else { } else {
cy.mhGetMailsBySubject(subject); cy.mhGetMailsBySubject(subject);
return mails; return mails;
@ -94,13 +110,17 @@ export function getMailWithResetPasswordLink(email, subject, i = 0) {
} }
export function getMailsForUser(email, i = 0) { export function getMailsForUser(email, i = 0) {
const serverStoredEmail = email.toLowerCase();
if (i > 5) { if (i > 5) {
throw new Error(`There is no email invitation for user ${email}`); throw new Error(
`There is no email invitation for user ${serverStoredEmail}`,
);
} }
return cy.mhGetMailsByRecipient(email).should(mails => { return cy.mhGetMailsByRecipient(serverStoredEmail).should(mails => {
if (!mails.length) { if (!mails.length) {
cy.wait(3000); cy.wait(3000);
getMailsForUser(email, i + 1); getMailsForUser(serverStoredEmail, i + 1);
} else { } else {
return mails; return mails;
} }

View file

@ -12,7 +12,9 @@ export function finalizeDraftOrder(name) {
.get(DRAFT_ORDER_SELECTORS.selectCustomer) .get(DRAFT_ORDER_SELECTORS.selectCustomer)
.type(name); .type(name);
return cy return cy
.contains(DRAFT_ORDER_SELECTORS.selectCustomerOption, name) .contains(DRAFT_ORDER_SELECTORS.selectCustomerOption, name, {
matchCase: false,
})
.click() .click()
.get(DRAFT_ORDER_SELECTORS.customerEmail) .get(DRAFT_ORDER_SELECTORS.customerEmail)
.should("be.visible") .should("be.visible")