All analytics in separate tests

This commit is contained in:
Karolina Rakoczy 2021-02-15 10:44:50 +01:00
parent 5b6d1ddd77
commit 592993c030
9 changed files with 341 additions and 175 deletions

View file

@ -20,41 +20,24 @@ class Channels {
}`;
return cy.sendRequestWithQuery(createChannelMutation);
}
deleteTestChannels(nameStartsWith) {
getChannels() {
const getChannelsInfoQuery = `query{
channels{
name
id
isActive
slug
currencyCode
}
}
`;
cy.sendRequestWithQuery(getChannelsInfoQuery).then(resp => {
const channels = new Set(resp.body.data.channels);
channels.forEach(element => {
if (element.name.startsWith(nameStartsWith)) {
const targetChannels = Array.from(channels).filter(function(channel) {
return (
element.currencyCode === channel.currencyCode &&
element.id !== channel.id
);
});
if (targetChannels[0]) {
this.deleteChannel(element.id, targetChannels[0].id);
channels.delete(element);
}
}
});
});
channels{
name
id
isActive
slug
currencyCode
}
}
`;
return cy.sendRequestWithQuery(getChannelsInfoQuery);
}
deleteChannel(channelId, targetChennelId) {
deleteChannel(channelId, targetChannelId) {
const deleteChannelMutation = `mutation{
channelDelete(id: "${channelId}", input:{
targetChannel: "${targetChennelId}"
targetChannel: "${targetChannelId}"
}){
channel{
name

View file

@ -0,0 +1,37 @@
class HomePage {
getSalesForChannel(channelSlug, period) {
const query = `query{
ordersTotal(period: ${period}, channel:"${channelSlug}"){
gross{
amount
}
}
}`;
return cy.sendRequestWithQuery(query);
}
getOrdersForChannel(channelSlug, created) {
const query = `query{
orders(created: ${created}, channel:"${channelSlug}"){
totalCount
}
}`;
return cy.sendRequestWithQuery(query);
}
getOrdersWithStatus(status, channelSlug) {
const query = `query{
orders(status: ${status}, channel:"${channelSlug}"){
totalCount
}
}`;
return cy.sendRequestWithQuery(query);
}
getProductsOutOfStock(channelSlug) {
const query = `query{
products(stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}"){
totalCount
}
}`;
return cy.sendRequestWithQuery(query);
}
}
export default HomePage;

View file

@ -1,4 +1,4 @@
export const DASHBOARD_SELECTORS = {
export const HOMEPAGE_SELECTORS = {
sales: "[data-test-id='sales-analytics']",
orders: "[data-test-id='orders-analytics']",
activity: "[data-test-id='activity-card']",

View file

@ -14,16 +14,18 @@ import { ORDERS_SELECTORS } from "../elements/orders/orders-selectors";
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
import ChannelsSteps from "../steps/channelsSteps";
import { urlList } from "../url/urlList";
import ChannelsUtils from "../utils/channelsUtils";
describe("Channels", () => {
const channelStartsWith = "Cypress:";
const currency = "PLN";
const channels = new Channels();
const channelsUtils = new ChannelsUtils();
const channelsSteps = new ChannelsSteps();
before(() => {
cy.clearSessionData().loginUserViaRequest();
channels.deleteTestChannels(channelStartsWith);
channelsUtils.deleteChannels(channelStartsWith);
});
beforeEach(() => {

View file

@ -1,143 +0,0 @@
import faker from "faker";
import Channels from "../apiRequests/Channels";
import Customer from "../apiRequests/Customer";
import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors";
import { HEADER_SELECTORS } from "../elements/header/header-selectors";
import OrdersUtils from "../utils/ordersUtils";
import ProductsUtils from "../utils/productsUtils";
import ShippingUtils from "../utils/shippingUtils";
// <reference types="cypress" />
describe("User authorization", () => {
const startsWith = "Cy-";
const customer = new Customer();
const channels = new Channels();
const productsUtils = new ProductsUtils();
const shippingUtils = new ShippingUtils();
const ordersUtils = new OrdersUtils();
before(() => {
cy.clearSessionData().loginUserViaRequest();
customer.deleteCustomers(startsWith);
shippingUtils.deleteShipping(startsWith);
productsUtils.deleteProducts(startsWith);
channels.deleteTestChannels(startsWith);
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should all elements be visible on the dashboard", () => {
cy.visit("/")
.softAssertVisibility(DASHBOARD_SELECTORS.sales)
.softAssertVisibility(DASHBOARD_SELECTORS.orders)
.softAssertVisibility(DASHBOARD_SELECTORS.activity)
.softAssertVisibility(DASHBOARD_SELECTORS.topProducts)
.softAssertVisibility(DASHBOARD_SELECTORS.ordersReadyToFulfill)
.softAssertVisibility(DASHBOARD_SELECTORS.paymentsWaitingForCapture)
.softAssertVisibility(DASHBOARD_SELECTORS.productsOutOfStock);
});
it("should correct amount of orders be displayed", () => {
const randomName = startsWith + faker.random.number();
const randomEmail = randomName + "@example.com";
const randomNameProductOutOfStock = `${startsWith}${faker.random.number()}`;
const shippingPrice = 12;
const productPrice = 22;
const sales = productPrice * 2 + shippingPrice;
// Create channel, customer, product - everything needed to create order
cy.fixture("addresses").then(json => {
channels
.createChannel(true, randomName, randomName, json.plAddress.currency)
.then(channelsResp => {
const channelId = channelsResp.body.data.channelCreate.channel.id;
const channelSlug = channelsResp.body.data.channelCreate.channel.slug;
customer
.createCustomer(randomEmail, randomName, json.plAddress)
.then(resp => {
const customerId = resp.body.data.customerCreate.user.id;
const customerEmail = resp.body.data.customerCreate.user.email;
shippingUtils
.createShipping(
channelId,
randomName,
json.plAddress,
shippingPrice
)
.then(() => {
const shippingId = shippingUtils.getShippingMethodId();
const warehouseId = shippingUtils.getWarehouseId();
productsUtils
.createTypeAttributeAndCategoryForProduct(randomName)
.then(() => {
const productTypeId = productsUtils.getProductTypeId();
const attributeId = productsUtils.getAttributeId();
const categoryId = productsUtils.getCategoryId();
productsUtils
.createProductInChannel(
randomName,
channelId,
warehouseId,
10,
productTypeId,
attributeId,
categoryId,
productPrice
)
.then(() => {
const variantsList = productsUtils.getCreatedVariants();
// Create order ready to fulfill
ordersUtils.createReadyToFulfillOrder(
customerId,
shippingId,
channelId,
variantsList
);
// Create order waiting for capture
ordersUtils.createWaitingForCaptureOrder(
channelSlug,
customerEmail,
variantsList,
shippingId
);
});
// Create product out of stock
productsUtils.createProductInChannel(
randomNameProductOutOfStock,
channelId,
warehouseId,
0,
productTypeId,
attributeId,
categoryId,
productPrice
);
});
});
});
});
});
cy.visit("/");
cy.get(HEADER_SELECTORS.channelSelect)
.click()
.get(HEADER_SELECTORS.channelSelectList)
.contains(randomName)
.click()
.waitForGraph("Home");
const salesRegexp = new RegExp(`\\D+${sales}[\,.]00\\D*`);
cy.contains(salesRegexp).should("be.visible");
const regex = /^1\D+/;
cy.softAssertMatch(DASHBOARD_SELECTORS.ordersReadyToFulfill, regex)
.softAssertMatch(DASHBOARD_SELECTORS.paymentsWaitingForCapture, regex)
.softAssertMatch(DASHBOARD_SELECTORS.productsOutOfStock, regex)
.softAssertMatch(DASHBOARD_SELECTORS.sales, salesRegexp)
.softAssertMatch(DASHBOARD_SELECTORS.orders, /\D+2\D*/);
});
});

View file

@ -0,0 +1,205 @@
import faker from "faker";
import Customer from "../apiRequests/Customer";
import { HOMEPAGE_SELECTORS } from "../elements/homePage/homePage-selectors";
import HomePageSteps from "../steps/homePageSteps";
import { urlList } from "../url/urlList";
import ChannelsUtils from "../utils/channelsUtils";
import HomePageUtils from "../utils/homePageUtils";
import OrdersUtils from "../utils/ordersUtils";
import ProductsUtils from "../utils/productsUtils";
import ShippingUtils from "../utils/shippingUtils";
// <reference types="cypress" />
describe("User authorization", () => {
const startsWith = "Cy-";
const customer = new Customer();
const productsUtils = new ProductsUtils();
const shippingUtils = new ShippingUtils();
const ordersUtils = new OrdersUtils();
const channelsUtils = new ChannelsUtils();
const homePageUtils = new HomePageUtils();
const homePageSteps = new HomePageSteps();
let customerId;
let defaultChannel;
const productPrice = 22;
const shippingPrice = 12;
const randomName = startsWith + faker.random.number();
const randomEmail = randomName + "@example.com";
before(() => {
cy.clearSessionData().loginUserViaRequest();
customer.deleteCustomers(startsWith);
shippingUtils.deleteShipping(startsWith);
productsUtils.deleteProducts(startsWith);
channelsUtils.getDefaultChannel().then(channel => {
defaultChannel = channel;
cy.fixture("addresses").then(addressesFixture => {
customer
.createCustomer(randomEmail, randomName, addressesFixture.plAddress)
.then(resp => {
customerId = resp.body.data.customerCreate.user.id;
shippingUtils
.createShipping(
defaultChannel.id,
randomName,
addressesFixture.plAddress,
shippingPrice
)
.then(() => {
const warehouseId = shippingUtils.getWarehouseId();
productsUtils
.createTypeAttributeAndCategoryForProduct(randomName)
.then(() => {
const productTypeId = productsUtils.getProductTypeId();
const attributeId = productsUtils.getAttributeId();
const categoryId = productsUtils.getCategoryId();
productsUtils.createProductInChannel(
randomName,
defaultChannel.id,
warehouseId,
20,
productTypeId,
attributeId,
categoryId,
productPrice
);
});
});
});
});
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should all elements be visible on the dashboard", () => {
cy.visit(urlList.homePage)
.softAssertVisibility(HOMEPAGE_SELECTORS.sales)
.softAssertVisibility(HOMEPAGE_SELECTORS.orders)
.softAssertVisibility(HOMEPAGE_SELECTORS.activity)
.softAssertVisibility(HOMEPAGE_SELECTORS.topProducts)
.softAssertVisibility(HOMEPAGE_SELECTORS.ordersReadyToFulfill)
.softAssertVisibility(HOMEPAGE_SELECTORS.paymentsWaitingForCapture)
.softAssertVisibility(HOMEPAGE_SELECTORS.productsOutOfStock);
});
it("should correct amount of ready to fullfil orders be displayed", () => {
homePageUtils
.getOrdersReadyToFulfill(defaultChannel.slug)
.as("ordersReadyToFulfill");
ordersUtils.createReadyToFulfillOrder(
customerId,
shippingUtils.getShippingMethodId(),
defaultChannel.id,
productsUtils.getCreatedVariants()
);
cy.get("@ordersReadyToFulfill").then(ordersReadyToFulfill => {
const regexp = new RegExp(`^${ordersReadyToFulfill + 1}\D*`);
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
cy.contains(HOMEPAGE_SELECTORS.ordersReadyToFulfill, regexp).should(
"be.visible"
);
});
});
it("should correct amount of payments waiting for capture be displayed", () => {
homePageUtils
.getOrdersReadyForCapture(defaultChannel.slug)
.as("ordersReadyForCapture");
const shippingId = shippingUtils.getShippingMethodId();
const variantsList = productsUtils.getCreatedVariants();
ordersUtils.createWaitingForCaptureOrder(
defaultChannel.slug,
randomEmail,
variantsList,
shippingId
);
cy.get("@ordersReadyForCapture").then(ordersReadyForCapture => {
const regexp = new RegExp(`^${ordersReadyForCapture + 1}\D*`);
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
cy.contains(HOMEPAGE_SELECTORS.ordersReadyForCapture, regexp).should(
"be.visible"
);
});
});
it("should correct amount of products out of stock be displayed", () => {
homePageUtils
.getProductsOutOfStock(defaultChannel.slug)
.as("productsOutOfStock");
const productOutOfStockRandomName = startsWith + faker.random.number();
const productsOutOfStockUtils = new ProductsUtils();
const warehouseId = shippingUtils.getWarehouseId();
const productTypeId = productsUtils.getProductTypeId();
const attributeId = productsUtils.getAttributeId();
const categoryId = productsUtils.getCategoryId();
productsOutOfStockUtils.createProductInChannel(
productOutOfStockRandomName,
defaultChannel.id,
warehouseId,
0,
productTypeId,
attributeId,
categoryId,
productPrice
);
cy.get("@productsOutOfStock").then(productsOutOfStock => {
const regexp = new RegExp(`^${productsOutOfStock + 1}\\D*`);
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
cy.contains(HOMEPAGE_SELECTORS.productsOutOfStock, regexp).should(
"be.visible"
);
});
});
it("should correct amount of sales be displayed", () => {
homePageUtils.getSalesAmount(defaultChannel.slug).as("salesAmount");
ordersUtils.createReadyToFulfillOrder(
customerId,
shippingUtils.getShippingMethodId(),
defaultChannel.id,
productsUtils.getCreatedVariants()
);
cy.get("@salesAmount").then(salesAmount => {
let totalAmount = salesAmount + productPrice;
totalAmount = totalAmount
.toFixed(2)
.toString()
.replace(".", "[,.]");
const regexp = new RegExp(`\\D*${totalAmount}\\D*`);
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
cy.contains(HOMEPAGE_SELECTORS.sales, regexp).should("be.visible");
});
});
it("should correct amount of orders be displayed", () => {
homePageUtils.getTodaysOrders(defaultChannel.slug).as("todaysOrders");
ordersUtils.createReadyToFulfillOrder(
customerId,
shippingUtils.getShippingMethodId(),
defaultChannel.id,
productsUtils.getCreatedVariants()
);
cy.get("@todaysOrders").then(todaysOrders => {
const regexp = new RegExp(`\\D*${todaysOrders + 1}\\D*`);
cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name);
cy.contains(HOMEPAGE_SELECTORS.orders, regexp).should("be.visible");
});
});
});

View file

@ -0,0 +1,12 @@
import { HEADER_SELECTORS } from "../elements/header/header-selectors";
class HomePageSteps {
changeChannel(channelName) {
cy.get(HEADER_SELECTORS.channelSelect)
.click()
.get(HEADER_SELECTORS.channelSelectList)
.contains(channelName)
.click()
.waitForGraph("Home");
}
}
export default HomePageSteps;

View file

@ -0,0 +1,40 @@
import Channels from "../apiRequests/Channels";
class ChannelsUtils {
channels = new Channels();
deleteChannels(nameStartsWith) {
this.channels.getChannels().then(resp => {
const channelsArray = new Set(resp.body.data.channels);
if (channelsArray) {
channelsArray.forEach(element => {
if (element.name.startsWith(nameStartsWith)) {
const targetChannels = Array.from(channelsArray).filter(function(
channelElement
) {
return (
element.currencyCode === channelElement.currencyCode &&
element.id !== channelElement.id
);
});
if (targetChannels[0]) {
this.channels.deleteChannel(element.id, targetChannels[0].id);
channelsArray.delete(element);
}
}
});
}
});
}
getDefaultChannel() {
return this.channels.getChannels().then(resp => {
const channelsArray = resp.body.data.channels;
return (this.defaultChannel = channelsArray.find(function(
channelElement
) {
return channelElement.slug === "default-channel";
}));
});
}
}
export default ChannelsUtils;

View file

@ -0,0 +1,30 @@
import HomePage from "../apiRequests/HomePage";
class HomePageUtils {
homePage = new HomePage();
getOrdersReadyToFulfill(channelSlug) {
return this.homePage
.getOrdersWithStatus("READY_TO_FULFILL", channelSlug)
.then(resp => resp.body.data.orders.totalCount);
}
getOrdersReadyForCapture(channelSlug) {
return this.homePage
.getOrdersWithStatus("READY_TO_CAPTURE", channelSlug)
.then(resp => resp.body.data.orders.totalCount);
}
getProductsOutOfStock(channelSlug) {
return this.homePage
.getProductsOutOfStock(channelSlug)
.then(resp => resp.body.data.products.totalCount);
}
getSalesAmount(channelSlug) {
return this.homePage
.getSalesForChannel(channelSlug, "TODAY")
.then(resp => resp.body.data.ordersTotal.gross.amount);
}
getTodaysOrders(channelSlug) {
return this.homePage
.getOrdersForChannel(channelSlug, "TODAY")
.then(resp => resp.body.data.orders.totalCount);
}
}
export default HomePageUtils;