2021-09-27 10:04:21 +00:00
|
|
|
import { SALES_SELECTORS } from "../../../elements/discounts/sales";
|
|
|
|
import { ASSIGN_ELEMENTS_SELECTORS } from "../../../elements/shared/assign-elements-selectors";
|
|
|
|
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
2021-10-21 10:47:18 +00:00
|
|
|
import { urlList } from "../../../fixtures/urlList";
|
2023-06-29 13:40:51 +00:00
|
|
|
import { getVariantWithSaleStatus } from "../../../support/api/utils/discounts/salesUtils";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { formatDate } from "../../../support/formatData/formatDate";
|
2021-10-21 10:47:18 +00:00
|
|
|
import { getVariant } from "../../api/requests/Product";
|
|
|
|
import { createProductInChannel } from "../../api/utils/products/productsUtils";
|
|
|
|
import { getProductPrice } from "../../api/utils/storeFront/storeFrontProductUtils";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { selectChannelInDetailsPages } from "../channelsPage";
|
2021-03-12 14:57:02 +00:00
|
|
|
|
|
|
|
export const discountOptions = {
|
|
|
|
PERCENTAGE: SALES_SELECTORS.percentageOption,
|
2022-06-27 16:49:35 +00:00
|
|
|
FIXED: SALES_SELECTORS.fixedOption,
|
2021-03-12 14:57:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function createSale({
|
|
|
|
saleName,
|
|
|
|
channelName,
|
|
|
|
discountValue = 10,
|
2022-06-27 16:49:35 +00:00
|
|
|
discountOption = discountOptions.PERCENTAGE,
|
2021-03-12 14:57:02 +00:00
|
|
|
}) {
|
|
|
|
const todaysDate = formatDate(new Date());
|
|
|
|
|
2021-09-27 10:04:21 +00:00
|
|
|
cy.get(SALES_SELECTORS.createSaleButton)
|
|
|
|
.click()
|
2021-03-12 14:57:02 +00:00
|
|
|
.get(SALES_SELECTORS.nameInput)
|
|
|
|
.type(saleName)
|
|
|
|
.get(discountOption)
|
2021-03-23 10:15:39 +00:00
|
|
|
.click();
|
|
|
|
selectChannelInDetailsPages(channelName);
|
|
|
|
cy.get(SALES_SELECTORS.discountValue)
|
2021-03-12 14:57:02 +00:00
|
|
|
.type(discountValue)
|
|
|
|
.get(SALES_SELECTORS.startDateInput)
|
2021-09-27 10:04:21 +00:00
|
|
|
.type(todaysDate)
|
|
|
|
.addAliasToGraphRequest("SaleCreate")
|
|
|
|
.get(SALES_SELECTORS.saveButton)
|
|
|
|
.click()
|
|
|
|
.waitForRequestAndCheckIfNoErrors("@SaleCreate");
|
2021-03-12 14:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function assignProducts(productName) {
|
2021-09-27 10:04:21 +00:00
|
|
|
cy.waitForProgressBarToNotBeVisible()
|
2021-07-15 09:20:59 +00:00
|
|
|
.get(SALES_SELECTORS.productsTab)
|
2021-03-12 14:57:02 +00:00
|
|
|
.click()
|
|
|
|
.get(SALES_SELECTORS.assignProducts)
|
|
|
|
.click()
|
2021-07-05 10:21:35 +00:00
|
|
|
.get(ASSIGN_ELEMENTS_SELECTORS.searchInput)
|
2021-03-12 14:57:02 +00:00
|
|
|
.type(productName);
|
2021-07-05 10:21:35 +00:00
|
|
|
cy.contains(ASSIGN_ELEMENTS_SELECTORS.productTableRow, productName)
|
|
|
|
.find(ASSIGN_ELEMENTS_SELECTORS.checkbox)
|
2021-03-12 14:57:02 +00:00
|
|
|
.click();
|
|
|
|
cy.addAliasToGraphRequest("SaleCataloguesAdd");
|
|
|
|
cy.get(BUTTON_SELECTORS.submit).click();
|
2021-09-27 10:04:21 +00:00
|
|
|
cy.waitForRequestAndCheckIfNoErrors("@SaleCataloguesAdd");
|
2021-03-12 14:57:02 +00:00
|
|
|
}
|
2021-10-21 10:47:18 +00:00
|
|
|
|
|
|
|
export function assignVariants(productName, variantName) {
|
|
|
|
cy.waitForProgressBarToNotBeVisible()
|
|
|
|
.get(SALES_SELECTORS.variantsTab)
|
|
|
|
.click()
|
|
|
|
.get(SALES_SELECTORS.assignVariants)
|
|
|
|
.click()
|
|
|
|
.get(ASSIGN_ELEMENTS_SELECTORS.searchInput)
|
|
|
|
.type(productName)
|
|
|
|
.get(ASSIGN_ELEMENTS_SELECTORS.variantTableRow)
|
|
|
|
.should("have.length", 1);
|
|
|
|
cy.contains(ASSIGN_ELEMENTS_SELECTORS.variantTableRow, variantName)
|
|
|
|
.find(ASSIGN_ELEMENTS_SELECTORS.checkbox)
|
|
|
|
.click();
|
|
|
|
cy.addAliasToGraphRequest("SaleCataloguesAdd");
|
|
|
|
cy.get(BUTTON_SELECTORS.submit).click();
|
|
|
|
cy.waitForRequestAndCheckIfNoErrors("@SaleCataloguesAdd");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createSaleWithNewProduct({
|
|
|
|
name,
|
|
|
|
channel,
|
|
|
|
warehouseId,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
price,
|
|
|
|
discountOption,
|
2022-06-27 16:49:35 +00:00
|
|
|
discountValue,
|
2023-01-25 10:32:28 +00:00
|
|
|
taxClassId,
|
2021-10-21 10:47:18 +00:00
|
|
|
}) {
|
|
|
|
return createProductInChannel({
|
|
|
|
name,
|
|
|
|
channelId: channel.id,
|
|
|
|
warehouseId,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
2022-06-27 16:49:35 +00:00
|
|
|
price,
|
2023-01-25 10:32:28 +00:00
|
|
|
taxClassId,
|
2021-10-21 10:47:18 +00:00
|
|
|
}).then(({ product: productResp }) => {
|
2022-08-24 19:02:30 +00:00
|
|
|
const product = productResp;
|
2021-10-21 10:47:18 +00:00
|
|
|
/* Uncomment after fixing SALEOR-3367 bug
|
|
|
|
cy.clearSessionData()
|
|
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
|
|
|
*/
|
2023-07-19 13:31:13 +00:00
|
|
|
cy.visit(urlList.sales);
|
2021-10-21 10:47:18 +00:00
|
|
|
createSale({
|
|
|
|
saleName: name,
|
|
|
|
channelName: channel.name,
|
|
|
|
discountValue,
|
2022-06-27 16:49:35 +00:00
|
|
|
discountOption,
|
2021-10-21 10:47:18 +00:00
|
|
|
});
|
|
|
|
assignProducts(product.name);
|
|
|
|
return getProductPrice(product.id, channel.slug);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createSaleWithNewVariant({
|
|
|
|
name,
|
|
|
|
channel,
|
|
|
|
warehouseId,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
price,
|
|
|
|
discountValue,
|
2022-06-27 16:49:35 +00:00
|
|
|
discountOption,
|
2021-10-21 10:47:18 +00:00
|
|
|
}) {
|
|
|
|
return createProductInChannel({
|
|
|
|
name,
|
|
|
|
channelId: channel.id,
|
|
|
|
warehouseId,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
2022-06-27 16:49:35 +00:00
|
|
|
price,
|
2021-10-21 10:47:18 +00:00
|
|
|
}).then(({ variantsList: variantsListResp, product }) => {
|
2022-08-24 19:02:30 +00:00
|
|
|
const variant = variantsListResp[0];
|
2021-10-21 10:47:18 +00:00
|
|
|
/* Uncomment after fixing SALEOR-3367 bug
|
|
|
|
cy.clearSessionData()
|
|
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
|
|
|
*/
|
2023-07-19 13:31:13 +00:00
|
|
|
cy.visit(urlList.sales);
|
2021-10-21 10:47:18 +00:00
|
|
|
createSale({
|
|
|
|
saleName: name,
|
|
|
|
channelName: channel.name,
|
|
|
|
discountValue,
|
2022-06-27 16:49:35 +00:00
|
|
|
discountOption,
|
2021-10-21 10:47:18 +00:00
|
|
|
});
|
|
|
|
assignVariants(product.name, variant.name);
|
2023-06-29 13:40:51 +00:00
|
|
|
getVariantWithSaleStatus({
|
|
|
|
channelSlug: channel.slug,
|
|
|
|
variantId: variant.id,
|
|
|
|
onSaleStatus: true,
|
|
|
|
});
|
2021-10-21 10:47:18 +00:00
|
|
|
return getVariant(variant.id, channel.slug, "token");
|
|
|
|
});
|
|
|
|
}
|