2021-09-27 10:04:21 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../support"/>
|
|
|
|
|
2021-07-23 09:46:44 +00:00
|
|
|
import faker from "faker";
|
|
|
|
|
2021-09-27 10:04:21 +00:00
|
|
|
import { CUSTOMER_DETAILS } from "../elements/customers/customer-details";
|
|
|
|
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
|
|
|
|
import { customerDetailsUrl } from "../fixtures/urlList";
|
2021-07-26 09:58:47 +00:00
|
|
|
import {
|
|
|
|
confirmAccount,
|
|
|
|
customerRegistration,
|
2022-06-27 16:49:35 +00:00
|
|
|
deleteCustomersStartsWith,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../support/api/requests/Customer";
|
|
|
|
import { getDefaultChannel } from "../support/api/utils/channelsUtils";
|
|
|
|
import { getMailActivationLinkForUser } from "../support/api/utils/users";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
|
|
|
describe("Tests for customer registration", () => {
|
|
|
|
const startsWith = "Registration";
|
|
|
|
const email = `${startsWith}${faker.datatype.number()}@example.com`;
|
|
|
|
|
|
|
|
let defaultChannel;
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
2021-07-26 09:58:47 +00:00
|
|
|
deleteCustomersStartsWith(startsWith);
|
2021-07-23 09:46:44 +00:00
|
|
|
getDefaultChannel().then(channel => {
|
|
|
|
defaultChannel = channel;
|
2023-01-16 13:55:38 +00:00
|
|
|
cy.checkIfDataAreNotNull({ defaultChannel });
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-25 10:32:28 +00:00
|
|
|
it("should register customer", { tags: ["@customer", "@allEnv"] }, () => {
|
2022-06-27 09:30:51 +00:00
|
|
|
const email = `${startsWith}${faker.datatype.number()}@example.com`;
|
|
|
|
customerRegistration({ email, channel: defaultChannel.slug });
|
2022-11-16 12:44:34 +00:00
|
|
|
const registrationLinkRegex = /\[(\s*http[^\]]*)\]/;
|
|
|
|
getMailActivationLinkForUser(email, registrationLinkRegex)
|
2022-06-27 09:30:51 +00:00
|
|
|
.then(urlLink => {
|
|
|
|
const tokenRegex = /token=(.*)/;
|
|
|
|
const token = urlLink.match(tokenRegex)[1];
|
|
|
|
cy.clearSessionData();
|
|
|
|
confirmAccount(email, token);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
cy.loginUserViaRequest("token", {
|
|
|
|
email,
|
2022-06-27 16:49:35 +00:00
|
|
|
password: Cypress.env("USER_PASSWORD"),
|
2022-06-27 09:30:51 +00:00
|
|
|
}).its("body.data.tokenCreate");
|
|
|
|
})
|
|
|
|
.then(({ errors, token }) => {
|
|
|
|
expect(errors.length).to.eq(0);
|
|
|
|
expect(token).to.be.ok;
|
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"shouldn't register customer with duplicated email",
|
|
|
|
{ tags: ["@customer", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const duplicatedEmail = Cypress.env("USER_NAME");
|
|
|
|
customerRegistration({
|
|
|
|
duplicatedEmail,
|
2022-06-27 16:49:35 +00:00
|
|
|
channel: defaultChannel.slug,
|
2021-07-23 09:46:44 +00:00
|
|
|
}).then(({ user, errors }) => {
|
|
|
|
expect(errors[0].field).to.eq("email");
|
|
|
|
expect(user).to.not.be.ok;
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should activate customer from dashboard",
|
|
|
|
{ tags: ["@customer", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
customerRegistration({ email, channel: defaultChannel.slug })
|
|
|
|
.then(({ user }) => {
|
|
|
|
cy.clearSessionData()
|
|
|
|
.loginUserViaRequest()
|
|
|
|
.visit(customerDetailsUrl(user.id))
|
|
|
|
.get(CUSTOMER_DETAILS.isActiveCheckbox)
|
|
|
|
.click()
|
|
|
|
.get(BUTTON_SELECTORS.confirm)
|
2021-09-27 10:04:21 +00:00
|
|
|
.click()
|
|
|
|
.confirmationMessageShouldDisappear()
|
|
|
|
.clearSessionData()
|
2021-07-23 09:46:44 +00:00
|
|
|
.loginUserViaRequest("token", {
|
|
|
|
email,
|
2022-06-27 16:49:35 +00:00
|
|
|
password: Cypress.env("USER_PASSWORD"),
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.its("body.data.tokenCreate");
|
|
|
|
})
|
|
|
|
.then(({ token, errors }) => {
|
|
|
|
expect(errors.length).to.eq(0);
|
|
|
|
expect(token).to.be.ok;
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|