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";
|
|
|
|
|
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,
|
|
|
|
updateChannelInProduct
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/api/requests/Product";
|
2022-03-21 12:17:37 +00:00
|
|
|
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
2021-09-27 10:04:21 +00:00
|
|
|
import * as productUtils from "../../support/api/utils/products/productsUtils";
|
|
|
|
import * as shippingUtils from "../../support/api/utils/shippingUtils";
|
|
|
|
import { getProductVariants } from "../../support/api/utils/storeFront/storeFrontProductUtils";
|
|
|
|
import filterTests from "../../support/filterTests";
|
2021-07-23 09:46:44 +00:00
|
|
|
import {
|
|
|
|
createFirstVariant,
|
|
|
|
createVariant,
|
|
|
|
variantsShouldBeVisible
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/pages/catalog/products/VariantsPage";
|
2022-03-21 12:17:37 +00:00
|
|
|
import {
|
|
|
|
enterHomePageChangeChannelAndReturn,
|
|
|
|
selectChannelInHeader
|
|
|
|
} from "../../support/pages/channelsPage";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-03-21 12:17:37 +00:00
|
|
|
filterTests({ definedTags: ["all", "critical", "refactored"] }, () => {
|
|
|
|
describe("As an admin I should be able to create variant", () => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const startsWith = "CyCreateVariants-";
|
|
|
|
const attributeValues = ["value1", "value2"];
|
|
|
|
|
|
|
|
let defaultChannel;
|
|
|
|
let warehouse;
|
|
|
|
let attribute;
|
|
|
|
let productType;
|
|
|
|
let category;
|
|
|
|
let newChannel;
|
|
|
|
|
|
|
|
before(() => {
|
2022-03-21 12:17:37 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
2021-07-23 09:46:44 +00:00
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
|
2022-03-21 12:17:37 +00:00
|
|
|
productUtils
|
|
|
|
.createShippingProductTypeAttributeAndCategory(name, attributeValues)
|
|
|
|
.then(resp => {
|
|
|
|
attribute = resp.attribute;
|
|
|
|
productType = resp.productType;
|
|
|
|
category = resp.category;
|
|
|
|
defaultChannel = resp.defaultChannel;
|
|
|
|
warehouse = resp.warehouse;
|
|
|
|
|
2021-11-03 11:15:39 +00:00
|
|
|
createChannel({ isActive: true, name, currencyCode: "USD" });
|
2021-07-23 09:46:44 +00:00
|
|
|
})
|
|
|
|
.then(resp => (newChannel = resp));
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest(
|
|
|
|
"auth",
|
|
|
|
ONE_PERMISSION_USERS.product
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-03-21 12:17:37 +00:00
|
|
|
it("should be able to create variant visible for the customers in all channels. TC: SALEOR_2901", () => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const price = 10;
|
|
|
|
let createdProduct;
|
|
|
|
|
|
|
|
createProduct({
|
|
|
|
attributeId: attribute.id,
|
|
|
|
name,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
categoryId: category.id
|
|
|
|
})
|
|
|
|
.then(resp => {
|
|
|
|
createdProduct = resp;
|
|
|
|
updateChannelInProduct({
|
|
|
|
productId: createdProduct.id,
|
|
|
|
channelId: defaultChannel.id
|
|
|
|
});
|
2022-03-21 12:17:37 +00:00
|
|
|
updateChannelInProduct({
|
|
|
|
productId: createdProduct.id,
|
|
|
|
channelId: newChannel.id
|
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
cy.visit(`${urlList.products}${createdProduct.id}`);
|
|
|
|
createFirstVariant({
|
|
|
|
sku: name,
|
|
|
|
price,
|
|
|
|
attribute: attributeValues[0]
|
|
|
|
});
|
2021-09-10 08:59:46 +00:00
|
|
|
enterHomePageChangeChannelAndReturn(defaultChannel.name);
|
2021-07-23 09:46:44 +00:00
|
|
|
variantsShouldBeVisible({ name, price });
|
|
|
|
getProductVariants(createdProduct.id, defaultChannel.slug);
|
|
|
|
})
|
2022-03-21 12:17:37 +00:00
|
|
|
.then(([variant]) => {
|
|
|
|
expect(variant).to.have.property("name", attributeValues[0]);
|
|
|
|
expect(variant).to.have.property("price", price);
|
|
|
|
selectChannelInHeader(newChannel.name);
|
|
|
|
variantsShouldBeVisible({ name, price });
|
|
|
|
getProductVariants(createdProduct.id, defaultChannel.slug);
|
|
|
|
})
|
|
|
|
.then(([variant]) => {
|
|
|
|
expect(variant).to.have.property("name", attributeValues[0]);
|
|
|
|
expect(variant).to.have.property("price", price);
|
|
|
|
getProductVariants(createdProduct.id, newChannel.slug);
|
|
|
|
})
|
2021-07-23 09:46:44 +00:00
|
|
|
.then(([variant]) => {
|
|
|
|
expect(variant).to.have.property("name", attributeValues[0]);
|
|
|
|
expect(variant).to.have.property("price", price);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-03-21 12:17:37 +00:00
|
|
|
it("should be able to create several variants visible for the customers. TC: SALEOR_2902", () => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const secondVariantSku = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
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,
|
|
|
|
price: variants[0].price
|
|
|
|
})
|
|
|
|
.then(({ product: productResp }) => {
|
|
|
|
createdProduct = productResp;
|
|
|
|
cy.visit(`${urlList.products}${createdProduct.id}`);
|
|
|
|
createVariant({
|
|
|
|
sku: secondVariantSku,
|
|
|
|
attributeName: variants[1].name,
|
|
|
|
price: variants[1].price,
|
|
|
|
channelName: defaultChannel.name
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(() => {
|
2021-09-10 08:59:46 +00:00
|
|
|
enterHomePageChangeChannelAndReturn(defaultChannel.name);
|
2021-07-23 09:46:44 +00:00
|
|
|
variantsShouldBeVisible({
|
|
|
|
name: variants[1].name,
|
|
|
|
price: variants[1].price
|
|
|
|
});
|
|
|
|
getProductVariants(createdProduct.id, defaultChannel.slug);
|
|
|
|
})
|
|
|
|
.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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|