saleor-dashboard/cypress/integration/products/productsVariants.js

192 lines
6 KiB
JavaScript
Raw Normal View History

2021-02-24 19:35:37 +00:00
import faker from "faker";
import Channels from "../../apiRequests/Channels";
import Product from "../../apiRequests/Product";
import VariantsSteps from "../../steps/products/VariantsSteps";
import { urlList } from "../../url/urlList";
import ChannelsUtils from "../../utils/channelsUtils";
import ProductsUtils from "../../utils/productsUtils";
import ShippingUtils from "../../utils/shippingUtils";
2021-03-01 11:54:08 +00:00
import { getProductVariants } from "../../utils/storeFront/storeFrontProductUtils";
2021-02-24 19:35:37 +00:00
// <reference types="cypress" />
describe("creating variants", () => {
const startsWith = "Cy-";
2021-02-26 15:39:42 +00:00
const attributeValues = ["value1", "value2"];
2021-02-24 19:35:37 +00:00
const productUtils = new ProductsUtils();
const channelsUtils = new ChannelsUtils();
const shippingUtils = new ShippingUtils();
const product = new Product();
const channels = new Channels();
const variantsSteps = new VariantsSteps();
let defaultChannel;
let warehouse;
let attribute;
let productType;
let category;
before(() => {
cy.clearSessionData().loginUserViaRequest();
shippingUtils.deleteShipping(startsWith);
productUtils.deleteProperProducts(startsWith);
2021-03-01 12:50:36 +00:00
channelsUtils.deleteChannels(startsWith);
2021-02-24 19:35:37 +00:00
const name = `${startsWith}${faker.random.number()}`;
channelsUtils
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
cy.fixture("addresses");
})
.then(fixtureAddresses =>
shippingUtils.createShipping({
channelId: defaultChannel.id,
name,
address: fixtureAddresses.plAddress
})
)
.then(() => (warehouse = shippingUtils.getWarehouse()));
2021-02-26 15:39:42 +00:00
productUtils
.createTypeAttributeAndCategoryForProduct(name, attributeValues)
.then(() => {
attribute = productUtils.getAttribute();
productType = productUtils.getProductType();
category = productUtils.getCategory();
});
2021-02-24 19:35:37 +00:00
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should create variant visible on frontend", () => {
const name = `${startsWith}${faker.random.number()}`;
const price = 10;
let createdProduct;
product
.createProduct(attribute.id, name, productType.id, category.id)
.then(resp => {
createdProduct = resp.body.data.productCreate.product;
product.updateChannelInProduct({
productId: createdProduct.id,
channelId: defaultChannel.id
});
cy.visit(`${urlList.products}${createdProduct.id}`);
2021-02-25 09:51:52 +00:00
variantsSteps.createFirstVariant({
sku: name,
warehouseId: warehouse.id,
price,
2021-03-01 11:54:08 +00:00
attribute: attributeValues[0]
2021-02-25 09:51:52 +00:00
});
2021-03-01 11:54:08 +00:00
getProductVariants(createdProduct.id, defaultChannel.slug);
2021-02-24 19:35:37 +00:00
})
.then(variants => {
2021-03-01 11:54:08 +00:00
expect(variants[0]).to.have.property("name", attributeValues[0]);
expect(variants[0].pricing.price.gross).to.have.property(
"amount",
price
);
2021-02-24 19:35:37 +00:00
});
});
it("should create several variants", () => {
const name = `${startsWith}${faker.random.number()}`;
const secondVariantSku = `${startsWith}${faker.random.number()}`;
2021-03-01 11:54:08 +00:00
const variants = [{ amount: 7 }, { name: attributeValues[1], amount: 16 }];
2021-02-24 19:35:37 +00:00
let createdProduct;
productUtils
.createProductInChannel({
name,
2021-02-26 14:32:01 +00:00
attributeId: attribute.id,
2021-02-24 19:35:37 +00:00
channelId: defaultChannel.id,
warehouseId: warehouse.id,
productTypeId: productType.id,
categoryId: category.id,
2021-03-01 11:54:08 +00:00
price: variants[0].amount
2021-02-24 19:35:37 +00:00
})
.then(() => {
createdProduct = productUtils.getCreatedProduct();
cy.visit(`${urlList.products}${createdProduct.id}`);
2021-02-26 14:32:01 +00:00
variantsSteps.createVariant({
sku: secondVariantSku,
warehouseName: warehouse.name,
2021-03-01 11:54:08 +00:00
attributeName: variants[1].name,
price: variants[1].amount
2021-02-26 14:32:01 +00:00
});
2021-02-24 19:35:37 +00:00
})
2021-03-01 11:54:08 +00:00
.then(() => getProductVariants(createdProduct.id, defaultChannel.slug))
.then(variantsResp => {
expect(variantsResp).to.have.length(2);
expect(variantsResp[0].pricing.price.gross).to.have.property(
"amount",
variants[0].amount
);
expect(variantsResp[1]).to.have.property("name", variants[1].name);
expect(variantsResp[1].pricing.price.gross).to.have.property(
"amount",
variants[1].amount
);
2021-02-24 19:35:37 +00:00
});
});
it("should create variant for many channels", () => {
const name = `${startsWith}${faker.random.number()}`;
const variantsPrice = 10;
let newChannel;
let createdProduct;
channels
.createChannel(true, name, name, "PLN")
.then(resp => {
newChannel = resp.body.data.channelCreate.channel;
productUtils.createProduct(
attribute.id,
name,
productType.id,
category.id
);
})
.then(() => {
createdProduct = productUtils.getCreatedProduct();
product.updateChannelInProduct({
productId: createdProduct.id,
channelId: defaultChannel.id
});
})
.then(() => {
product.updateChannelInProduct({
productId: createdProduct.id,
channelId: newChannel.id
});
})
.then(() => {
cy.visit(`${urlList.products}${createdProduct.id}`);
2021-02-26 15:39:42 +00:00
variantsSteps.createFirstVariant({
2021-03-01 11:54:08 +00:00
sku: name,
2021-02-26 15:39:42 +00:00
warehouseId: warehouse.id,
price: variantsPrice,
2021-03-01 11:54:08 +00:00
attribute: attributeValues[0]
2021-02-26 15:39:42 +00:00
});
2021-03-01 11:54:08 +00:00
getProductVariants(createdProduct.id, defaultChannel.slug);
2021-02-24 19:35:37 +00:00
})
.then(variants => {
2021-03-01 11:54:08 +00:00
expect(variants[0]).to.have.property("name", attributeValues[0]);
expect(variants[0].pricing.price.gross).to.have.property(
"amount",
variantsPrice
);
getProductVariants(createdProduct.id, newChannel.slug);
2021-02-24 19:35:37 +00:00
})
.then(variants => {
2021-03-01 11:54:08 +00:00
expect(variants[0]).to.have.property("name", attributeValues[0]);
expect(variants[0].pricing.price.gross).to.have.property(
"amount",
variantsPrice
);
2021-02-24 19:35:37 +00:00
});
});
});