
* reference type cypress working * refactor * remove screenshots * add reference * add slash marker * run tests based on shop version * fix run tests based on shop version * fix run tests based on shop version * change base url to localhost * fix plugins * fix plugins * fix plugins * fix plugins * fix plugins * fix plugins * fix yml * fix yml * chage file names * fix files names * fix broken imports add checking for errors in grpah responses * fix broken imports add checking for errors in grpah responses * update jest * fix snapshot
202 lines
6.2 KiB
JavaScript
202 lines
6.2 KiB
JavaScript
/// <reference types="cypress"/>
|
|
/// <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 {
|
|
createShipping,
|
|
deleteShippingStartsWith
|
|
} from "../../support/api/utils/shippingUtils";
|
|
import { getProductPrice } from "../../support/api/utils/storeFront/storeFrontProductUtils";
|
|
import filterTests from "../../support/filterTests";
|
|
import {
|
|
assignProducts,
|
|
createSale,
|
|
discountOptions
|
|
} from "../../support/pages/discounts/salesPage";
|
|
|
|
filterTests({ definedTags: ["all"] }, () => {
|
|
describe("Sales discounts", () => {
|
|
const startsWith = "CySales-";
|
|
|
|
let productType;
|
|
let attribute;
|
|
let category;
|
|
let defaultChannel;
|
|
let warehouse;
|
|
|
|
before(() => {
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
channelsUtils.deleteChannelsStartsWith(startsWith);
|
|
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", () => {
|
|
const saleName = `${startsWith}${faker.datatype.number()}`;
|
|
const discountValue = 50;
|
|
const productPrice = 100;
|
|
|
|
productsUtils
|
|
.createProductInChannel({
|
|
name: saleName,
|
|
channelId: defaultChannel.id,
|
|
warehouseId: warehouse.id,
|
|
productTypeId: productType.id,
|
|
attributeId: attribute.id,
|
|
categoryId: category.id,
|
|
price: productPrice
|
|
})
|
|
.then(({ product: productResp }) => {
|
|
/* Uncomment after fixing SALEOR-3367 bug
|
|
cy.clearSessionData()
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
|
*/
|
|
|
|
cy.visit(urlList.sales);
|
|
cy.softExpectSkeletonIsVisible();
|
|
const product = productResp;
|
|
createSale({
|
|
saleName,
|
|
channelName: defaultChannel.name,
|
|
discountValue,
|
|
discountOption: discountOptions.PERCENTAGE
|
|
});
|
|
assignProducts(product.name);
|
|
getProductPrice(product.id, defaultChannel.slug);
|
|
})
|
|
.then(price => {
|
|
const expectedPrice = (productPrice * discountValue) / 100;
|
|
expect(expectedPrice).to.be.eq(price);
|
|
});
|
|
});
|
|
|
|
it("should create fixed price discount", () => {
|
|
const saleName = `${startsWith}${faker.datatype.number()}`;
|
|
const discountValue = 50;
|
|
const productPrice = 100;
|
|
|
|
productsUtils
|
|
.createProductInChannel({
|
|
name: saleName,
|
|
channelId: defaultChannel.id,
|
|
warehouseId: warehouse.id,
|
|
productTypeId: productType.id,
|
|
attributeId: attribute.id,
|
|
categoryId: category.id,
|
|
price: productPrice
|
|
})
|
|
.then(({ product: productResp }) => {
|
|
/* Uncomment after fixing SALEOR-3367 bug
|
|
cy.clearSessionData()
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
|
*/
|
|
|
|
cy.visit(urlList.sales);
|
|
cy.softExpectSkeletonIsVisible();
|
|
const product = productResp;
|
|
createSale({
|
|
saleName,
|
|
channelName: defaultChannel.name,
|
|
discountValue,
|
|
discountOption: discountOptions.FIXED
|
|
});
|
|
assignProducts(product.name);
|
|
getProductPrice(product.id, defaultChannel.slug);
|
|
})
|
|
.then(price => {
|
|
const expectedPrice = productPrice - discountValue;
|
|
expect(expectedPrice).to.be.eq(price);
|
|
});
|
|
});
|
|
|
|
it("should not displayed discount not assign to channel", () => {
|
|
const saleName = `${startsWith}${faker.datatype.number()}`;
|
|
let channel;
|
|
let product;
|
|
const discountValue = 50;
|
|
const productPrice = 100;
|
|
|
|
createChannel({ name: saleName }).then(
|
|
channelResp => (channel = channelResp)
|
|
);
|
|
productsUtils
|
|
.createProductInChannel({
|
|
name: saleName,
|
|
channelId: defaultChannel.id,
|
|
warehouseId: warehouse.id,
|
|
productTypeId: productType.id,
|
|
attributeId: attribute.id,
|
|
categoryId: category.id,
|
|
price: productPrice
|
|
})
|
|
.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.softExpectSkeletonIsVisible();
|
|
createSale({
|
|
saleName,
|
|
channelName: channel.name,
|
|
discountValue
|
|
});
|
|
assignProducts(product.name);
|
|
getProductPrice(product.id, defaultChannel.slug);
|
|
})
|
|
.then(price => expect(price).to.equal(productPrice));
|
|
});
|
|
});
|
|
});
|