2021-09-27 10:04:21 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../support"/>
|
|
|
|
|
2021-07-23 09:46:44 +00:00
|
|
|
import faker from "faker";
|
|
|
|
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
PRODUCT_DETAILS,
|
|
|
|
} from "../../elements/catalog/products/product-details";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { urlList } from "../../fixtures/urlList";
|
|
|
|
import { ONE_PERMISSION_USERS } from "../../fixtures/users";
|
|
|
|
import { createChannel } from "../../support/api/requests/Channels";
|
2021-07-23 09:46:44 +00:00
|
|
|
import {
|
|
|
|
createProduct,
|
2022-06-27 16:49:35 +00:00
|
|
|
updateChannelInProduct,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/api/requests/Product";
|
|
|
|
import * as productUtils from "../../support/api/utils/products/productsUtils";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
getProductVariants,
|
|
|
|
} from "../../support/api/utils/storeFront/storeFrontProductUtils";
|
2022-10-20 09:16:50 +00:00
|
|
|
import {
|
|
|
|
addVariantToDataGrid,
|
|
|
|
enterVariantEditPage,
|
|
|
|
} from "../../support/pages/catalog/products/productDetailsPage";
|
|
|
|
import {
|
|
|
|
createVariant,
|
|
|
|
selectChannelsForVariant,
|
|
|
|
} from "../../support/pages/catalog/products/VariantsPage";
|
2023-01-25 10:32:28 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("As an admin I should be able to create variant", () => {
|
|
|
|
const startsWith = "CyCreateVariants-";
|
|
|
|
const attributeValues = ["value1", "value2"];
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
let defaultChannel;
|
|
|
|
let warehouse;
|
|
|
|
let attribute;
|
|
|
|
let productType;
|
|
|
|
let category;
|
|
|
|
let newChannel;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
before(() => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
2022-03-21 12:17:37 +00:00
|
|
|
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
productUtils
|
|
|
|
.createShippingProductTypeAttributeAndCategory(name, attributeValues)
|
|
|
|
.then(resp => {
|
|
|
|
attribute = resp.attribute;
|
|
|
|
productType = resp.productType;
|
|
|
|
category = resp.category;
|
|
|
|
defaultChannel = resp.defaultChannel;
|
|
|
|
warehouse = resp.warehouse;
|
2022-03-21 12:17:37 +00:00
|
|
|
|
2022-10-18 09:10:15 +00:00
|
|
|
createChannel({ isActive: true, name, currencyCode: "PLN" });
|
2022-06-27 09:30:51 +00:00
|
|
|
})
|
2023-01-16 09:43:13 +00:00
|
|
|
.then(resp => {
|
2023-01-16 13:55:38 +00:00
|
|
|
newChannel = resp;
|
2023-01-16 09:43:13 +00:00
|
|
|
});
|
2023-01-25 10:32:28 +00:00
|
|
|
cy.checkIfDataAreNotNull({
|
|
|
|
defaultChannel,
|
|
|
|
warehouse,
|
|
|
|
attribute,
|
|
|
|
productType,
|
|
|
|
category,
|
|
|
|
newChannel,
|
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
beforeEach(() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest("auth", ONE_PERMISSION_USERS.product);
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to create variant visible for the customers in all channels. TC: SALEOR_2901",
|
2023-02-23 15:41:35 +00:00
|
|
|
{ tags: ["@variants", "@allEnv", "@stable", "@oldRelease"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const price = 10;
|
|
|
|
let createdProduct;
|
2023-05-05 09:34:35 +00:00
|
|
|
// TODO fix name for proper one when problem with typing in grid will be solved - now only first letter of string is able to be typed in grid cell
|
|
|
|
const variantName = "A";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
|
|
|
createProduct({
|
|
|
|
attributeId: attribute.id,
|
|
|
|
name,
|
|
|
|
productTypeId: productType.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
categoryId: category.id,
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.then(resp => {
|
|
|
|
createdProduct = resp;
|
2022-10-18 09:10:15 +00:00
|
|
|
|
2021-07-23 09:46:44 +00:00
|
|
|
updateChannelInProduct({
|
|
|
|
productId: createdProduct.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
channelId: defaultChannel.id,
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
2022-03-21 12:17:37 +00:00
|
|
|
updateChannelInProduct({
|
|
|
|
productId: createdProduct.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
channelId: newChannel.id,
|
2022-03-21 12:17:37 +00:00
|
|
|
});
|
2022-10-20 09:16:50 +00:00
|
|
|
cy.visit(
|
|
|
|
`${urlList.products}${createdProduct.id}`,
|
|
|
|
).waitForProgressBarToNotBeVisible();
|
2023-05-05 09:34:35 +00:00
|
|
|
addVariantToDataGrid(variantName);
|
2022-10-20 09:16:50 +00:00
|
|
|
enterVariantEditPage();
|
|
|
|
selectChannelsForVariant();
|
2023-05-05 09:34:35 +00:00
|
|
|
cy.addAliasToGraphRequest("VariantUpdate");
|
2022-08-10 10:29:17 +00:00
|
|
|
createVariant({
|
|
|
|
channelName: [defaultChannel.name, newChannel.name],
|
2021-07-23 09:46:44 +00:00
|
|
|
sku: name,
|
|
|
|
price,
|
2022-08-10 10:29:17 +00:00
|
|
|
attributeName: attributeValues[0],
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
2023-05-05 09:34:35 +00:00
|
|
|
cy.wait("@VariantUpdate");
|
2021-07-23 09:46:44 +00:00
|
|
|
getProductVariants(createdProduct.id, defaultChannel.slug);
|
|
|
|
})
|
2022-03-21 12:17:37 +00:00
|
|
|
.then(([variant]) => {
|
2023-05-05 09:34:35 +00:00
|
|
|
expect(variant).to.have.property("name", variantName);
|
2022-03-21 12:17:37 +00:00
|
|
|
expect(variant).to.have.property("price", price);
|
2022-10-18 09:10:15 +00:00
|
|
|
expect(variant).to.have.property("currency", "USD");
|
2022-03-21 12:17:37 +00:00
|
|
|
getProductVariants(createdProduct.id, newChannel.slug);
|
|
|
|
})
|
2021-07-23 09:46:44 +00:00
|
|
|
.then(([variant]) => {
|
2023-05-05 09:34:35 +00:00
|
|
|
expect(variant).to.have.property("name", variantName);
|
2021-07-23 09:46:44 +00:00
|
|
|
expect(variant).to.have.property("price", price);
|
2022-10-18 09:10:15 +00:00
|
|
|
expect(variant).to.have.property("currency", "PLN");
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2023-02-23 15:41:35 +00:00
|
|
|
it(
|
|
|
|
"should be able to create variant. TC: SALEOR_2900",
|
|
|
|
{ tags: ["@variants", "@allEnv", "@critical", "@stable", "@oldRelease"] },
|
|
|
|
() => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let createdProduct;
|
|
|
|
|
|
|
|
createProduct({
|
|
|
|
attributeId: attribute.id,
|
|
|
|
name,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
categoryId: category.id,
|
|
|
|
}).then(resp => {
|
|
|
|
createdProduct = resp;
|
|
|
|
|
|
|
|
updateChannelInProduct({
|
|
|
|
productId: createdProduct.id,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
});
|
|
|
|
updateChannelInProduct({
|
|
|
|
productId: createdProduct.id,
|
|
|
|
channelId: newChannel.id,
|
|
|
|
});
|
|
|
|
cy.visit(
|
|
|
|
`${urlList.products}${createdProduct.id}`,
|
|
|
|
).waitForProgressBarToNotBeVisible();
|
|
|
|
addVariantToDataGrid(name);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to create several variants visible for the customers. TC: SALEOR_2902",
|
2022-10-25 17:27:26 +00:00
|
|
|
{ tags: ["@variants", "@allEnv", "@critical", "@stable", "@oldRelease"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const secondVariantSku = `${startsWith}${faker.datatype.number()}`;
|
2023-05-05 09:34:35 +00:00
|
|
|
const secondVariantName = `${startsWith}${faker.datatype.number()}`;
|
2021-07-23 09:46:44 +00:00
|
|
|
const variants = [{ price: 7 }, { name: attributeValues[1], price: 16 }];
|
|
|
|
let createdProduct;
|
|
|
|
|
|
|
|
productUtils
|
|
|
|
.createProductInChannel({
|
|
|
|
name,
|
|
|
|
attributeId: attribute.id,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
warehouseId: warehouse.id,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
categoryId: category.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
price: variants[0].price,
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.then(({ product: productResp }) => {
|
|
|
|
createdProduct = productResp;
|
2022-10-18 09:10:15 +00:00
|
|
|
|
2022-10-20 09:16:50 +00:00
|
|
|
cy.visit(`${urlList.products}${createdProduct.id}`);
|
2023-02-23 15:41:35 +00:00
|
|
|
cy.get(PRODUCT_DETAILS.dataGridTable).scrollIntoView();
|
2022-10-20 09:16:50 +00:00
|
|
|
enterVariantEditPage();
|
|
|
|
cy.get(PRODUCT_DETAILS.addVariantButton)
|
2022-10-18 09:10:15 +00:00
|
|
|
.click()
|
|
|
|
.then(() => {
|
2023-05-05 09:34:35 +00:00
|
|
|
cy.addAliasToGraphRequest("VariantCreate");
|
2022-10-18 09:10:15 +00:00
|
|
|
createVariant({
|
|
|
|
sku: secondVariantSku,
|
|
|
|
attributeName: variants[1].name,
|
|
|
|
price: variants[1].price,
|
|
|
|
channelName: defaultChannel.name,
|
2023-05-05 09:34:35 +00:00
|
|
|
variantName: secondVariantName,
|
2022-10-18 09:10:15 +00:00
|
|
|
});
|
2023-05-05 09:34:35 +00:00
|
|
|
cy.wait("@VariantCreate");
|
2022-10-18 09:10:15 +00:00
|
|
|
getProductVariants(createdProduct.id, defaultChannel.slug);
|
|
|
|
})
|
2023-02-15 13:31:45 +00:00
|
|
|
.then(([secondVariant, firstVariant]) => {
|
2022-10-18 09:10:15 +00:00
|
|
|
expect(firstVariant).to.have.property("price", variants[0].price);
|
|
|
|
expect(firstVariant).to.have.property("name", "value");
|
|
|
|
expect(firstVariant).to.have.property("currency", "USD");
|
2023-05-05 09:34:35 +00:00
|
|
|
expect(secondVariant).to.have.property("name", secondVariantName);
|
2022-10-18 09:10:15 +00:00
|
|
|
expect(secondVariant).to.have.property(
|
|
|
|
"price",
|
|
|
|
variants[1].price,
|
|
|
|
);
|
|
|
|
expect(secondVariant).to.have.property("currency", "USD");
|
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|