diff --git a/cypress/apiRequests/Customer.js b/cypress/apiRequests/Customer.js index 71e62ec57..4c0fc5607 100644 --- a/cypress/apiRequests/Customer.js +++ b/cypress/apiRequests/Customer.js @@ -1,4 +1,5 @@ import { getDefaultAddress } from "./utils/Utils"; + export function createCustomer(email, customerName, address, isActive = false) { const mutation = ` mutation{ @@ -64,6 +65,46 @@ export function getCustomers(startsWith) { return cy.sendRequestWithQuery(query); } +export function customerRegistration({ + email, + password = Cypress.env("USER_PASSWORD"), + channel +}) { + const mutation = `mutation{ + accountRegister(input:{ + email:"${email}", + password:"${password}" + channel:"${channel}" + redirectUrl: "${Cypress.config().baseUrl}account-confirm" + }){ + requiresConfirmation + user{ + id + } + errors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation).its("body.data.accountRegister"); +} + +export function confirmAccount(email, token) { + const mutation = `mutation{ + confirmAccount(email:"${email}", token:"${token}"){ + user{ + email + } + errors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation).its("body.data.confirmAccount"); +} + export function getCustomer(customerId) { const query = `query{ user(id:"${customerId}"){ diff --git a/cypress/elements/customers/customer-details.js b/cypress/elements/customers/customer-details.js new file mode 100644 index 000000000..1c92c0650 --- /dev/null +++ b/cypress/elements/customers/customer-details.js @@ -0,0 +1,3 @@ +export const CUSTOMER_DETAILS = { + isActiveCheckbox: '[name="isActive"]' +}; diff --git a/cypress/integration/allEnv/customerRegistration.js b/cypress/integration/allEnv/customerRegistration.js new file mode 100644 index 000000000..b12d6299d --- /dev/null +++ b/cypress/integration/allEnv/customerRegistration.js @@ -0,0 +1,55 @@ +import faker from "faker"; + +import { customerRegistration } from "../../apiRequests/Customer"; +import { CUSTOMER_DETAILS } from "../../elements/customers/customer-details"; +import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; +import { confirmationMessageShouldDisappear } from "../../steps/shared/confirmationMessage"; +import { customerDetailsUrl } from "../../url/urlList"; +import { getDefaultChannel } from "../../utils/channelsUtils"; + +describe("Tests for customer registration", () => { + const startsWith = "Registration"; + const email = `${startsWith}${faker.datatype.number()}@example.com`; + + let defaultChannel; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + getDefaultChannel().then(channel => { + defaultChannel = channel; + }); + }); + + it("shouldn't register customer with duplicated email", () => { + const duplicatedEmail = Cypress.env("USER_NAME"); + customerRegistration({ + duplicatedEmail, + channel: defaultChannel.slug + }).then(({ user, errors }) => { + expect(errors[0].field).to.eq("email"); + expect(user).to.not.be.ok; + }); + }); + + it("should activate customer from dashboard", () => { + customerRegistration({ email, channel: defaultChannel.slug }) + .then(({ user }) => { + cy.visit(customerDetailsUrl(user.id)) + .get(CUSTOMER_DETAILS.isActiveCheckbox) + .click() + .get(BUTTON_SELECTORS.confirm) + .click(); + confirmationMessageShouldDisappear(); + cy.clearSessionData() + .loginUserViaRequest("token", { + email, + password: Cypress.env("USER_PASSWORD") + }) + .its("body.data.tokenCreate"); + }) + .then(({ token, errors }) => { + expect(errors.length).to.eq(0); + expect(token).to.be.ok; + }); + }); +}); diff --git a/cypress/integration/stagedOnly/customerRegistration.js b/cypress/integration/stagedOnly/customerRegistration.js new file mode 100644 index 000000000..08922922c --- /dev/null +++ b/cypress/integration/stagedOnly/customerRegistration.js @@ -0,0 +1,40 @@ +import faker from "faker"; + +import { + confirmAccount, + customerRegistration +} from "../../apiRequests/Customer"; +import { getDefaultChannel } from "../../utils/channelsUtils"; +import { getMailActivationLinkForUser } from "../../utils/users"; + +describe("Tests for customer registration with email", () => { + const startsWith = "RegistrationEmail"; + let defaultChannel; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + getDefaultChannel().then(channel => (defaultChannel = channel)); + }); + + it("should register customer", () => { + const email = `${startsWith}${faker.datatype.number()}@example.com`; + customerRegistration({ email, channel: defaultChannel.slug }); + getMailActivationLinkForUser(email) + .then(urlLink => { + const tokenRegex = /token=(.*)/; + const token = urlLink.match(tokenRegex)[1]; + cy.clearSessionData(); + confirmAccount(email, token); + }) + .then(() => { + cy.loginUserViaRequest("token", { + email, + password: Cypress.env("USER_PASSWORD") + }).its("body.data.tokenCreate"); + }) + .then(({ errors, token }) => { + expect(errors.length).to.eq(0); + expect(token).to.be.ok; + }); + }); +}); diff --git a/cypress/integration/stagedOnly/staffMembers.js b/cypress/integration/stagedOnly/staffMembers.js index 19c19d963..3829816f5 100644 --- a/cypress/integration/stagedOnly/staffMembers.js +++ b/cypress/integration/stagedOnly/staffMembers.js @@ -22,7 +22,7 @@ import { } from "../../utils/users"; describe("Staff members", () => { - const startsWith = "Cypress"; + const startsWith = "StaffMembers"; const password = Cypress.env("USER_PASSWORD"); const lastName = faker.name.lastName(); const email = `${startsWith}${lastName}@example.com`; diff --git a/cypress/url/urlList.js b/cypress/url/urlList.js index a1acb9d39..731a6a575 100644 --- a/cypress/url/urlList.js +++ b/cypress/url/urlList.js @@ -50,6 +50,9 @@ export const warehouseDetailsUrl = warehouseId => export const productTypeDetailsUrl = productTypeId => `${urlList.productTypes}${productTypeId}`; +export const customerDetailsUrl = customerId => + `${urlList.customers}${customerId}`; + export const pageTypeDetailsUrl = pageTypeId => `${urlList.pageTypes}${pageTypeId}`;