2021-02-09 13:06:10 +00:00
|
|
|
import faker from "faker";
|
2021-02-17 12:50:57 +00:00
|
|
|
import { visit } from "graphql";
|
2021-02-09 13:06:10 +00:00
|
|
|
|
2021-02-17 10:47:23 +00:00
|
|
|
import Channels from "../apiRequests/Channels";
|
2021-02-19 08:45:34 +00:00
|
|
|
import ProductDetails from "../apiRequests/frontShop/ProductDetails";
|
2021-02-09 13:06:10 +00:00
|
|
|
import Product from "../apiRequests/Product";
|
2021-02-17 10:47:23 +00:00
|
|
|
import VariantsSteps from "../steps/products/VariantsSteps";
|
2021-02-19 08:45:34 +00:00
|
|
|
import { urlList } from "../url/urlList";
|
2021-02-09 13:06:10 +00:00
|
|
|
import ChannelsUtils from "../utils/channelsUtils";
|
|
|
|
import ProductsUtils from "../utils/productsUtils";
|
|
|
|
import ShippingUtils from "../utils/shippingUtils";
|
|
|
|
|
|
|
|
// <reference types="cypress" />
|
|
|
|
describe("creating variants", () => {
|
|
|
|
const startsWith = "Cy-";
|
|
|
|
|
|
|
|
const productUtils = new ProductsUtils();
|
|
|
|
const channelsUtils = new ChannelsUtils();
|
|
|
|
const shippingUtils = new ShippingUtils();
|
|
|
|
const product = new Product();
|
2021-02-17 10:47:23 +00:00
|
|
|
const channels = new Channels();
|
2021-02-19 08:45:34 +00:00
|
|
|
const productDetails = new ProductDetails();
|
2021-02-17 10:47:23 +00:00
|
|
|
|
|
|
|
const variantsSteps = new VariantsSteps();
|
|
|
|
|
|
|
|
let defaultChannel;
|
|
|
|
let warehouse;
|
|
|
|
let attribute;
|
|
|
|
let productType;
|
|
|
|
let category;
|
2021-02-09 13:06:10 +00:00
|
|
|
|
|
|
|
before(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
shippingUtils.deleteShipping(startsWith);
|
2021-02-19 08:45:34 +00:00
|
|
|
productUtils.deleteProperProducts(startsWith);
|
2021-02-17 10:47:23 +00:00
|
|
|
|
|
|
|
const name = `${startsWith}${faker.random.number()}`;
|
|
|
|
channelsUtils
|
|
|
|
.getDefaultChannel()
|
|
|
|
.then(channel => {
|
|
|
|
defaultChannel = channel;
|
|
|
|
cy.fixture("addresses");
|
|
|
|
})
|
|
|
|
.then(fixtureAddresses =>
|
|
|
|
shippingUtils.createShipping(
|
2021-02-19 08:45:34 +00:00
|
|
|
defaultChannel.id,
|
2021-02-17 10:47:23 +00:00
|
|
|
name,
|
|
|
|
fixtureAddresses.plAddress,
|
|
|
|
10
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.then(() => (warehouse = shippingUtils.getWarehouse()));
|
|
|
|
|
|
|
|
productUtils.createTypeAttributeAndCategoryForProduct(name).then(() => {
|
|
|
|
attribute = productUtils.getAttribute();
|
|
|
|
productType = productUtils.getProductType();
|
|
|
|
category = productUtils.getCategory();
|
|
|
|
});
|
2021-02-09 13:06:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create variant visible on frontend", () => {
|
|
|
|
const name = `${startsWith}${faker.random.number()}`;
|
2021-02-19 08:45:34 +00:00
|
|
|
const price = 10;
|
2021-02-17 10:47:23 +00:00
|
|
|
let createdProduct;
|
2021-02-09 13:06:10 +00:00
|
|
|
|
2021-02-17 10:47:23 +00:00
|
|
|
product
|
|
|
|
.createProduct(attribute.id, name, productType.id, category.id)
|
|
|
|
.then(resp => {
|
|
|
|
createdProduct = resp.body.data.productCreate.product;
|
|
|
|
product.updateChannelInProduct(
|
|
|
|
createdProduct.id,
|
|
|
|
defaultChannel.id,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true
|
|
|
|
);
|
2021-02-19 08:45:34 +00:00
|
|
|
cy.visit(`${urlList.products}${createdProduct.id}`);
|
|
|
|
variantsSteps.createFirstVariant(name, warehouse.id, price);
|
|
|
|
productDetails
|
|
|
|
.getProductDetails(createdProduct.id, defaultChannel.slug)
|
|
|
|
.then(productDetailsResp => {
|
2021-02-17 10:47:23 +00:00
|
|
|
expect(productDetailsResp.body[0].data.product.name).to.equal(name);
|
|
|
|
expect(
|
|
|
|
productDetailsResp.body[0].data.product.variants[0].pricing.price
|
|
|
|
.gross.amount
|
2021-02-19 08:45:34 +00:00
|
|
|
).to.equal(price);
|
|
|
|
});
|
2021-02-17 10:47:23 +00:00
|
|
|
});
|
2021-02-11 09:20:39 +00:00
|
|
|
});
|
|
|
|
it("should create several variants", () => {
|
|
|
|
const name = `${startsWith}${faker.random.number()}`;
|
|
|
|
const secondVariantSku = `${startsWith}${faker.random.number()}`;
|
2021-02-19 08:45:34 +00:00
|
|
|
const variantsPrice = 5;
|
|
|
|
let createdProduct;
|
2021-02-17 10:47:23 +00:00
|
|
|
productUtils
|
|
|
|
.createProductInChannel(
|
|
|
|
name,
|
2021-02-19 08:45:34 +00:00
|
|
|
defaultChannel.id,
|
|
|
|
warehouse.id,
|
|
|
|
1,
|
2021-02-17 10:47:23 +00:00
|
|
|
productType.id,
|
|
|
|
attribute.id,
|
|
|
|
category.id,
|
2021-02-19 08:45:34 +00:00
|
|
|
variantsPrice
|
2021-02-17 10:47:23 +00:00
|
|
|
)
|
|
|
|
.then(() => {
|
2021-02-19 08:45:34 +00:00
|
|
|
createdProduct = productUtils.getCreatedProduct();
|
|
|
|
cy.visit(`${urlList.products}${createdProduct.id}`);
|
|
|
|
variantsSteps.createVariant(
|
|
|
|
secondVariantSku,
|
|
|
|
warehouse.name,
|
|
|
|
variantsPrice
|
|
|
|
);
|
2021-02-17 10:47:23 +00:00
|
|
|
})
|
2021-02-19 08:45:34 +00:00
|
|
|
.then(() =>
|
|
|
|
productDetails.getProductDetails(createdProduct.id, defaultChannel.slug)
|
|
|
|
)
|
2021-02-17 10:47:23 +00:00
|
|
|
.then(productDetailsResp => {
|
|
|
|
expect(productDetailsResp.body[0].data.product.name).to.equal(name);
|
|
|
|
expect(productDetailsResp.body[0].data.product.variants).to.have.length(
|
|
|
|
2
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
productDetailsResp.body[0].data.product.variants[0].pricing.price
|
|
|
|
.gross.amount
|
2021-02-19 08:45:34 +00:00
|
|
|
).to.equal(variantsPrice);
|
2021-02-17 10:47:23 +00:00
|
|
|
expect(
|
|
|
|
productDetailsResp.body[0].data.product.variants[1].pricing.price
|
|
|
|
.gross.amount
|
2021-02-19 08:45:34 +00:00
|
|
|
).to.equal(variantsPrice);
|
2021-02-11 09:20:39 +00:00
|
|
|
});
|
2021-02-17 10:47:23 +00:00
|
|
|
});
|
|
|
|
it("should create variant for many channels", () => {
|
|
|
|
const name = `${startsWith}${faker.random.number()}`;
|
|
|
|
let newChannel;
|
2021-02-19 08:45:34 +00:00
|
|
|
let createdProduct;
|
2021-02-17 10:47:23 +00:00
|
|
|
channels
|
|
|
|
.createChannel(true, name, name, "PLN")
|
|
|
|
.then(resp => {
|
2021-02-19 08:45:34 +00:00
|
|
|
newChannel = resp.body.data.channelCreate.channel;
|
|
|
|
productUtils.createProduct(
|
|
|
|
attribute.id,
|
|
|
|
name,
|
|
|
|
productType.id,
|
|
|
|
category.id
|
|
|
|
);
|
2021-02-17 10:47:23 +00:00
|
|
|
})
|
2021-02-19 08:45:34 +00:00
|
|
|
.then(() => {
|
|
|
|
createdProduct = productUtils.getCreatedProduct();
|
2021-02-17 10:47:23 +00:00
|
|
|
product.updateChannelInProduct(
|
|
|
|
createdProduct.id,
|
2021-02-11 09:20:39 +00:00
|
|
|
defaultChannel.id,
|
|
|
|
true,
|
|
|
|
true,
|
2021-02-17 10:47:23 +00:00
|
|
|
true
|
|
|
|
);
|
2021-02-19 08:45:34 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
2021-02-17 10:47:23 +00:00
|
|
|
product.updateChannelInProduct(
|
|
|
|
createdProduct.id,
|
|
|
|
newChannel.id,
|
2021-02-11 09:20:39 +00:00
|
|
|
true,
|
2021-02-17 10:47:23 +00:00
|
|
|
true,
|
|
|
|
true
|
|
|
|
);
|
2021-02-19 08:45:34 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
cy.visit(`${urlList.products}${createdProduct.id}`);
|
|
|
|
variantsSteps.createFirstVariant(warehouse.id);
|
|
|
|
productDetails.getProductDetails(product.id, defaultChannel.slug);
|
|
|
|
})
|
|
|
|
.then(productDetailsResp => {
|
2021-02-17 12:50:57 +00:00
|
|
|
expect(productDetailsResp.body[0].data.product.name).to.equal(name);
|
|
|
|
expect(
|
|
|
|
productDetailsResp.body[0].data.product.variants[0].pricing.price
|
|
|
|
.gross.amount
|
|
|
|
).to.equal(10);
|
2021-02-19 08:45:34 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
productDetails.getProductDetails(product.id, newChannel.slug);
|
|
|
|
})
|
|
|
|
.then(productDetailsResp => {
|
2021-02-17 12:50:57 +00:00
|
|
|
expect(productDetailsResp.body[0].data.product.name).to.equal(name);
|
|
|
|
expect(
|
|
|
|
productDetailsResp.body[0].data.product.variants[0].pricing.price
|
|
|
|
.gross.amount
|
|
|
|
).to.equal(10);
|
2021-02-19 08:45:34 +00:00
|
|
|
});
|
2021-02-09 13:06:10 +00:00
|
|
|
});
|
|
|
|
});
|