2021-09-27 10:04:21 +00:00
|
|
|
import { getPermissionsArray } from "../requests/Permissions";
|
|
|
|
import { inviteStaffMember } from "../requests/StaffMembers";
|
2021-06-07 11:35:53 +00:00
|
|
|
|
|
|
|
export function inviteStaffMemberWithFirstPermission({
|
|
|
|
email,
|
|
|
|
isActive = true,
|
|
|
|
firstName = "",
|
2022-09-15 07:34:31 +00:00
|
|
|
lastName = "",
|
2021-06-07 11:35:53 +00:00
|
|
|
}) {
|
|
|
|
return getPermissionsArray(1).then(permissions => {
|
|
|
|
inviteStaffMember({
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
email,
|
|
|
|
isActive,
|
2022-09-15 07:34:31 +00:00
|
|
|
permissionId: permissions[0].node.id,
|
2021-06-07 11:35:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-05-10 10:13:52 +00:00
|
|
|
* Function mpGetMailsByRecipient first get all emails from mailpit with a timeout, and after that it finds email from recipient.
|
2021-06-07 11:35:53 +00:00
|
|
|
* It cloud happened that invite email from saleor has not been received yet, so in this case the action should be retried.
|
|
|
|
*/
|
2022-11-16 12:44:34 +00:00
|
|
|
export function getMailActivationLinkForUser(email, regex, i = 0) {
|
2022-12-07 09:52:39 +00:00
|
|
|
const serverStoredEmail = email.toLowerCase();
|
|
|
|
|
2022-11-16 12:44:34 +00:00
|
|
|
const urlRegex = regex ? regex : /\[\w*password\w*\]\(([^\)]*)/;
|
2021-06-07 11:35:53 +00:00
|
|
|
if (i > 3) {
|
2022-12-07 09:52:39 +00:00
|
|
|
throw new Error(
|
|
|
|
`There is no email invitation for user ${serverStoredEmail}`,
|
|
|
|
);
|
2021-06-07 11:35:53 +00:00
|
|
|
}
|
2023-05-10 10:13:52 +00:00
|
|
|
return cy.mpGetMailsByRecipient(serverStoredEmail).then(mails => {
|
2021-06-07 11:35:53 +00:00
|
|
|
if (!mails.length) {
|
2021-07-26 09:58:47 +00:00
|
|
|
cy.wait(10000);
|
2022-12-07 09:52:39 +00:00
|
|
|
getMailActivationLinkForUser(serverStoredEmail, regex, i + 1);
|
2021-06-07 11:35:53 +00:00
|
|
|
} else {
|
|
|
|
cy.wrap(mails)
|
2023-05-10 10:13:52 +00:00
|
|
|
.mpLatest()
|
2021-06-07 11:35:53 +00:00
|
|
|
.should("not.eq", undefined)
|
2023-05-10 10:13:52 +00:00
|
|
|
.mpGetMailDetails()
|
|
|
|
.its("Text")
|
2021-06-07 11:35:53 +00:00
|
|
|
.then(body => {
|
|
|
|
const bodyWithoutWhiteSpaces = body.replace(/(\r\n|\n|\r|\s)/gm, "");
|
|
|
|
return urlRegex.exec(bodyWithoutWhiteSpaces)[1];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-09-10 09:03:42 +00:00
|
|
|
|
2021-12-05 15:03:29 +00:00
|
|
|
export function getMailActivationLinkForUserAndSubject(email, subject, i = 0) {
|
2022-12-07 09:52:39 +00:00
|
|
|
const serverStoredEmail = email.toLowerCase();
|
|
|
|
|
2021-12-05 15:03:29 +00:00
|
|
|
if (i > 3) {
|
2022-12-07 09:52:39 +00:00
|
|
|
throw new Error(
|
|
|
|
`There is no email invitation for user ${serverStoredEmail}`,
|
|
|
|
);
|
2021-12-05 15:03:29 +00:00
|
|
|
}
|
2023-05-10 10:13:52 +00:00
|
|
|
return cy.mpGetMailsByRecipient(serverStoredEmail).then(mails => {
|
2021-12-05 15:03:29 +00:00
|
|
|
if (!mails.length) {
|
|
|
|
cy.wait(10000);
|
2022-12-07 09:52:39 +00:00
|
|
|
getMailActivationLinkForUserAndSubject(serverStoredEmail, subject, i + 1);
|
2021-12-05 15:03:29 +00:00
|
|
|
} else {
|
|
|
|
cy.wrap(mails)
|
2023-05-10 10:13:52 +00:00
|
|
|
.mpGetMailsBySubject(subject)
|
2023-01-27 15:27:49 +00:00
|
|
|
.then(mailsWithSubject => {
|
2021-12-05 15:03:29 +00:00
|
|
|
if (!mailsWithSubject.length) {
|
|
|
|
cy.wait(10000);
|
2022-12-07 09:52:39 +00:00
|
|
|
getMailActivationLinkForUserAndSubject(
|
|
|
|
serverStoredEmail,
|
|
|
|
subject,
|
|
|
|
i + 1,
|
|
|
|
);
|
2021-12-05 15:03:29 +00:00
|
|
|
} else {
|
|
|
|
cy.wrap(mailsWithSubject)
|
2023-05-10 10:13:52 +00:00
|
|
|
.mpLatest()
|
2021-12-05 15:03:29 +00:00
|
|
|
.should("not.eq", undefined)
|
2023-05-10 10:13:52 +00:00
|
|
|
.mpGetMailDetails()
|
|
|
|
.its("Text")
|
2021-12-05 15:03:29 +00:00
|
|
|
.then(body => {
|
2022-10-20 12:07:45 +00:00
|
|
|
const urlRegex = /\[\w*password\w*\]\(([^\)]*)/;
|
2021-12-05 15:03:29 +00:00
|
|
|
const bodyWithoutWhiteSpaces = body.replace(
|
|
|
|
/(\r\n|\n|\r|\s)/gm,
|
2022-09-15 07:34:31 +00:00
|
|
|
"",
|
2021-12-05 15:03:29 +00:00
|
|
|
);
|
|
|
|
return urlRegex.exec(bodyWithoutWhiteSpaces)[1];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-15 07:34:31 +00:00
|
|
|
export function getMailWithResetPasswordLink(email, subject, i = 0) {
|
2022-12-07 09:52:39 +00:00
|
|
|
const serverStoredEmail = email.toLowerCase();
|
|
|
|
|
2022-09-15 07:34:31 +00:00
|
|
|
if (i > 5) {
|
2022-12-07 09:52:39 +00:00
|
|
|
throw new Error(
|
|
|
|
`There is no email with reset password for user ${serverStoredEmail}`,
|
|
|
|
);
|
2022-09-15 07:34:31 +00:00
|
|
|
}
|
2023-05-10 10:13:52 +00:00
|
|
|
return cy.mpGetMailsByRecipient(serverStoredEmail).then(mails => {
|
2022-09-15 07:34:31 +00:00
|
|
|
if (!mails.length) {
|
|
|
|
cy.wait(3000);
|
2022-12-07 09:52:39 +00:00
|
|
|
getMailWithResetPasswordLink(serverStoredEmail, subject, i + 1);
|
2022-09-15 07:34:31 +00:00
|
|
|
} else {
|
2023-05-10 10:13:52 +00:00
|
|
|
cy.mpGetMailsBySubject(subject).then(resetPasswordMails => {
|
2023-01-27 15:27:49 +00:00
|
|
|
if (!resetPasswordMails.length) {
|
|
|
|
cy.wait(3000);
|
|
|
|
getMailWithResetPasswordLink(serverStoredEmail, subject, i + 1);
|
|
|
|
} else {
|
2023-05-11 13:44:26 +00:00
|
|
|
cy.wrap(resetPasswordMails).mpLatest().mpGetMailDetails();
|
2023-01-27 15:27:49 +00:00
|
|
|
}
|
|
|
|
});
|
2022-09-15 07:34:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-10 09:03:42 +00:00
|
|
|
export function getMailsForUser(email, i = 0) {
|
2022-12-07 09:52:39 +00:00
|
|
|
const serverStoredEmail = email.toLowerCase();
|
|
|
|
|
2022-09-15 07:34:31 +00:00
|
|
|
if (i > 5) {
|
2022-12-07 09:52:39 +00:00
|
|
|
throw new Error(
|
|
|
|
`There is no email invitation for user ${serverStoredEmail}`,
|
|
|
|
);
|
2021-09-10 09:03:42 +00:00
|
|
|
}
|
2023-05-10 10:13:52 +00:00
|
|
|
return cy.mpGetMailsByRecipient(serverStoredEmail).then(mails => {
|
2021-09-10 09:03:42 +00:00
|
|
|
if (!mails.length) {
|
2022-09-15 07:34:31 +00:00
|
|
|
cy.wait(3000);
|
2022-12-07 09:52:39 +00:00
|
|
|
getMailsForUser(serverStoredEmail, i + 1);
|
2021-09-10 09:03:42 +00:00
|
|
|
} else {
|
2021-12-05 15:03:29 +00:00
|
|
|
return mails;
|
2021-09-10 09:03:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-12-13 07:04:54 +00:00
|
|
|
|
|
|
|
export function getMailWithGiftCardExportWithAttachment(
|
|
|
|
email,
|
|
|
|
subject,
|
|
|
|
attachmentFileType,
|
|
|
|
i = 0,
|
|
|
|
) {
|
|
|
|
if (i > 5) {
|
|
|
|
throw new Error(`There is no email Gift Card export for user ${email}`);
|
|
|
|
}
|
2023-05-11 13:44:26 +00:00
|
|
|
return cy.mpGetMailsByRecipient(email).then(mails => {
|
2022-12-13 07:04:54 +00:00
|
|
|
if (!mails.length) {
|
|
|
|
cy.wait(3000);
|
|
|
|
getMailWithGiftCardExportWithAttachment(
|
|
|
|
email,
|
|
|
|
subject,
|
|
|
|
attachmentFileType,
|
|
|
|
i + 1,
|
|
|
|
);
|
|
|
|
} else {
|
2023-05-11 13:44:26 +00:00
|
|
|
cy.mpGetMailsBySubject(subject).then(mailsWithSubject => {
|
2022-12-13 07:04:54 +00:00
|
|
|
if (!mailsWithSubject.length) {
|
|
|
|
cy.wait(10000);
|
|
|
|
getMailWithGiftCardExportWithAttachment(
|
|
|
|
email,
|
|
|
|
subject,
|
|
|
|
attachmentFileType,
|
|
|
|
i + 1,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
cy.wrap(mailsWithSubject)
|
2023-05-11 13:44:26 +00:00
|
|
|
.mpLatest()
|
|
|
|
.mpGetMailDetails()
|
2022-12-13 07:04:54 +00:00
|
|
|
.should("not.eq", undefined)
|
2023-05-11 13:44:26 +00:00
|
|
|
.its("Text");
|
2022-12-13 07:04:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|