2022-02-11 14:58:40 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../../support"/>
|
|
|
|
|
|
|
|
import faker from "faker";
|
|
|
|
|
|
|
|
import { VOUCHERS_SELECTORS } from "../../../elements/discounts/vouchers";
|
|
|
|
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
|
|
|
import { voucherDetailsUrl } from "../../../fixtures/urlList";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
createVoucherInChannel,
|
|
|
|
} from "../../../support/api/utils/discounts/vouchersUtils";
|
|
|
|
import {
|
|
|
|
createCheckoutWithVoucher,
|
|
|
|
} from "../../../support/api/utils/ordersUtils";
|
|
|
|
import * as productsUtils
|
|
|
|
from "../../../support/api/utils/products/productsUtils";
|
|
|
|
import {
|
|
|
|
updateTaxConfigurationForChannel,
|
|
|
|
} from "../../../support/api/utils/taxesUtils";
|
|
|
|
import {
|
|
|
|
formatDate,
|
|
|
|
formatTime,
|
|
|
|
} from "../../../support/formatData/formatDate";
|
2022-02-11 14:58:40 +00:00
|
|
|
import { setVoucherDate } from "../../../support/pages/discounts/vouchersPage";
|
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("As an admin I want to update vouchers", () => {
|
2022-08-16 10:49:22 +00:00
|
|
|
const startsWith = "UpdateVou-";
|
2022-06-27 09:30:51 +00:00
|
|
|
const productPrice = 100;
|
|
|
|
const shippingPrice = 100;
|
2022-08-18 13:14:29 +00:00
|
|
|
const voucherValue = 50;
|
2022-02-11 14:58:40 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
let defaultChannel;
|
|
|
|
let product;
|
|
|
|
let dataForCheckout;
|
2022-02-11 14:58:40 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
before(() => {
|
2022-08-18 13:14:29 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2022-06-27 09:30:51 +00:00
|
|
|
productsUtils
|
|
|
|
.createProductWithShipping({ name, productPrice, shippingPrice })
|
|
|
|
.then(
|
|
|
|
({
|
|
|
|
variantsList: variantsResp,
|
|
|
|
defaultChannel: channel,
|
|
|
|
shippingMethod: shippingMethodResp,
|
|
|
|
address: addressResp,
|
2022-06-27 16:49:35 +00:00
|
|
|
product: productResp,
|
2022-06-27 09:30:51 +00:00
|
|
|
}) => {
|
|
|
|
defaultChannel = channel;
|
|
|
|
product = productResp;
|
|
|
|
|
|
|
|
dataForCheckout = {
|
|
|
|
channelSlug: defaultChannel.slug,
|
2022-02-11 14:58:40 +00:00
|
|
|
variantsList: variantsResp,
|
|
|
|
address: addressResp,
|
2022-06-27 09:30:51 +00:00
|
|
|
shippingMethodName: shippingMethodResp.name,
|
2022-06-27 16:49:35 +00:00
|
|
|
auth: "token",
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
2023-02-02 08:59:55 +00:00
|
|
|
cy.checkIfDataAreNotNull({
|
|
|
|
dataForCheckout,
|
|
|
|
defaultChannel,
|
|
|
|
product,
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
|
|
|
});
|
2022-02-11 14:58:40 +00:00
|
|
|
|
2023-01-25 10:32:28 +00:00
|
|
|
beforeEach(() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2023-01-25 10:32:28 +00:00
|
|
|
updateTaxConfigurationForChannel({
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
pricesEnteredWithTax: true,
|
|
|
|
});
|
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should delete voucher. TC: SALEOR_1905",
|
2022-08-18 13:14:29 +00:00
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-02-11 14:58:40 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
createVoucherInChannel({
|
|
|
|
name,
|
|
|
|
productId: product.id,
|
|
|
|
channelId: defaultChannel.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
value: voucherValue,
|
2022-08-18 13:14:29 +00:00
|
|
|
}).then(voucherResp => {
|
|
|
|
expect(voucherResp.voucher.id).to.be.ok;
|
|
|
|
|
|
|
|
cy.visit(voucherDetailsUrl(voucherResp.voucher.id))
|
|
|
|
.addAliasToGraphRequest("VoucherDelete")
|
|
|
|
.get(BUTTON_SELECTORS.deleteButton)
|
|
|
|
.click()
|
|
|
|
.get(BUTTON_SELECTORS.submit)
|
|
|
|
.click()
|
|
|
|
.wait("@VoucherDelete");
|
|
|
|
|
|
|
|
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
|
|
|
window.sessionStorage.setItem("token", "");
|
|
|
|
dataForCheckout.auth = "token";
|
|
|
|
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors.0")
|
|
|
|
.should("include", { field: "promoCode" })
|
|
|
|
.and("include", { message: "Promo code is invalid" });
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 14:58:40 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should update voucher. TC: SALEOR_1906",
|
2022-08-18 13:14:29 +00:00
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-02-11 14:58:40 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const voucherUpdatedValue = 20;
|
|
|
|
const expectedOrderAmount =
|
|
|
|
productPrice +
|
|
|
|
shippingPrice -
|
|
|
|
(productPrice * voucherUpdatedValue) / 100;
|
|
|
|
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
createVoucherInChannel({
|
|
|
|
name,
|
|
|
|
productId: product.id,
|
|
|
|
channelId: defaultChannel.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
value: voucherValue,
|
2022-08-18 13:14:29 +00:00
|
|
|
}).then(voucherResp => {
|
|
|
|
expect(voucherResp.voucher.id).to.be.ok;
|
|
|
|
|
|
|
|
cy.visit(voucherDetailsUrl(voucherResp.voucher.id))
|
|
|
|
.addAliasToGraphRequest("VoucherUpdate")
|
|
|
|
.get(VOUCHERS_SELECTORS.percentageDiscountRadioButton)
|
|
|
|
.click()
|
|
|
|
.get(VOUCHERS_SELECTORS.discountValueInputs)
|
|
|
|
.clearAndType(voucherUpdatedValue)
|
|
|
|
.get(BUTTON_SELECTORS.confirm)
|
|
|
|
.click()
|
|
|
|
.wait("@VoucherUpdate");
|
|
|
|
|
|
|
|
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
|
|
|
window.sessionStorage.setItem("token", "");
|
|
|
|
dataForCheckout.auth = "token";
|
|
|
|
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.checkout.totalPrice.gross.amount")
|
|
|
|
.should("eq", expectedOrderAmount);
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 14:58:40 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should set date on voucher. TC: SALEOR_1912",
|
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2022-02-11 14:58:40 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
2022-08-18 13:14:29 +00:00
|
|
|
const todayDate = formatDate(new Date());
|
|
|
|
const tomorrowDate = formatDate(
|
|
|
|
new Date().setDate(new Date().getDate() + 1),
|
|
|
|
);
|
2022-02-11 14:58:40 +00:00
|
|
|
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
createVoucherInChannel({
|
|
|
|
name,
|
|
|
|
productId: product.id,
|
|
|
|
channelId: defaultChannel.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
value: voucherValue,
|
2022-08-18 13:14:29 +00:00
|
|
|
}).then(voucherResp => {
|
|
|
|
expect(voucherResp.voucher.id).to.be.ok;
|
|
|
|
|
|
|
|
setVoucherDate({
|
|
|
|
voucherId: voucherResp.voucher.id,
|
|
|
|
startDate: tomorrowDate,
|
2022-02-11 14:58:40 +00:00
|
|
|
});
|
2022-08-18 13:14:29 +00:00
|
|
|
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
|
|
|
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors.0")
|
|
|
|
.should("include", { field: "promoCode" })
|
|
|
|
.and("include", { message: "Promo code is invalid" });
|
|
|
|
setVoucherDate({
|
|
|
|
voucherId: voucherResp.voucher.id,
|
|
|
|
startDate: todayDate,
|
|
|
|
});
|
|
|
|
window.sessionStorage.setItem("token", "");
|
|
|
|
dataForCheckout.auth = "token";
|
|
|
|
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors")
|
|
|
|
.should("be.be.empty");
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 14:58:40 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should set end date on voucher. TC: SALEOR_1913",
|
2022-08-18 13:14:29 +00:00
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-02-11 14:58:40 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
2022-08-18 13:14:29 +00:00
|
|
|
const todayDate = formatDate(new Date());
|
|
|
|
const tomorrowDate = formatDate(
|
|
|
|
new Date().setDate(new Date().getDate() + 1),
|
|
|
|
);
|
2022-02-11 14:58:40 +00:00
|
|
|
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
createVoucherInChannel({
|
|
|
|
name,
|
|
|
|
productId: product.id,
|
|
|
|
channelId: defaultChannel.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
value: voucherValue,
|
2022-08-18 13:14:29 +00:00
|
|
|
}).then(voucherResp => {
|
|
|
|
expect(voucherResp.voucher.id).to.be.ok;
|
|
|
|
|
|
|
|
setVoucherDate({
|
|
|
|
voucherId: voucherResp.voucher.id,
|
|
|
|
endDate: todayDate,
|
|
|
|
endTime: formatTime(new Date()),
|
|
|
|
hasEndDate: true,
|
2022-02-11 14:58:40 +00:00
|
|
|
});
|
2022-08-18 13:14:29 +00:00
|
|
|
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
|
|
|
window.sessionStorage.setItem("token", "");
|
|
|
|
dataForCheckout.auth = "token";
|
|
|
|
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors.0")
|
|
|
|
.should("include", { field: "promoCode" })
|
|
|
|
.and("include", { message: "Promo code is invalid" });
|
|
|
|
setVoucherDate({
|
|
|
|
voucherId: voucherResp.voucher.id,
|
|
|
|
endDate: tomorrowDate,
|
|
|
|
endTime: formatTime(new Date()),
|
|
|
|
});
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors")
|
|
|
|
.should("be.be.empty");
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 14:58:40 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should set country on voucher. TC: SALEOR_1914",
|
2022-08-18 13:14:29 +00:00
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-02-11 14:58:40 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
createVoucherInChannel({
|
|
|
|
name,
|
|
|
|
productId: product.id,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
value: voucherValue,
|
|
|
|
type: "SHIPPING",
|
2022-06-27 16:49:35 +00:00
|
|
|
country: "US",
|
2022-08-18 13:14:29 +00:00
|
|
|
}).then(voucherResp => {
|
|
|
|
expect(voucherResp.voucher.id).to.be.ok;
|
|
|
|
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
|
|
|
window.sessionStorage.setItem("token", "");
|
|
|
|
dataForCheckout.auth = "token";
|
|
|
|
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors")
|
|
|
|
.should("be.be.empty");
|
|
|
|
cy.visit(voucherDetailsUrl(voucherResp.voucher.id))
|
|
|
|
.get(VOUCHERS_SELECTORS.shippingDiscountRadioButton)
|
|
|
|
.click()
|
|
|
|
.get(VOUCHERS_SELECTORS.countriesDropdownIcon)
|
|
|
|
.click()
|
|
|
|
.get(BUTTON_SELECTORS.deleteIcon)
|
|
|
|
.click()
|
|
|
|
.get(BUTTON_SELECTORS.deleteIcon)
|
|
|
|
.should("not.exist")
|
|
|
|
.get(VOUCHERS_SELECTORS.assignCountryButton)
|
|
|
|
.click()
|
2022-10-20 10:03:53 +00:00
|
|
|
.assignElements("Poland")
|
2022-08-18 13:14:29 +00:00
|
|
|
.addAliasToGraphRequest("VoucherUpdate")
|
|
|
|
.get(BUTTON_SELECTORS.confirm)
|
|
|
|
.click()
|
|
|
|
.wait("@VoucherUpdate");
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors.0")
|
|
|
|
.should("include", { field: "promoCode" })
|
|
|
|
.and("include", {
|
|
|
|
message: "Voucher is not applicable to this checkout.",
|
|
|
|
});
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2022-02-11 14:58:40 +00:00
|
|
|
});
|