test for customer registration (#1231)
* test for customer registration * change name
This commit is contained in:
parent
0c21788d61
commit
99507d5bed
6 changed files with 143 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import { getDefaultAddress } from "./utils/Utils";
|
import { getDefaultAddress } from "./utils/Utils";
|
||||||
|
|
||||||
export function createCustomer(email, customerName, address, isActive = false) {
|
export function createCustomer(email, customerName, address, isActive = false) {
|
||||||
const mutation = `
|
const mutation = `
|
||||||
mutation{
|
mutation{
|
||||||
|
@ -64,6 +65,46 @@ export function getCustomers(startsWith) {
|
||||||
return cy.sendRequestWithQuery(query);
|
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) {
|
export function getCustomer(customerId) {
|
||||||
const query = `query{
|
const query = `query{
|
||||||
user(id:"${customerId}"){
|
user(id:"${customerId}"){
|
||||||
|
|
3
cypress/elements/customers/customer-details.js
Normal file
3
cypress/elements/customers/customer-details.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const CUSTOMER_DETAILS = {
|
||||||
|
isActiveCheckbox: '[name="isActive"]'
|
||||||
|
};
|
55
cypress/integration/allEnv/customerRegistration.js
Normal file
55
cypress/integration/allEnv/customerRegistration.js
Normal 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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
40
cypress/integration/stagedOnly/customerRegistration.js
Normal file
40
cypress/integration/stagedOnly/customerRegistration.js
Normal 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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -22,7 +22,7 @@ import {
|
||||||
} from "../../utils/users";
|
} from "../../utils/users";
|
||||||
|
|
||||||
describe("Staff members", () => {
|
describe("Staff members", () => {
|
||||||
const startsWith = "Cypress";
|
const startsWith = "StaffMembers";
|
||||||
const password = Cypress.env("USER_PASSWORD");
|
const password = Cypress.env("USER_PASSWORD");
|
||||||
const lastName = faker.name.lastName();
|
const lastName = faker.name.lastName();
|
||||||
const email = `${startsWith}${lastName}@example.com`;
|
const email = `${startsWith}${lastName}@example.com`;
|
||||||
|
|
|
@ -50,6 +50,9 @@ export const warehouseDetailsUrl = warehouseId =>
|
||||||
export const productTypeDetailsUrl = productTypeId =>
|
export const productTypeDetailsUrl = productTypeId =>
|
||||||
`${urlList.productTypes}${productTypeId}`;
|
`${urlList.productTypes}${productTypeId}`;
|
||||||
|
|
||||||
|
export const customerDetailsUrl = customerId =>
|
||||||
|
`${urlList.customers}${customerId}`;
|
||||||
|
|
||||||
export const pageTypeDetailsUrl = pageTypeId =>
|
export const pageTypeDetailsUrl = pageTypeId =>
|
||||||
`${urlList.pageTypes}${pageTypeId}`;
|
`${urlList.pageTypes}${pageTypeId}`;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue