2022-08-24 19:02:30 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../../support"/>
|
|
|
|
|
|
|
|
import faker from "faker";
|
|
|
|
|
|
|
|
import { SALES_SELECTORS } from "../../../elements/discounts/sales";
|
|
|
|
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
|
|
|
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
|
|
|
|
import { saleDetailsUrl } from "../../../fixtures/urlList";
|
2022-10-20 05:36:49 +00:00
|
|
|
import { updateSale } from "../../../support/api/requests/Discounts/Sales";
|
2022-08-24 19:02:30 +00:00
|
|
|
import { getDefaultChannel } from "../../../support/api/utils/channelsUtils";
|
|
|
|
import {
|
|
|
|
createSaleInChannel,
|
|
|
|
createSaleInChannelWithProduct,
|
|
|
|
deleteSalesStartsWith,
|
2023-06-29 13:40:51 +00:00
|
|
|
getVariantWithSaleStatus,
|
2022-08-24 19:02:30 +00:00
|
|
|
} from "../../../support/api/utils/discounts/salesUtils";
|
|
|
|
import {
|
|
|
|
createProductInChannel,
|
|
|
|
createTypeAttributeAndCategoryForProduct,
|
|
|
|
deleteProductsStartsWith,
|
|
|
|
} from "../../../support/api/utils/products/productsUtils";
|
|
|
|
import {
|
|
|
|
createShipping,
|
|
|
|
deleteShippingStartsWith,
|
|
|
|
} from "../../../support/api/utils/shippingUtils";
|
2023-01-25 10:32:28 +00:00
|
|
|
import {
|
|
|
|
getDefaultTaxClass,
|
|
|
|
updateTaxConfigurationForChannel,
|
|
|
|
} from "../../../support/api/utils/taxesUtils";
|
2022-08-24 19:02:30 +00:00
|
|
|
|
|
|
|
describe("As an admin I want to update sales", () => {
|
|
|
|
const startsWith = "CySales";
|
|
|
|
const discountValue = 10;
|
|
|
|
const productPrice = 30;
|
|
|
|
const productPriceOnSale = productPrice - discountValue;
|
|
|
|
|
|
|
|
let defaultChannel;
|
|
|
|
let sale;
|
|
|
|
let warehouse;
|
|
|
|
let address;
|
|
|
|
let productData;
|
|
|
|
let variants;
|
2023-01-25 10:32:28 +00:00
|
|
|
let taxClass;
|
2022-08-24 19:02:30 +00:00
|
|
|
|
|
|
|
before(() => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2022-08-24 19:02:30 +00:00
|
|
|
deleteProductsStartsWith(startsWith);
|
|
|
|
deleteShippingStartsWith(startsWith);
|
|
|
|
deleteSalesStartsWith(startsWith);
|
|
|
|
getDefaultChannel()
|
|
|
|
.then(channel => {
|
|
|
|
defaultChannel = channel;
|
2023-01-25 10:32:28 +00:00
|
|
|
getDefaultTaxClass();
|
|
|
|
})
|
|
|
|
.then(taxResp => {
|
|
|
|
taxClass = taxResp;
|
2022-08-24 19:02:30 +00:00
|
|
|
createSaleInChannel({
|
|
|
|
name,
|
|
|
|
type: "FIXED",
|
|
|
|
value: discountValue,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(saleResp => (sale = saleResp));
|
|
|
|
cy.fixture("addresses")
|
|
|
|
.then(addresses => {
|
|
|
|
address = addresses.usAddress;
|
|
|
|
|
|
|
|
createShipping({
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
address,
|
|
|
|
name: startsWith,
|
2023-01-25 10:32:28 +00:00
|
|
|
taxClassId: taxClass.id,
|
2022-08-24 19:02:30 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(({ warehouse: warehouseResp }) => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
});
|
|
|
|
createTypeAttributeAndCategoryForProduct({
|
|
|
|
name,
|
|
|
|
attributeValues: ["value1", "value2"],
|
|
|
|
}).then(({ attribute, category, productType }) => {
|
|
|
|
productData = {
|
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
warehouseId: warehouse.id,
|
|
|
|
price: productPrice,
|
2023-01-25 10:32:28 +00:00
|
|
|
taxClassId: taxClass.id,
|
2022-08-24 19:02:30 +00:00
|
|
|
};
|
2023-01-16 13:55:38 +00:00
|
|
|
cy.checkIfDataAreNotNull({
|
|
|
|
productData,
|
|
|
|
defaultChannel,
|
|
|
|
warehouse,
|
|
|
|
address,
|
|
|
|
sale,
|
|
|
|
variants,
|
|
|
|
});
|
2022-08-24 19:02:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2023-01-25 10:32:28 +00:00
|
|
|
updateTaxConfigurationForChannel({
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
pricesEnteredWithTax: true,
|
|
|
|
});
|
2022-08-24 19:02:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it(
|
|
|
|
"should be able to delete sale. TC: SALEOR_1805",
|
|
|
|
{ tags: ["@sales", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
|
|
|
const productName = `${startsWith}${faker.datatype.number()}`;
|
2023-06-29 13:40:51 +00:00
|
|
|
const productSku = `${startsWith}${faker.datatype.number()}`;
|
2022-08-24 19:02:30 +00:00
|
|
|
|
|
|
|
productData.name = productName;
|
2023-06-29 13:40:51 +00:00
|
|
|
productData.sku = productSku;
|
2022-08-24 19:02:30 +00:00
|
|
|
|
|
|
|
createProductInChannel(productData)
|
|
|
|
.then(({ variantsList }) => {
|
|
|
|
variants = variantsList;
|
|
|
|
|
|
|
|
createSaleInChannelWithProduct({
|
|
|
|
name: productName,
|
|
|
|
type: "FIXED",
|
|
|
|
value: discountValue,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
variants,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(saleResp => {
|
2023-06-29 13:40:51 +00:00
|
|
|
getVariantWithSaleStatus({
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
variantId: variants[0].id,
|
|
|
|
onSaleStatus: true,
|
|
|
|
})
|
2022-08-24 19:02:30 +00:00
|
|
|
.its("pricing")
|
|
|
|
.its("price.gross.amount")
|
|
|
|
.should("eq", productPriceOnSale);
|
|
|
|
cy.visit(saleDetailsUrl(saleResp.id))
|
|
|
|
.addAliasToGraphRequest("SaleDelete")
|
|
|
|
.get(BUTTON_SELECTORS.deleteButton)
|
|
|
|
.click()
|
|
|
|
.get(BUTTON_SELECTORS.submit)
|
|
|
|
.click()
|
|
|
|
.wait("@SaleDelete");
|
2023-06-29 13:40:51 +00:00
|
|
|
getVariantWithSaleStatus({
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
variantId: variants[0].id,
|
|
|
|
onSaleStatus: false,
|
|
|
|
})
|
2022-08-24 19:02:30 +00:00
|
|
|
.its("pricing")
|
|
|
|
.its("price.gross.amount")
|
|
|
|
.should("eq", productPrice);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"should be able to remove variant from sale. TC: SALEOR_1806",
|
|
|
|
{ tags: ["@sales", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
|
|
|
const productName = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
|
|
|
let product;
|
|
|
|
productData.name = productName;
|
|
|
|
productData.sku = productName;
|
|
|
|
|
|
|
|
createProductInChannel(productData).then(
|
|
|
|
({ variantsList, product: productResp }) => {
|
|
|
|
product = productResp;
|
|
|
|
variants = variantsList;
|
|
|
|
|
|
|
|
updateSale({
|
|
|
|
saleId: sale.id,
|
|
|
|
variants,
|
|
|
|
});
|
2023-06-29 13:40:51 +00:00
|
|
|
getVariantWithSaleStatus({
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
variantId: variants[0].id,
|
|
|
|
onSaleStatus: true,
|
|
|
|
})
|
2022-08-24 19:02:30 +00:00
|
|
|
.its("pricing")
|
|
|
|
.its("price.gross.amount")
|
|
|
|
.should("eq", productPriceOnSale);
|
|
|
|
cy.visit(saleDetailsUrl(sale.id))
|
|
|
|
.get(SALES_SELECTORS.variantsTab)
|
|
|
|
.click()
|
|
|
|
.addAliasToGraphRequest("SaleCataloguesRemove");
|
|
|
|
cy.contains(SHARED_ELEMENTS.tableRow, product.name)
|
|
|
|
.find(BUTTON_SELECTORS.button)
|
|
|
|
.click()
|
|
|
|
.get(BUTTON_SELECTORS.submit)
|
|
|
|
.click()
|
|
|
|
.wait("@SaleCataloguesRemove");
|
2023-06-29 13:40:51 +00:00
|
|
|
getVariantWithSaleStatus({
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
variantId: variants[0].id,
|
|
|
|
onSaleStatus: false,
|
|
|
|
})
|
2022-08-24 19:02:30 +00:00
|
|
|
.its("pricing")
|
|
|
|
.its("price.gross.amount")
|
|
|
|
.should("eq", productPrice);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|