
* 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
184 lines
5.5 KiB
JavaScript
184 lines
5.5 KiB
JavaScript
/// <reference types="cypress"/>
|
|
/// <reference types="../../support"/>
|
|
|
|
import faker from "faker";
|
|
|
|
import { urlList } from "../../fixtures/urlList";
|
|
import { ONE_PERMISSION_USERS } from "../../fixtures/users";
|
|
import { createChannel } from "../../support/api/requests/Channels";
|
|
import * as channelsUtils from "../../support/api/utils/channelsUtils";
|
|
import { deleteVouchersStartsWith } from "../../support/api/utils/discounts/vouchersUtils";
|
|
import { createCheckoutWithVoucher } from "../../support/api/utils/ordersUtils";
|
|
import * as productsUtils from "../../support/api/utils/products/productsUtils";
|
|
import {
|
|
createShipping,
|
|
deleteShippingStartsWith
|
|
} from "../../support/api/utils/shippingUtils";
|
|
import filterTests from "../../support/filterTests";
|
|
import {
|
|
createVoucher,
|
|
discountOptions
|
|
} from "../../support/pages/discounts/vouchersPage";
|
|
|
|
filterTests({ definedTags: ["all"] }, () => {
|
|
describe("Vouchers discounts", () => {
|
|
const startsWith = "CyVou-";
|
|
const productPrice = 100;
|
|
const shippingPrice = 100;
|
|
|
|
let defaultChannel;
|
|
let createdChannel;
|
|
let productType;
|
|
let attribute;
|
|
let category;
|
|
let shippingMethod;
|
|
let variants;
|
|
let address;
|
|
|
|
before(() => {
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
channelsUtils.deleteChannelsStartsWith(startsWith);
|
|
productsUtils.deleteProductsStartsWith(startsWith);
|
|
deleteShippingStartsWith(startsWith);
|
|
deleteVouchersStartsWith(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 => {
|
|
address = addresses.plAddress;
|
|
createShipping({
|
|
channelId: defaultChannel.id,
|
|
name,
|
|
address,
|
|
price: shippingPrice
|
|
});
|
|
})
|
|
.then(
|
|
({ shippingMethod: shippingMethodResp, warehouse: warehouse }) => {
|
|
shippingMethod = shippingMethodResp;
|
|
productsUtils.createProductInChannel({
|
|
name,
|
|
channelId: defaultChannel.id,
|
|
warehouseId: warehouse.id,
|
|
productTypeId: productType.id,
|
|
attributeId: attribute.id,
|
|
categoryId: category.id,
|
|
price: productPrice
|
|
});
|
|
}
|
|
)
|
|
.then(({ variantsList: variantsResp }) => {
|
|
variants = variantsResp;
|
|
createChannel({ name });
|
|
})
|
|
.then(channel => {
|
|
createdChannel = channel;
|
|
});
|
|
});
|
|
|
|
it("should create percentage voucher", () => {
|
|
const voucherValue = 50;
|
|
|
|
loginAndCreateCheckoutForVoucherWithDiscount(
|
|
discountOptions.PERCENTAGE,
|
|
voucherValue
|
|
).then(amount => {
|
|
const expectedAmount =
|
|
(productPrice * voucherValue) / 100 + shippingPrice;
|
|
expect(amount).to.be.eq(expectedAmount);
|
|
});
|
|
});
|
|
|
|
it("should create fixed price voucher", () => {
|
|
const voucherValue = 50;
|
|
loginAndCreateCheckoutForVoucherWithDiscount(
|
|
discountOptions.FIXED,
|
|
voucherValue
|
|
).then(amount => {
|
|
const expectedAmount = productPrice + shippingPrice - voucherValue;
|
|
expect(amount).to.be.eq(expectedAmount);
|
|
});
|
|
});
|
|
|
|
it("should create free shipping voucher", () => {
|
|
loginAndCreateCheckoutForVoucherWithDiscount(
|
|
discountOptions.SHIPPING,
|
|
null
|
|
).then(amount => {
|
|
const expectedAmount = productPrice;
|
|
expect(amount).to.be.eq(expectedAmount);
|
|
});
|
|
});
|
|
|
|
it("should create voucher not available for selected channel", () => {
|
|
const randomName = `${startsWith}${faker.datatype.number()}`;
|
|
const voucherValue = 50;
|
|
|
|
cy.clearSessionData()
|
|
.loginUserViaRequest()
|
|
.visit(urlList.vouchers);
|
|
cy.softExpectSkeletonIsVisible();
|
|
createVoucher({
|
|
voucherCode: randomName,
|
|
voucherValue,
|
|
discountOption: discountOptions.PERCENTAGE,
|
|
channelName: createdChannel.name
|
|
});
|
|
createCheckoutForCreatedVoucher(randomName).then(resp => {
|
|
const errorField = resp.checkoutErrors[0].field;
|
|
expect(errorField).to.be.eq("promoCode");
|
|
});
|
|
});
|
|
|
|
function createCheckoutForCreatedVoucher(voucherCode) {
|
|
return createCheckoutWithVoucher({
|
|
channelSlug: defaultChannel.slug,
|
|
variantsList: variants,
|
|
address,
|
|
shippingMethodId: shippingMethod.id,
|
|
voucherCode,
|
|
auth: "token"
|
|
});
|
|
}
|
|
|
|
function loginAndCreateCheckoutForVoucherWithDiscount(
|
|
discount,
|
|
voucherValue
|
|
) {
|
|
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
cy.clearSessionData()
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
|
.visit(urlList.vouchers);
|
|
cy.softExpectSkeletonIsVisible();
|
|
createVoucher({
|
|
voucherCode,
|
|
voucherValue,
|
|
discountOption: discount,
|
|
channelName: defaultChannel.name
|
|
});
|
|
return createCheckoutForCreatedVoucher(voucherCode).its(
|
|
"checkout.totalPrice.gross.amount"
|
|
);
|
|
}
|
|
});
|
|
});
|