saleor-dashboard/cypress/support/api/utils/users.js
Karolina Rakoczy 2c64a966cc
Saleor 4437 refactor tests (#1389)
* reference type cypress working

* refactor

* remove screenshots

* add reference

* add slash marker

* run tests based on shop version

* fix run tests based on shop version

* fix run tests based on shop version

* change base url to localhost

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix yml

* fix yml

* chage file names

* fix files names

* fix broken imports add checking for errors in grpah responses

* fix broken imports add checking for errors in grpah responses

* update jest

* fix snapshot
2021-09-27 12:04:21 +02:00

59 lines
1.7 KiB
JavaScript

import { getPermissionsArray } from "../requests/Permissions";
import { inviteStaffMember } from "../requests/StaffMembers";
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) {
cy.wait(10000);
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];
});
}
});
}
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);
getEmailForUser(email, i + 1);
} else {
return mails[0].Content.Headers.Subject[0];
}
});
}