2021-09-27 10:04:21 +00:00
|
|
|
import { VOUCHERS_SELECTORS } from "../../../elements/discounts/vouchers";
|
|
|
|
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
2023-08-03 08:51:19 +00:00
|
|
|
import { urlList, voucherDetailsUrl } from "../../../fixtures/urlList";
|
2022-02-11 14:39:10 +00:00
|
|
|
import { ONE_PERMISSION_USERS } from "../../../fixtures/users";
|
2023-08-03 08:51:19 +00:00
|
|
|
import { ensureCanvasStatic } from "../../../support/customCommands/sharedElementsOperations/canvas";
|
2022-02-11 14:39:10 +00:00
|
|
|
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,
|
2022-06-27 16:49:35 +00:00
|
|
|
SHIPPING: VOUCHERS_SELECTORS.shippingDiscountRadioButton,
|
2021-03-23 10:15:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function createVoucher({
|
|
|
|
voucherCode,
|
|
|
|
voucherValue,
|
|
|
|
discountOption,
|
2022-02-11 14:39:10 +00:00
|
|
|
channelName,
|
|
|
|
usageLimit,
|
|
|
|
applyOnePerCustomer,
|
|
|
|
onlyStaff,
|
|
|
|
minOrderValue,
|
2022-06-27 16:49:35 +00:00
|
|
|
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) {
|
2023-06-30 12:02:37 +00:00
|
|
|
cy.get(VOUCHERS_SELECTORS.discountValueInputs).type(voucherValue, {
|
|
|
|
force: true,
|
|
|
|
});
|
2021-03-23 10:15:39 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
2023-06-30 12:02:37 +00:00
|
|
|
cy.get(BUTTON_SELECTORS.confirm).click().confirmationMessageShouldAppear();
|
2021-03-23 10:15:39 +00:00
|
|
|
}
|
2022-02-11 14:39:10 +00:00
|
|
|
|
2022-02-11 14:58:40 +00:00
|
|
|
export function setVoucherDate({
|
|
|
|
voucherId,
|
|
|
|
startDate,
|
|
|
|
endDate,
|
|
|
|
endTime,
|
2022-06-27 16:49:35 +00:00
|
|
|
hasEndDate = false,
|
2022-02-11 14:58:40 +00:00
|
|
|
}) {
|
|
|
|
cy.visit(voucherDetailsUrl(voucherId)).waitForProgressBarToNotBeVisible();
|
|
|
|
if (startDate) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.startDateInput).type(startDate);
|
|
|
|
}
|
|
|
|
if (endDate) {
|
|
|
|
if (hasEndDate) {
|
|
|
|
cy.get(VOUCHERS_SELECTORS.hasEndDateCheckbox).click();
|
|
|
|
}
|
|
|
|
cy.get(VOUCHERS_SELECTORS.endDateInput)
|
|
|
|
.type(endDate)
|
|
|
|
.get(VOUCHERS_SELECTORS.endTimeInput)
|
|
|
|
.type(endTime);
|
|
|
|
}
|
|
|
|
cy.addAliasToGraphRequest("VoucherUpdate")
|
|
|
|
.get(BUTTON_SELECTORS.confirm)
|
|
|
|
.click()
|
|
|
|
.wait("@VoucherUpdate");
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:39:10 +00:00
|
|
|
export function loginAndCreateCheckoutForVoucherWithDiscount({
|
|
|
|
discount,
|
|
|
|
voucherValue,
|
|
|
|
voucherCode,
|
|
|
|
channelName,
|
|
|
|
dataForCheckout,
|
|
|
|
usageLimit,
|
|
|
|
applyOnePerCustomer,
|
|
|
|
onlyStaff,
|
|
|
|
minOrderValue,
|
2022-06-27 16:49:35 +00:00
|
|
|
minAmountOfItems,
|
2022-02-11 14:39:10 +00:00
|
|
|
}) {
|
|
|
|
cy.clearSessionData()
|
|
|
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
|
|
|
.visit(urlList.vouchers);
|
2023-08-03 08:51:19 +00:00
|
|
|
ensureCanvasStatic();
|
2022-02-11 14:39:10 +00:00
|
|
|
createVoucher({
|
|
|
|
voucherCode,
|
|
|
|
voucherValue,
|
|
|
|
discountOption: discount,
|
|
|
|
channelName,
|
|
|
|
usageLimit,
|
|
|
|
applyOnePerCustomer,
|
|
|
|
onlyStaff,
|
|
|
|
minOrderValue,
|
2022-06-27 16:49:35 +00:00
|
|
|
minAmountOfItems,
|
2022-02-11 14:39:10 +00:00
|
|
|
});
|
|
|
|
dataForCheckout.voucherCode = voucherCode;
|
|
|
|
return createCheckoutWithVoucher(dataForCheckout);
|
|
|
|
}
|