test for customer registration (#1231)

* test for customer registration

* change name
This commit is contained in:
Karolina Rakoczy 2021-07-15 15:06:30 +03:00 committed by GitHub
parent 0c21788d61
commit 99507d5bed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 143 additions and 1 deletions

View file

@ -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}"){

View file

@ -0,0 +1,3 @@
export const CUSTOMER_DETAILS = {
isActiveCheckbox: '[name="isActive"]'
};

View file

@ -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;
});
});
});

View file

@ -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;
});
});
});

View file

@ -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`;

View file

@ -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}`;