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

196 lines
6.3 KiB
JavaScript
Raw Normal View History

2021-02-24 19:35:37 +00:00
import faker from "faker";
import { createChannel } from "../../apiRequests/Channels";
import {
createProduct,
updateChannelInProduct
} from "../../apiRequests/Product";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import {
createFirstVariant,
createVariant,
variantsShouldBeVisible
} from "../../steps/catalog/products/VariantsSteps";
import { selectChannelInHeader } from "../../steps/channelsSteps";
2021-02-24 19:35:37 +00:00
import { urlList } from "../../url/urlList";
import {
deleteChannelsStartsWith,
getDefaultChannel
} from "../../utils/channelsUtils";
import * as productUtils from "../../utils/products/productsUtils";
import * as 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 = "CyCreateVariants-";
2021-02-26 15:39:42 +00:00
const attributeValues = ["value1", "value2"];
2021-02-24 19:35:37 +00:00
let defaultChannel;
let warehouse;
let attribute;
let productType;
let category;
before(() => {
cy.clearSessionData().loginUserViaRequest();
shippingUtils.deleteShippingStartsWith(startsWith);
productUtils.deleteProductsStartsWith(startsWith);
deleteChannelsStartsWith(startsWith);
2021-02-24 19:35:37 +00:00
const name = `${startsWith}${faker.random.number()}`;
getDefaultChannel()
2021-02-24 19:35:37 +00:00
.then(channel => {
defaultChannel = channel;
cy.fixture("addresses");
})
.then(fixtureAddresses =>
shippingUtils.createShipping({
channelId: defaultChannel.id,
name,
address: fixtureAddresses.plAddress
})
)
.then(({ warehouse: warehouseResp }) => (warehouse = warehouseResp));
2021-02-24 19:35:37 +00:00
2021-02-26 15:39:42 +00:00
productUtils
.createTypeAttributeAndCategoryForProduct(name, attributeValues)
.then(
({
attribute: attributeResp,
productType: productTypeResp,
category: categoryResp
}) => {
attribute = attributeResp;
productType = productTypeResp;
category = categoryResp;
}
);
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;
createProduct(attribute.id, name, productType.id, category.id)
2021-02-24 19:35:37 +00:00
.then(resp => {
createdProduct = resp.body.data.productCreate.product;
updateChannelInProduct({
2021-02-24 19:35:37 +00:00
productId: createdProduct.id,
channelId: defaultChannel.id
});
cy.visit(`${urlList.products}${createdProduct.id}`);
createFirstVariant({
2021-02-25 09:51:52 +00:00
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
});
selectChannelInHeader(defaultChannel.name);
variantsShouldBeVisible({ name, price });
2021-03-01 11:54:08 +00:00
getProductVariants(createdProduct.id, defaultChannel.slug);
2021-02-24 19:35:37 +00:00
})
2021-03-02 17:26:57 +00:00
.then(([variant]) => {
expect(variant).to.have.property("name", attributeValues[0]);
expect(variant).to.have.property("price", price);
2021-02-24 19:35:37 +00:00
});
});
xit("should create several variants", () => {
2021-02-24 19:35:37 +00:00
const name = `${startsWith}${faker.random.number()}`;
const secondVariantSku = `${startsWith}${faker.random.number()}`;
2021-03-02 17:26:57 +00:00
const variants = [{ price: 7 }, { name: attributeValues[1], price: 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-02 17:26:57 +00:00
price: variants[0].price
2021-02-24 19:35:37 +00:00
})
.then(({ product: productResp }) => {
createdProduct = productResp;
2021-02-24 19:35:37 +00:00
cy.visit(`${urlList.products}${createdProduct.id}`);
createVariant({
2021-02-26 14:32:01 +00:00
sku: secondVariantSku,
warehouseName: warehouse.name,
2021-03-01 11:54:08 +00:00
attributeName: variants[1].name,
2021-03-02 17:26:57 +00:00
price: variants[1].price
2021-02-26 14:32:01 +00:00
});
2021-02-24 19:35:37 +00:00
})
.then(() => {
selectChannelInHeader(defaultChannel.name);
variantsShouldBeVisible({
name: variants[1].name,
price: variants.price
});
getProductVariants(createdProduct.id, defaultChannel.slug);
})
2021-03-02 17:26:57 +00:00
.then(([firstVariant, secondVariant]) => {
expect(firstVariant).to.have.property("price", variants[0].price);
expect(secondVariant).to.have.property("name", variants[1].name);
expect(secondVariant).to.have.property("price", variants[1].price);
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;
createChannel(true, name, name, "PLN")
2021-02-24 19:35:37 +00:00
.then(resp => {
newChannel = resp.body.data.channelCreate.channel;
productUtils.createProduct(
attribute.id,
name,
productType.id,
category.id
);
})
.then(productResp => {
createdProduct = productResp;
updateChannelInProduct({
2021-02-24 19:35:37 +00:00
productId: createdProduct.id,
channelId: defaultChannel.id
});
})
.then(() => {
updateChannelInProduct({
2021-02-24 19:35:37 +00:00
productId: createdProduct.id,
channelId: newChannel.id
});
})
.then(() => {
cy.visit(`${urlList.products}${createdProduct.id}`);
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
});
selectChannelInHeader(defaultChannel.name);
variantsShouldBeVisible({ name, price: variantsPrice });
selectChannelInHeader(newChannel.name);
variantsShouldBeVisible({ name, price: variantsPrice });
2021-03-01 11:54:08 +00:00
getProductVariants(createdProduct.id, defaultChannel.slug);
2021-02-24 19:35:37 +00:00
})
2021-03-02 17:26:57 +00:00
.then(([variant]) => {
expect(variant).to.have.property("name", attributeValues[0]);
expect(variant).to.have.property("price", variantsPrice);
2021-03-01 11:54:08 +00:00
getProductVariants(createdProduct.id, newChannel.slug);
2021-02-24 19:35:37 +00:00
})
2021-03-02 17:26:57 +00:00
.then(([variant]) => {
expect(variant).to.have.property("name", attributeValues[0]);
expect(variant).to.have.property("price", variantsPrice);
2021-02-24 19:35:37 +00:00
});
});
});