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-07-23 09:46:44 +00:00
|
|
|
import { PRODUCTS_LIST } from "../../elements/catalog/products/products-list";
|
|
|
|
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { urlList } from "../../fixtures/urlList";
|
|
|
|
import { ONE_PERMISSION_USERS } from "../../fixtures/users";
|
|
|
|
import { createAttribute } from "../../support/api/requests/Attribute";
|
|
|
|
import { createTypeProduct } from "../../support/api/requests/ProductType";
|
2021-07-23 09:46:44 +00:00
|
|
|
import {
|
|
|
|
expectCorrectProductInformation,
|
2022-06-27 16:49:35 +00:00
|
|
|
expectCorrectProductVariantInformation,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/api/utils/products/checkProductInfo";
|
|
|
|
import { metadataForms } from "../../support/pages/catalog/metadataComponent";
|
|
|
|
import {
|
|
|
|
fillUpPriceList,
|
2022-06-27 16:49:35 +00:00
|
|
|
priceInputLists,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/pages/catalog/products/priceListComponent";
|
2022-09-23 12:15:59 +00:00
|
|
|
import {
|
|
|
|
fillUpCommonFieldsForAllProductTypes,
|
|
|
|
fillUpProductTypeDialog,
|
|
|
|
} from "../../support/pages/catalog/products/productDetailsPage";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { selectChannelInDetailsPages } from "../../support/pages/channelsPage";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("As an admin I should be able to create product", () => {
|
|
|
|
const startsWith = "CyCreateProduct-";
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const generalInfo = {
|
|
|
|
name: `${startsWith}${faker.datatype.number()}`,
|
|
|
|
description: faker.lorem.sentence(),
|
2022-06-27 16:49:35 +00:00
|
|
|
rating: 2,
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
|
|
|
const seo = {
|
|
|
|
title: "testTitle",
|
2022-06-27 16:49:35 +00:00
|
|
|
description: generalInfo.description,
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
|
|
|
const metadata = {
|
|
|
|
public: {
|
|
|
|
metadataForm: metadataForms.public,
|
|
|
|
name: "metadataName",
|
2022-06-27 16:49:35 +00:00
|
|
|
value: "metadataValue",
|
2022-06-27 09:30:51 +00:00
|
|
|
},
|
|
|
|
private: {
|
|
|
|
metadataForm: metadataForms.private,
|
|
|
|
name: "privateMetadataName",
|
2022-06-27 16:49:35 +00:00
|
|
|
value: "privateMetadataValue",
|
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
|
|
|
let attribute;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
before(() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2022-06-27 09:30:51 +00:00
|
|
|
createAttribute({ name }).then(attributeResp => {
|
|
|
|
attribute = attributeResp;
|
2023-01-16 13:55:38 +00:00
|
|
|
cy.checkIfDataAreNotNull({ attribute });
|
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();
|
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 product with variants as an admin. SALEOR_2701",
|
2022-10-25 17:27:26 +00:00
|
|
|
{ tags: ["@products", "@allEnv", "@critical", "@stable", "@oldRelease"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const randomName = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
seo.slug = randomName;
|
|
|
|
const productData = {
|
|
|
|
generalInfo,
|
|
|
|
seo,
|
|
|
|
metadata,
|
|
|
|
productOrganization: { productType: randomName },
|
2022-06-27 16:49:35 +00:00
|
|
|
attribute,
|
2021-07-23 09:46:44 +00:00
|
|
|
};
|
|
|
|
createTpeAndFillUpProductFields(randomName, true, productData).then(
|
2022-06-27 16:49:35 +00:00
|
|
|
productOrgResp => (productData.productOrganization = productOrgResp),
|
2021-07-23 09:46:44 +00:00
|
|
|
);
|
2021-09-27 10:04:21 +00:00
|
|
|
cy.addAliasToGraphRequest("ProductDetails")
|
2022-11-08 10:20:02 +00:00
|
|
|
.addAliasToGraphRequest("ProductCreate")
|
2021-09-27 10:04:21 +00:00
|
|
|
.get(BUTTON_SELECTORS.confirm)
|
|
|
|
.click()
|
2022-11-08 10:20:02 +00:00
|
|
|
.waitForRequestAndCheckIfNoErrors("@ProductCreate")
|
2021-09-27 10:04:21 +00:00
|
|
|
.confirmationMessageShouldDisappear()
|
|
|
|
.waitForRequestAndCheckIfNoErrors("@ProductDetails")
|
|
|
|
.get("@ProductDetails")
|
2021-07-23 09:46:44 +00:00
|
|
|
.its("response.body")
|
|
|
|
.then(resp => {
|
2022-03-23 09:36:30 +00:00
|
|
|
let productResp;
|
|
|
|
if (Array.isArray(resp)) {
|
|
|
|
productResp = resp.find(element => element.data.product).data
|
|
|
|
.product;
|
|
|
|
} else {
|
|
|
|
productResp = resp.data.product;
|
|
|
|
}
|
2021-07-23 09:46:44 +00:00
|
|
|
expectCorrectProductInformation(productResp, productData);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
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 product without variants as an admin. SALEOR_2702",
|
2022-10-25 17:27:26 +00:00
|
|
|
{ tags: ["@products", "@allEnv", "@critical", "@stable", "@oldRelease"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const prices = { sellingPrice: 6, costPrice: 3 };
|
|
|
|
const randomName = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
seo.slug = randomName;
|
|
|
|
const productData = {
|
|
|
|
generalInfo,
|
|
|
|
seo,
|
|
|
|
metadata,
|
|
|
|
productOrganization: { productType: randomName },
|
2022-06-27 16:49:35 +00:00
|
|
|
attribute,
|
2021-07-23 09:46:44 +00:00
|
|
|
};
|
|
|
|
createTpeAndFillUpProductFields(randomName, false, productData).then(
|
2022-06-27 16:49:35 +00:00
|
|
|
productOrgResp => (productData.productOrganization = productOrgResp),
|
2021-07-23 09:46:44 +00:00
|
|
|
);
|
|
|
|
selectChannelInDetailsPages();
|
|
|
|
fillUpPriceList(prices.sellingPrice);
|
|
|
|
fillUpPriceList(prices.costPrice, priceInputLists.costPrice);
|
2021-09-27 10:04:21 +00:00
|
|
|
cy.get(PRODUCT_DETAILS.skuInput)
|
2023-06-20 08:29:28 +00:00
|
|
|
.type(randomName, { force: true })
|
2021-09-27 10:04:21 +00:00
|
|
|
.addAliasToGraphRequest("ProductDetails")
|
|
|
|
.get(BUTTON_SELECTORS.confirm)
|
|
|
|
.click()
|
|
|
|
.confirmationMessageShouldDisappear()
|
|
|
|
.wait("@ProductDetails")
|
|
|
|
.get("@ProductDetails")
|
2021-07-23 09:46:44 +00:00
|
|
|
.its("response.body")
|
|
|
|
.then(resp => {
|
2022-03-23 09:36:30 +00:00
|
|
|
let productResp;
|
|
|
|
if (Array.isArray(resp)) {
|
|
|
|
productResp = resp.find(element => element.data.product).data
|
|
|
|
.product;
|
|
|
|
} else {
|
|
|
|
productResp = resp.data.product;
|
|
|
|
}
|
2021-07-23 09:46:44 +00:00
|
|
|
expectCorrectProductInformation(productResp, productData);
|
|
|
|
expectCorrectProductVariantInformation(
|
|
|
|
productResp.variants,
|
|
|
|
randomName,
|
2022-06-27 16:49:35 +00:00
|
|
|
prices,
|
2021-07-23 09:46:44 +00:00
|
|
|
);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
function createTpeAndFillUpProductFields(
|
|
|
|
randomName,
|
|
|
|
hasVariants,
|
2022-06-27 16:49:35 +00:00
|
|
|
productData,
|
2022-06-27 09:30:51 +00:00
|
|
|
) {
|
|
|
|
createTypeProduct({
|
|
|
|
name: randomName,
|
|
|
|
attributeId: attribute.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
hasVariants,
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
|
|
|
cy.clearSessionData()
|
|
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.product)
|
|
|
|
.visit(urlList.products)
|
|
|
|
.get(PRODUCTS_LIST.createProductBtn)
|
|
|
|
.click();
|
2022-09-23 12:15:59 +00:00
|
|
|
fillUpProductTypeDialog(productData);
|
|
|
|
cy.get(BUTTON_SELECTORS.submit).click();
|
2022-06-27 09:30:51 +00:00
|
|
|
return fillUpCommonFieldsForAllProductTypes(productData);
|
|
|
|
}
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|