2021-09-27 10:04:21 +00:00
|
|
|
import { VOUCHERS_SELECTORS } from "../../../elements/discounts/vouchers";
|
|
|
|
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
2022-02-11 14:39:10 +00:00
|
|
|
import { urlList } from "../../../fixtures/urlList";
|
|
|
|
import { ONE_PERMISSION_USERS } from "../../../fixtures/users";
|
|
|
|
import { createCheckoutWithVoucher } from "../../api/utils/ordersUtils";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { selectChannelInDetailsPages } from "../channelsPage";
|
2021-03-23 10:15:39 +00:00
|
|
|
|
|
|
|
export const discountOptions = {
|
|
|
|
PERCENTAGE: VOUCHERS_SELECTORS.percentageDiscountRadioButton,
|
|
|
|
FIXED: VOUCHERS_SELECTORS.fixedDiscountRadioButton,
|
|
|
|
SHIPPING: VOUCHERS_SELECTORS.shippingDiscountRadioButton
|
|
|
|
};
|
|
|
|
|
|
|
|
export function createVoucher({
|
|
|
|
voucherCode,
|
|
|
|
voucherValue,
|
|
|
|
discountOption,
|
2022-02-11 14:39:10 +00:00
|
|
|
channelName,
|
|
|
|
usageLimit,
|
|
|
|
applyOnePerCustomer,
|
|
|
|
onlyStaff,
|
|
|
|
minOrderValue,
|
|
|
|
minAmountOfItems
|
2021-03-23 10:15:39 +00:00
|
|
|
}) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.createVoucherButton).click();
|
|
|
|
selectChannelInDetailsPages(channelName);
|
|
|
|
cy.get(VOUCHERS_SELECTORS.voucherCodeInput)
|
|
|
|
.type(voucherCode)
|
|
|
|
.get(discountOption)
|
|
|
|
.click();
|
|
|
|
if (discountOption !== discountOptions.SHIPPING) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.discountValueInputs).type(voucherValue);
|
|
|
|
}
|
2022-02-11 14:39:10 +00:00
|
|
|
if (usageLimit) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.limits.usageLimitCheckbox)
|
|
|
|
.click()
|
|
|
|
.type(usageLimit);
|
|
|
|
}
|
|
|
|
if (applyOnePerCustomer) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.limits.applyOncePerCustomerCheckbox).click();
|
|
|
|
}
|
|
|
|
if (onlyStaff) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.limits.onlyForStaffCheckbox).click();
|
|
|
|
}
|
|
|
|
if (minOrderValue) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.requirements.minOrderValueCheckbox)
|
|
|
|
.click()
|
|
|
|
.get(VOUCHERS_SELECTORS.requirements.minOrderValueInput)
|
|
|
|
.type(minOrderValue);
|
|
|
|
}
|
|
|
|
if (minAmountOfItems) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.requirements.minAmountOfItemsCheckbox)
|
|
|
|
.click()
|
|
|
|
.get(VOUCHERS_SELECTORS.requirements.minCheckoutItemsQuantityInput)
|
|
|
|
.type(minAmountOfItems);
|
|
|
|
}
|
2021-09-27 10:04:21 +00:00
|
|
|
cy.get(BUTTON_SELECTORS.confirm)
|
|
|
|
.click()
|
|
|
|
.confirmationMessageShouldDisappear();
|
2021-03-23 10:15:39 +00:00
|
|
|
}
|
2022-02-11 14:39:10 +00:00
|
|
|
|
|
|
|
export function loginAndCreateCheckoutForVoucherWithDiscount({
|
|
|
|
discount,
|
|
|
|
voucherValue,
|
|
|
|
voucherCode,
|
|
|
|
channelName,
|
|
|
|
dataForCheckout,
|
|
|
|
usageLimit,
|
|
|
|
applyOnePerCustomer,
|
|
|
|
onlyStaff,
|
|
|
|
minOrderValue,
|
|
|
|
minAmountOfItems
|
|
|
|
}) {
|
|
|
|
cy.clearSessionData()
|
|
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
|
|
|
.visit(urlList.vouchers);
|
|
|
|
cy.softExpectSkeletonIsVisible();
|
|
|
|
createVoucher({
|
|
|
|
voucherCode,
|
|
|
|
voucherValue,
|
|
|
|
discountOption: discount,
|
|
|
|
channelName,
|
|
|
|
usageLimit,
|
|
|
|
applyOnePerCustomer,
|
|
|
|
onlyStaff,
|
|
|
|
minOrderValue,
|
|
|
|
minAmountOfItems
|
|
|
|
});
|
|
|
|
dataForCheckout.voucherCode = voucherCode;
|
|
|
|
return createCheckoutWithVoucher(dataForCheckout);
|
|
|
|
}
|