Saleor 7930 fix for sales tests (#2249)
* moving sales files to sales folder * refactor tests for sales for products * refactor of updateSales and createSalesForVariants tests
This commit is contained in:
parent
3684a55ba9
commit
1a41d24ac5
8 changed files with 406 additions and 394 deletions
|
@ -1,224 +0,0 @@
|
|||
/// <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";
|
||||
import { createCheckout } from "../../support/api/requests/Checkout";
|
||||
import { updateSale } from "../../support/api/requests/Discounts/Sales";
|
||||
import { createVariant, getVariant } from "../../support/api/requests/Product";
|
||||
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
||||
import {
|
||||
createSaleInChannel,
|
||||
createSaleInChannelWithProduct,
|
||||
deleteSalesStartsWith,
|
||||
} from "../../support/api/utils/discounts/salesUtils";
|
||||
import {
|
||||
createProductInChannel,
|
||||
createTypeAttributeAndCategoryForProduct,
|
||||
deleteProductsStartsWith,
|
||||
} from "../../support/api/utils/products/productsUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith,
|
||||
} from "../../support/api/utils/shippingUtils";
|
||||
|
||||
describe("Create sale with assigned products", () => {
|
||||
const startsWith = "CySales";
|
||||
const saleValue = 10;
|
||||
|
||||
let channel;
|
||||
let sale;
|
||||
let warehouse;
|
||||
let address;
|
||||
let productData;
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
deleteSalesStartsWith(startsWith);
|
||||
getDefaultChannel()
|
||||
.then(defaultChannel => {
|
||||
channel = defaultChannel;
|
||||
createSaleInChannel({
|
||||
name: startsWith,
|
||||
type: "FIXED",
|
||||
value: saleValue,
|
||||
channelId: channel.id,
|
||||
});
|
||||
})
|
||||
.then(saleResp => (sale = saleResp));
|
||||
cy.fixture("addresses")
|
||||
.then(addresses => {
|
||||
address = addresses.usAddress;
|
||||
createShipping({
|
||||
channelId: channel.id,
|
||||
address,
|
||||
name: startsWith,
|
||||
});
|
||||
})
|
||||
.then(({ warehouse: warehouseResp }) => {
|
||||
warehouse = warehouseResp;
|
||||
});
|
||||
createTypeAttributeAndCategoryForProduct({
|
||||
name: startsWith,
|
||||
attributeValues: ["value1", "value2"],
|
||||
}).then(({ attribute, category, productType }) => {
|
||||
productData = {
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
productTypeId: productType.id,
|
||||
channelId: channel.id,
|
||||
warehouseId: warehouse.id,
|
||||
price: 30,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
});
|
||||
|
||||
it(
|
||||
"should discount only variants added to sale",
|
||||
{ tags: ["@sales", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const productName = `${startsWith}${faker.datatype.number()}`;
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
let variantNotOnSale;
|
||||
let variantOnSale;
|
||||
|
||||
productData.name = productName;
|
||||
productData.sku = productName;
|
||||
createProductInChannel(productData)
|
||||
.then(({ product, variantsList }) => {
|
||||
variantNotOnSale = variantsList;
|
||||
productData.name = name;
|
||||
productData.sku = name;
|
||||
productData.productId = product.id;
|
||||
productData.quantityInWarehouse = 10;
|
||||
productData.attributeName = "value2";
|
||||
createVariant(productData);
|
||||
})
|
||||
.then(variantsList => {
|
||||
variantOnSale = variantsList;
|
||||
updateSale({ saleId: sale.id, variants: variantOnSale });
|
||||
})
|
||||
.then(() => {
|
||||
createCheckout({
|
||||
channelSlug: channel.slug,
|
||||
email: "example@example.com",
|
||||
address,
|
||||
variantsList: variantOnSale.concat(variantNotOnSale),
|
||||
});
|
||||
})
|
||||
.then(({ checkout }) => {
|
||||
const variantRespNotOnSale = checkout.lines.find(
|
||||
element => element.variant.id === variantNotOnSale[0].id,
|
||||
).variant;
|
||||
const variantRespOnSale = checkout.lines.find(
|
||||
element => element.variant.id === variantOnSale[0].id,
|
||||
).variant;
|
||||
expect(variantRespNotOnSale.pricing.onSale).to.be.false;
|
||||
expect(variantRespOnSale.pricing.onSale).to.be.true;
|
||||
expect(variantRespNotOnSale.pricing.price.gross.amount).to.eq(
|
||||
productData.price,
|
||||
);
|
||||
expect(variantRespOnSale.pricing.price.gross.amount).to.eq(
|
||||
productData.price - saleValue,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("should delete sale", { tags: ["@sales", "@allEnv", "@stable"] }, () => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
let variants;
|
||||
let saleToDelete;
|
||||
productData.name = name;
|
||||
productData.sku = name;
|
||||
createProductInChannel(productData)
|
||||
.then(({ variantsList }) => {
|
||||
variants = variantsList;
|
||||
createSaleInChannelWithProduct({
|
||||
name,
|
||||
type: "FIXED",
|
||||
value: saleValue,
|
||||
channelId: channel.id,
|
||||
variants,
|
||||
});
|
||||
})
|
||||
.then(saleResp => {
|
||||
saleToDelete = saleResp;
|
||||
getVariant(variants[0].id, channel.slug);
|
||||
})
|
||||
.then(variantResp => {
|
||||
expect(variantResp.pricing.onSale).to.be.true;
|
||||
expect(variantResp.pricing.price.gross.amount).to.eq(
|
||||
productData.price - saleValue,
|
||||
);
|
||||
cy.visit(saleDetailsUrl(saleToDelete.id))
|
||||
.addAliasToGraphRequest("SaleDelete")
|
||||
.get(BUTTON_SELECTORS.deleteButton)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.submit)
|
||||
.click()
|
||||
.wait("@SaleDelete");
|
||||
getVariant(variants[0].id, channel.slug);
|
||||
})
|
||||
.then(variantResp => {
|
||||
expect(variantResp.pricing.onSale).to.be.false;
|
||||
expect(variantResp.pricing.price.gross.amount).to.eq(productData.price);
|
||||
});
|
||||
});
|
||||
|
||||
xit(
|
||||
"should remove variant from sale",
|
||||
{ tags: ["@sales", "@allEnv"] },
|
||||
() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
let product;
|
||||
let variants;
|
||||
productData.name = name;
|
||||
productData.sku = name;
|
||||
createProductInChannel(productData)
|
||||
.then(({ variantsList, product: productResp }) => {
|
||||
product = productResp;
|
||||
variants = variantsList;
|
||||
updateSale({
|
||||
saleId: sale.id,
|
||||
variants,
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
getVariant(variants[0].id, channel.slug);
|
||||
})
|
||||
.then(variantResp => {
|
||||
expect(variantResp.pricing.onSale).to.be.true;
|
||||
expect(variantResp.pricing.price.gross.amount).to.eq(
|
||||
productData.price - saleValue,
|
||||
);
|
||||
cy.visit(saleDetailsUrl(sale.id))
|
||||
.get(SALES_SELECTORS.variantsTab)
|
||||
.click()
|
||||
.addAliasToGraphRequest("SaleCataloguesRemove");
|
||||
cy.contains(SHARED_ELEMENTS.tableRow, product.name)
|
||||
.find(BUTTON_SELECTORS.button)
|
||||
.click()
|
||||
.wait("@SaleCataloguesRemove");
|
||||
getVariant(variants[0].id, channel.slug);
|
||||
})
|
||||
.then(variantResp => {
|
||||
expect(variantResp.pricing.onSale).to.be.false;
|
||||
expect(variantResp.pricing.price.gross.amount).to.eq(
|
||||
productData.price,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
|
@ -1,28 +1,30 @@
|
|||
/// <reference types="cypress"/>
|
||||
/// <reference types="../../support"/>
|
||||
/// <reference types="../../../support"/>
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
import { urlList } from "../../fixtures/urlList";
|
||||
import { createChannel } from "../../support/api/requests/Channels";
|
||||
import { updateChannelInProduct } from "../../support/api/requests/Product";
|
||||
import * as channelsUtils from "../../support/api/utils/channelsUtils";
|
||||
import { deleteSalesStartsWith } from "../../support/api/utils/discounts/salesUtils";
|
||||
import * as productsUtils from "../../support/api/utils/products/productsUtils";
|
||||
import { urlList } from "../../../fixtures/urlList";
|
||||
import { createChannel } from "../../../support/api/requests/Channels";
|
||||
import { updateChannelInProduct } from "../../../support/api/requests/Product";
|
||||
import * as channelsUtils from "../../../support/api/utils/channelsUtils";
|
||||
import { deleteSalesStartsWith } from "../../../support/api/utils/discounts/salesUtils";
|
||||
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith,
|
||||
} from "../../support/api/utils/shippingUtils";
|
||||
import { getProductPrice } from "../../support/api/utils/storeFront/storeFrontProductUtils";
|
||||
} from "../../../support/api/utils/shippingUtils";
|
||||
import { getProductPrice } from "../../../support/api/utils/storeFront/storeFrontProductUtils";
|
||||
import {
|
||||
assignProducts,
|
||||
createSale,
|
||||
createSaleWithNewProduct,
|
||||
discountOptions,
|
||||
} from "../../support/pages/discounts/salesPage";
|
||||
} from "../../../support/pages/discounts/salesPage";
|
||||
|
||||
xdescribe("Sales discounts for products", () => {
|
||||
describe("As an admin I want to create sale for products", () => {
|
||||
const startsWith = "SalesProd-";
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
let productType;
|
||||
let attribute;
|
||||
|
@ -31,13 +33,13 @@ xdescribe("Sales discounts for products", () => {
|
|||
let warehouse;
|
||||
|
||||
before(() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||
deleteSalesStartsWith(startsWith);
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
|
@ -75,12 +77,11 @@ xdescribe("Sales discounts for products", () => {
|
|||
});
|
||||
|
||||
it(
|
||||
"should create percentage discount",
|
||||
{ tags: ["@sales", "@allEnv"] },
|
||||
"should be able to create percentage discount. TC: SALEOR_1801",
|
||||
{ tags: ["@sales", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
const expectedPrice = (productPrice * discountValue) / 100;
|
||||
|
||||
createSaleWithNewProduct({
|
||||
name: saleName,
|
||||
|
@ -92,20 +93,16 @@ xdescribe("Sales discounts for products", () => {
|
|||
price: productPrice,
|
||||
discountOption: discountOptions.PERCENTAGE,
|
||||
discountValue,
|
||||
}).then(price => {
|
||||
const expectedPrice = (productPrice * discountValue) / 100;
|
||||
expect(expectedPrice).to.be.eq(price);
|
||||
});
|
||||
}).should("eq", expectedPrice);
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"should create fixed price discount",
|
||||
{ tags: ["@sales", "@allEnv"] },
|
||||
"should be able to create fixed price discount. TC: SALEOR_1802",
|
||||
{ tags: ["@sales", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
const expectedPrice = productPrice - discountValue;
|
||||
|
||||
createSaleWithNewProduct({
|
||||
name: saleName,
|
||||
|
@ -117,22 +114,18 @@ xdescribe("Sales discounts for products", () => {
|
|||
price: productPrice,
|
||||
discountOption: discountOptions.FIXED,
|
||||
discountValue,
|
||||
}).then(price => {
|
||||
const expectedPrice = productPrice - discountValue;
|
||||
expect(expectedPrice).to.be.eq(price);
|
||||
});
|
||||
}).should("eq", expectedPrice);
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"should not displayed discount not assign to channel",
|
||||
{ tags: ["@sales", "@allEnv"] },
|
||||
"should not be able to see product discount not assign to channel. TC: SALEOR_1803",
|
||||
{ tags: ["@sales", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
let channel;
|
||||
let product;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
createChannel({ name: saleName }).then(
|
||||
channelResp => (channel = channelResp),
|
||||
|
@ -149,19 +142,18 @@ xdescribe("Sales discounts for products", () => {
|
|||
})
|
||||
.then(({ product: productResp }) => {
|
||||
product = productResp;
|
||||
|
||||
updateChannelInProduct({
|
||||
productId: product.id,
|
||||
channelId: channel.id,
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
/* Uncomment after fixing SALEOR-3367 bug
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
||||
*/
|
||||
|
||||
cy.visit(urlList.sales);
|
||||
cy.expectSkeletonIsVisible();
|
||||
cy.visit(urlList.sales)
|
||||
.expectSkeletonIsVisible()
|
||||
.waitForProgressBarToNotExist();
|
||||
createSale({
|
||||
saleName,
|
||||
channelName: channel.name,
|
||||
|
@ -170,7 +162,7 @@ xdescribe("Sales discounts for products", () => {
|
|||
assignProducts(product.name);
|
||||
getProductPrice(product.id, defaultChannel.slug);
|
||||
})
|
||||
.then(price => expect(price).to.equal(productPrice));
|
||||
.should("eq", productPrice);
|
||||
},
|
||||
);
|
||||
});
|
183
cypress/e2e/discounts/sales/createSalesForVariants.js
Normal file
183
cypress/e2e/discounts/sales/createSalesForVariants.js
Normal file
|
@ -0,0 +1,183 @@
|
|||
/// <reference types="cypress"/>
|
||||
/// <reference types="../../../support"/>
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
import { createCheckout } from "../../../support/api/requests/Checkout";
|
||||
import { updateSale } from "../../../support/api/requests/Discounts/Sales";
|
||||
import { createVariant } from "../../../support/api/requests/Product";
|
||||
import * as channelsUtils from "../../../support/api/utils/channelsUtils";
|
||||
import {
|
||||
createSaleInChannel,
|
||||
deleteSalesStartsWith,
|
||||
} from "../../../support/api/utils/discounts/salesUtils";
|
||||
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith,
|
||||
} from "../../../support/api/utils/shippingUtils";
|
||||
import { deleteWarehouseStartsWith } from "../../../support/api/utils/warehouseUtils";
|
||||
import {
|
||||
createSaleWithNewVariant,
|
||||
discountOptions,
|
||||
} from "../../../support/pages/discounts/salesPage";
|
||||
|
||||
describe("Sales discounts for variant", () => {
|
||||
const startsWith = "SalesVar-";
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
let defaultChannel;
|
||||
let warehouse;
|
||||
let productData;
|
||||
let address;
|
||||
|
||||
before(() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
deleteSalesStartsWith(startsWith);
|
||||
deleteWarehouseStartsWith(startsWith);
|
||||
channelsUtils.getDefaultChannel().then(channel => {
|
||||
defaultChannel = channel;
|
||||
});
|
||||
cy.fixture("addresses")
|
||||
.then(addresses => {
|
||||
address = addresses.usAddress;
|
||||
|
||||
createShipping({
|
||||
channelId: defaultChannel.id,
|
||||
address,
|
||||
name,
|
||||
});
|
||||
})
|
||||
.then(({ warehouse: warehouseResp }) => {
|
||||
warehouse = warehouseResp;
|
||||
});
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct({
|
||||
name,
|
||||
attributeValues: ["value1", "value2"],
|
||||
})
|
||||
.then(({ attribute, category, productType }) => {
|
||||
productData = {
|
||||
attributeId: attribute.id,
|
||||
attributeName: attribute.name,
|
||||
categoryId: category.id,
|
||||
productTypeId: productType.id,
|
||||
channelId: defaultChannel.id,
|
||||
warehouseId: warehouse.id,
|
||||
price: productPrice,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
});
|
||||
|
||||
it(
|
||||
"should not be able see product variant discount not assigned to channel. TC: SALEOR_1804",
|
||||
{ tags: ["@sales", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const productPriceOnSale = productPrice - discountValue;
|
||||
|
||||
let sale;
|
||||
let variantNotOnSale;
|
||||
|
||||
createSaleInChannel({
|
||||
name: saleName,
|
||||
type: "FIXED",
|
||||
value: discountValue,
|
||||
channelId: defaultChannel.id,
|
||||
}).then(saleResp => (sale = saleResp));
|
||||
productsUtils
|
||||
.createProductInChannel(productData)
|
||||
.then(({ product, variantsList }) => {
|
||||
variantNotOnSale = variantsList;
|
||||
|
||||
createVariant({
|
||||
productId: product.id,
|
||||
sku: saleName,
|
||||
attributeId: productData.attributeId,
|
||||
attributeName: "value2",
|
||||
warehouseId: warehouse.id,
|
||||
quantityInWarehouse: 10,
|
||||
channelId: defaultChannel.id,
|
||||
price: productPrice,
|
||||
weight: 10,
|
||||
});
|
||||
})
|
||||
.then(variantsList => {
|
||||
updateSale({ saleId: sale.id, variants: variantsList });
|
||||
createCheckout({
|
||||
channelSlug: defaultChannel.slug,
|
||||
email: "example@example.com",
|
||||
address,
|
||||
variantsList: variantsList.concat(variantNotOnSale),
|
||||
}).then(({ checkout }) => {
|
||||
const variantRespOnSale = checkout.lines[0].variant.pricing;
|
||||
const variantRespNotOnSale = checkout.lines[1].variant.pricing;
|
||||
|
||||
expect(variantRespOnSale.onSale).to.be.true;
|
||||
expect(variantRespOnSale.price.gross.amount).to.eq(
|
||||
productPriceOnSale,
|
||||
);
|
||||
expect(variantRespNotOnSale.onSale).to.be.false;
|
||||
expect(variantRespNotOnSale.price.gross.amount).to.eq(
|
||||
productData.price,
|
||||
);
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"should be able to create percentage discount. TC: SALEOR_1807",
|
||||
{ tags: ["@sales", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const expectedPrice = (productPrice * discountValue) / 100;
|
||||
|
||||
createSaleWithNewVariant({
|
||||
name: saleName,
|
||||
channel: defaultChannel,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productData.productTypeId,
|
||||
attributeId: productData.attributeId,
|
||||
categoryId: productData.categoryId,
|
||||
price: productPrice,
|
||||
discountOption: discountOptions.PERCENTAGE,
|
||||
discountValue,
|
||||
})
|
||||
.its("pricing.price.gross.amount")
|
||||
.should("eq", expectedPrice);
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"should be able to create fixed price discount. TC: SALEOR_1808",
|
||||
{ tags: ["@sales", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const expectedPrice = productPrice - discountValue;
|
||||
|
||||
createSaleWithNewVariant({
|
||||
name: saleName,
|
||||
channel: defaultChannel,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productData.productTypeId,
|
||||
attributeId: productData.attributeId,
|
||||
categoryId: productData.categoryId,
|
||||
price: productPrice,
|
||||
discountOption: discountOptions.FIXED,
|
||||
discountValue,
|
||||
})
|
||||
.its("pricing.price.gross.amount")
|
||||
.should("eq", expectedPrice);
|
||||
},
|
||||
);
|
||||
});
|
181
cypress/e2e/discounts/sales/updateSales.js
Normal file
181
cypress/e2e/discounts/sales/updateSales.js
Normal file
|
@ -0,0 +1,181 @@
|
|||
/// <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";
|
||||
import {
|
||||
getSales,
|
||||
updateSale,
|
||||
} from "../../../support/api/requests/Discounts/Sales";
|
||||
import { getVariant } from "../../../support/api/requests/Product";
|
||||
import { getDefaultChannel } from "../../../support/api/utils/channelsUtils";
|
||||
import {
|
||||
createSaleInChannel,
|
||||
createSaleInChannelWithProduct,
|
||||
deleteSalesStartsWith,
|
||||
} from "../../../support/api/utils/discounts/salesUtils";
|
||||
import {
|
||||
createProductInChannel,
|
||||
createTypeAttributeAndCategoryForProduct,
|
||||
deleteProductsStartsWith,
|
||||
} from "../../../support/api/utils/products/productsUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith,
|
||||
} from "../../../support/api/utils/shippingUtils";
|
||||
|
||||
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;
|
||||
|
||||
before(() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
deleteSalesStartsWith(startsWith);
|
||||
getDefaultChannel()
|
||||
.then(channel => {
|
||||
defaultChannel = channel;
|
||||
|
||||
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,
|
||||
});
|
||||
})
|
||||
.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,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
});
|
||||
|
||||
it(
|
||||
"should be able to delete sale. TC: SALEOR_1805",
|
||||
{ tags: ["@sales", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const productName = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
productData.name = productName;
|
||||
productData.sku = productName;
|
||||
|
||||
createProductInChannel(productData)
|
||||
.then(({ variantsList }) => {
|
||||
variants = variantsList;
|
||||
|
||||
createSaleInChannelWithProduct({
|
||||
name: productName,
|
||||
type: "FIXED",
|
||||
value: discountValue,
|
||||
channelId: defaultChannel.id,
|
||||
variants,
|
||||
});
|
||||
})
|
||||
.then(saleResp => {
|
||||
getVariant(variants[0].id, defaultChannel.slug)
|
||||
.its("pricing")
|
||||
.should("include", { onSale: true })
|
||||
.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");
|
||||
getVariant(variants[0].id, defaultChannel.slug)
|
||||
.its("pricing")
|
||||
.should("include", { onSale: false })
|
||||
.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,
|
||||
});
|
||||
getVariant(variants[0].id, defaultChannel.slug)
|
||||
.its("pricing")
|
||||
.should("include", { onSale: true })
|
||||
.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");
|
||||
getVariant(variants[0].id, defaultChannel.slug)
|
||||
.its("pricing")
|
||||
.should("include", { onSale: false })
|
||||
.its("price.gross.amount")
|
||||
.should("eq", productPrice);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
|
@ -1,121 +0,0 @@
|
|||
/// <reference types="cypress"/>
|
||||
/// <reference types="../../support"/>
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
import * as channelsUtils from "../../support/api/utils/channelsUtils";
|
||||
import { deleteSalesStartsWith } from "../../support/api/utils/discounts/salesUtils";
|
||||
import * as productsUtils from "../../support/api/utils/products/productsUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith,
|
||||
} from "../../support/api/utils/shippingUtils";
|
||||
import {
|
||||
createSaleWithNewVariant,
|
||||
discountOptions,
|
||||
} from "../../support/pages/discounts/salesPage";
|
||||
|
||||
xdescribe("Sales discounts for variant", () => {
|
||||
const startsWith = "SalesVar-";
|
||||
|
||||
let productType;
|
||||
let attribute;
|
||||
let category;
|
||||
let defaultChannel;
|
||||
let warehouse;
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteSalesStartsWith(startsWith);
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
({
|
||||
productType: productTypeResp,
|
||||
attribute: attributeResp,
|
||||
category: categoryResp,
|
||||
}) => {
|
||||
productType = productTypeResp;
|
||||
attribute = attributeResp;
|
||||
category = categoryResp;
|
||||
|
||||
channelsUtils.getDefaultChannel();
|
||||
},
|
||||
)
|
||||
.then(channel => {
|
||||
defaultChannel = channel;
|
||||
cy.fixture("addresses");
|
||||
})
|
||||
.then(addresses => {
|
||||
createShipping({
|
||||
channelId: defaultChannel.id,
|
||||
name,
|
||||
address: addresses.plAddress,
|
||||
price: 100,
|
||||
});
|
||||
})
|
||||
.then(({ warehouse: warehouseResp }) => {
|
||||
warehouse = warehouseResp;
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
});
|
||||
|
||||
it(
|
||||
"should create percentage discount",
|
||||
{ tags: ["@sales", "@allEnv"] },
|
||||
() => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
createSaleWithNewVariant({
|
||||
name: saleName,
|
||||
channel: defaultChannel,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice,
|
||||
discountOption: discountOptions.PERCENTAGE,
|
||||
discountValue,
|
||||
}).then(({ pricing }) => {
|
||||
const priceInResponse = pricing.price.gross.amount;
|
||||
const expectedPrice = (productPrice * discountValue) / 100;
|
||||
expect(expectedPrice).to.be.eq(priceInResponse);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"should create fixed price discount",
|
||||
{ tags: ["@sales", "@allEnv"] },
|
||||
() => {
|
||||
const saleName = `${startsWith}${faker.datatype.number()}`;
|
||||
const discountValue = 50;
|
||||
const productPrice = 100;
|
||||
|
||||
createSaleWithNewVariant({
|
||||
name: saleName,
|
||||
channel: defaultChannel,
|
||||
warehouseId: warehouse.id,
|
||||
productTypeId: productType.id,
|
||||
attributeId: attribute.id,
|
||||
categoryId: category.id,
|
||||
price: productPrice,
|
||||
discountOption: discountOptions.FIXED,
|
||||
discountValue,
|
||||
}).then(({ pricing }) => {
|
||||
const priceInResponse = pricing.price.gross.amount;
|
||||
const expectedPrice = productPrice - discountValue;
|
||||
expect(expectedPrice).to.be.eq(priceInResponse);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
|
@ -9,5 +9,5 @@ export const SALES_SELECTORS = {
|
|||
productsTab: "[data-test-id='products-tab']",
|
||||
variantsTab: "[data-test-id='variants-tab']",
|
||||
assignProducts: "[data-test-id='assign-products']",
|
||||
assignVariants: "[data-test-id='assign-variant']"
|
||||
assignVariants: "[data-test-id='assign-variant']",
|
||||
};
|
||||
|
|
|
@ -24,13 +24,13 @@ export const getProductVariants = (productId, channelSlug) => {
|
|||
return variantsList.map(element => ({
|
||||
id: element.id,
|
||||
name: element.name,
|
||||
price: element.pricing.price.gross.amount
|
||||
price: element.pricing.price.gross.amount,
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
export const getProductPrice = (productId, channelSlug) => {
|
||||
getProductDetails(productId, channelSlug).then(
|
||||
resp => resp.body.data.product.variants[0].pricing.price.gross.amount
|
||||
resp => resp.body.data.product.variants[0].pricing.price.gross.amount,
|
||||
);
|
||||
};
|
||||
|
|
|
@ -94,14 +94,14 @@ export function createSaleWithNewProduct({
|
|||
categoryId,
|
||||
price,
|
||||
}).then(({ product: productResp }) => {
|
||||
const product = productResp;
|
||||
/* Uncomment after fixing SALEOR-3367 bug
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
||||
*/
|
||||
|
||||
cy.visit(urlList.sales);
|
||||
cy.expectSkeletonIsVisible();
|
||||
const product = productResp;
|
||||
cy.visit(urlList.sales)
|
||||
.expectSkeletonIsVisible()
|
||||
.waitForProgressBarToNotExist();
|
||||
createSale({
|
||||
saleName: name,
|
||||
channelName: channel.name,
|
||||
|
@ -133,13 +133,14 @@ export function createSaleWithNewVariant({
|
|||
categoryId,
|
||||
price,
|
||||
}).then(({ variantsList: variantsListResp, product }) => {
|
||||
const variant = variantsListResp[0];
|
||||
/* Uncomment after fixing SALEOR-3367 bug
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
||||
*/
|
||||
cy.visit(urlList.sales);
|
||||
cy.expectSkeletonIsVisible();
|
||||
const variant = variantsListResp[0];
|
||||
cy.visit(urlList.sales)
|
||||
.expectSkeletonIsVisible()
|
||||
.waitForProgressBarToNotExist();
|
||||
createSale({
|
||||
saleName: name,
|
||||
channelName: channel.name,
|
||||
|
|
Loading…
Reference in a new issue