2021-01-27 09:41:55 +00:00
|
|
|
import faker from "faker";
|
|
|
|
|
2021-02-02 11:34:10 +00:00
|
|
|
import Channels from "../apiRequests/Channels";
|
|
|
|
import Customer from "../apiRequests/Customer";
|
2021-01-21 10:05:54 +00:00
|
|
|
import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors";
|
2021-02-02 11:34:10 +00:00
|
|
|
import { HEADER_SELECTORS } from "../elements/header/header-selectors";
|
|
|
|
import OrdersUtils from "../utils/ordersUtils";
|
|
|
|
import ProductsUtils from "../utils/productsUtils";
|
|
|
|
import ShippingUtils from "../utils/shippingUtils";
|
2021-01-19 21:17:49 +00:00
|
|
|
|
2021-01-21 10:05:54 +00:00
|
|
|
// <reference types="cypress" />
|
|
|
|
describe("User authorization", () => {
|
2021-01-27 09:41:55 +00:00
|
|
|
const startsWith = "Cy-";
|
|
|
|
|
|
|
|
const customer = new Customer();
|
2021-02-02 11:34:10 +00:00
|
|
|
const channels = new Channels();
|
|
|
|
const productsUtils = new ProductsUtils();
|
|
|
|
const shippingUtils = new ShippingUtils();
|
|
|
|
const ordersUtils = new OrdersUtils();
|
2021-01-27 09:41:55 +00:00
|
|
|
|
|
|
|
before(() => {
|
2021-02-02 11:34:10 +00:00
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
2021-01-27 09:41:55 +00:00
|
|
|
customer.deleteCustomers(startsWith);
|
2021-02-02 11:34:10 +00:00
|
|
|
shippingUtils.deleteShipping(startsWith);
|
|
|
|
productsUtils.deleteProducts(startsWith);
|
|
|
|
channels.deleteTestChannels(startsWith);
|
2021-01-27 09:41:55 +00:00
|
|
|
});
|
|
|
|
|
2021-01-21 10:05:54 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
});
|
2021-01-19 21:17:49 +00:00
|
|
|
|
2021-02-11 12:20:00 +00:00
|
|
|
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);
|
2021-01-21 10:05:54 +00:00
|
|
|
});
|
2021-01-19 21:17:49 +00:00
|
|
|
|
2021-01-27 09:41:55 +00:00
|
|
|
it("should correct amount of orders be displayed", () => {
|
|
|
|
const randomName = startsWith + faker.random.number();
|
|
|
|
const randomEmail = randomName + "@example.com";
|
2021-02-02 11:34:10 +00:00
|
|
|
const randomNameProductOutOfStock = `${startsWith}${faker.random.number()}`;
|
|
|
|
const shippingPrice = 12;
|
|
|
|
const productPrice = 22;
|
2021-02-11 12:20:00 +00:00
|
|
|
let sales = productPrice * 2 + shippingPrice;
|
|
|
|
|
|
|
|
// Create channel, customer, product - everything needed to create order
|
2021-02-02 11:34:10 +00:00
|
|
|
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();
|
2021-02-11 12:20:00 +00:00
|
|
|
|
|
|
|
// Create order ready to fulfill
|
|
|
|
ordersUtils.createReadyToFulfillOrder(
|
2021-02-02 11:34:10 +00:00
|
|
|
customerId,
|
|
|
|
shippingId,
|
|
|
|
channelId,
|
|
|
|
variantsList
|
|
|
|
);
|
2021-02-11 12:20:00 +00:00
|
|
|
|
|
|
|
// Create order waiting for capture
|
2021-02-02 11:34:10 +00:00
|
|
|
ordersUtils.createWaitingForCaptureOrder(
|
|
|
|
channelSlug,
|
|
|
|
customerEmail,
|
|
|
|
variantsList,
|
|
|
|
shippingId
|
|
|
|
);
|
|
|
|
});
|
2021-02-11 12:20:00 +00:00
|
|
|
|
|
|
|
// Create product out of stock
|
2021-02-02 11:34:10 +00:00
|
|
|
productsUtils.createProductInChannel(
|
|
|
|
randomNameProductOutOfStock,
|
|
|
|
channelId,
|
|
|
|
warehouseId,
|
|
|
|
0,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
productPrice
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-27 09:41:55 +00:00
|
|
|
});
|
2021-01-21 10:05:54 +00:00
|
|
|
});
|
2021-01-27 09:41:55 +00:00
|
|
|
cy.visit("/");
|
2021-02-02 11:34:10 +00:00
|
|
|
cy.get(HEADER_SELECTORS.channelSelect)
|
|
|
|
.click()
|
|
|
|
.get(HEADER_SELECTORS.channelSelectList)
|
|
|
|
.contains(randomName)
|
2021-02-11 12:20:00 +00:00
|
|
|
.click()
|
|
|
|
.get(DASHBOARD_SELECTORS.dataAreLoading)
|
|
|
|
.should("not.exist");
|
|
|
|
const regex = /^1\D+/;
|
|
|
|
sales = sales.toFixed(2).replace(".", ",");
|
|
|
|
cy.softAssertMatch(DASHBOARD_SELECTORS.ordersReadyToFulfill, regex)
|
|
|
|
.softAssertMatch(DASHBOARD_SELECTORS.paymentsWaitingForCapture, regex)
|
|
|
|
.softAssertMatch(DASHBOARD_SELECTORS.productsOutOfStock, regex)
|
|
|
|
.softAssertMatch(
|
|
|
|
DASHBOARD_SELECTORS.sales,
|
|
|
|
new RegExp(`\\D+${sales}\\D+`)
|
|
|
|
)
|
|
|
|
.softAssertMatch(DASHBOARD_SELECTORS.orders, /\D+2\D*/);
|
2021-01-21 10:05:54 +00:00
|
|
|
});
|
|
|
|
});
|