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 = "",
|
|
|
|
lastName = ""
|
|
|
|
}) {
|
|
|
|
return getPermissionsArray(1).then(permissions => {
|
|
|
|
inviteStaffMember({
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
email,
|
|
|
|
isActive,
|
|
|
|
permissionId: permissions[0].node.id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
export function getMailActivationLinkForUser(email, i = 0) {
|
|
|
|
if (i > 3) {
|
|
|
|
throw new Error(`There is no email invitation for user ${email}`);
|
|
|
|
}
|
|
|
|
return cy.mhGetMailsByRecipient(email).should(mails => {
|
|
|
|
if (!mails.length) {
|
2021-07-26 09:58:47 +00:00
|
|
|
cy.wait(10000);
|
2021-06-07 11:35:53 +00:00
|
|
|
getMailActivationLinkForUser(email, i + 1);
|
|
|
|
} else {
|
|
|
|
cy.wrap(mails)
|
|
|
|
.mhFirst()
|
|
|
|
.should("not.eq", undefined)
|
|
|
|
.mhGetBody()
|
|
|
|
.then(body => {
|
|
|
|
const urlRegex = /\[([^\]]*)\]/;
|
|
|
|
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) {
|
|
|
|
if (i > 3) {
|
|
|
|
throw new Error(`There is no email invitation for user ${email}`);
|
|
|
|
}
|
|
|
|
return cy.mhGetMailsByRecipient(email).should(mails => {
|
|
|
|
if (!mails.length) {
|
|
|
|
cy.wait(10000);
|
|
|
|
getMailActivationLinkForUserAndSubject(email, subject, i + 1);
|
|
|
|
} else {
|
|
|
|
cy.wrap(mails)
|
|
|
|
.mhGetMailsBySubject(subject)
|
|
|
|
.should(mailsWithSubject => {
|
|
|
|
if (!mailsWithSubject.length) {
|
|
|
|
cy.wait(10000);
|
|
|
|
getMailActivationLinkForUserAndSubject(email, subject, i + 1);
|
|
|
|
} else {
|
|
|
|
cy.wrap(mailsWithSubject)
|
|
|
|
.mhFirst()
|
|
|
|
.should("not.eq", undefined)
|
|
|
|
.mhGetBody()
|
|
|
|
.then(body => {
|
|
|
|
const urlRegex = /\[([^\]]*)\]/;
|
|
|
|
const bodyWithoutWhiteSpaces = body.replace(
|
|
|
|
/(\r\n|\n|\r|\s)/gm,
|
|
|
|
""
|
|
|
|
);
|
|
|
|
return urlRegex.exec(bodyWithoutWhiteSpaces)[1];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-10 09:03:42 +00:00
|
|
|
export function getMailsForUser(email, i = 0) {
|
|
|
|
if (i > 3) {
|
|
|
|
throw new Error(`There is no email invitation for user ${email}`);
|
|
|
|
}
|
|
|
|
return cy.mhGetMailsByRecipient(email).should(mails => {
|
|
|
|
if (!mails.length) {
|
|
|
|
cy.wait(10000);
|
2021-12-05 15:03:29 +00:00
|
|
|
getMailsForUser(email, 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
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|