2022-06-06 10:27:18 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../../support"/>
|
|
|
|
|
|
|
|
import faker from "faker";
|
|
|
|
|
|
|
|
import { completeCheckout } from "../../../support/api/requests/Checkout";
|
|
|
|
import {
|
|
|
|
addPayment,
|
2022-06-27 16:49:35 +00:00
|
|
|
createCheckoutWithVoucher,
|
2022-06-06 10:27:18 +00:00
|
|
|
} from "../../../support/api/utils/ordersUtils";
|
2023-07-28 07:48:41 +00:00
|
|
|
import * as productsUtils
|
|
|
|
from "../../../support/api/utils/products/productsUtils";
|
2022-06-06 10:27:18 +00:00
|
|
|
import {
|
|
|
|
discountOptions,
|
2022-06-27 16:49:35 +00:00
|
|
|
loginAndCreateCheckoutForVoucherWithDiscount,
|
2022-06-06 10:27:18 +00:00
|
|
|
} from "../../../support/pages/discounts/vouchersPage";
|
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("As an admin I want to create voucher", () => {
|
2022-08-16 10:49:22 +00:00
|
|
|
const startsWith = "CyVouLimit-";
|
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-06-27 09:30:51 +00:00
|
|
|
|
|
|
|
let defaultChannel;
|
|
|
|
let dataForCheckout;
|
|
|
|
|
|
|
|
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,
|
2022-06-27 16:49:35 +00:00
|
|
|
address: addressResp,
|
2022-06-27 09:30:51 +00:00
|
|
|
}) => {
|
|
|
|
defaultChannel = channel;
|
2022-08-18 13:14:29 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
dataForCheckout = {
|
|
|
|
channelSlug: defaultChannel.slug,
|
2022-08-18 13:14:29 +00:00
|
|
|
variantsList: variantsResp,
|
|
|
|
address: addressResp,
|
|
|
|
shippingMethodName: shippingMethodResp.name,
|
2022-06-27 16:49:35 +00:00
|
|
|
auth: "token",
|
2022-06-27 09:30:51 +00:00
|
|
|
};
|
2023-01-16 13:55:38 +00:00
|
|
|
cy.checkIfDataAreNotNull({ dataForCheckout, defaultChannel });
|
2022-07-11 09:14:23 +00:00
|
|
|
cy.clearSessionData();
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
|
|
|
});
|
2022-06-06 10:27:18 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to create voucher with limited number of times discount can be used in total. TC: SALEOR_1907",
|
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2022-06-06 10:27:18 +00:00
|
|
|
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const usageLimit = 1;
|
2022-07-11 09:14:23 +00:00
|
|
|
dataForCheckout.auth = "auth";
|
2022-06-06 10:27:18 +00:00
|
|
|
let firstCheckout;
|
|
|
|
|
|
|
|
loginAndCreateCheckoutForVoucherWithDiscount({
|
|
|
|
discount: discountOptions.PERCENTAGE,
|
|
|
|
voucherValue,
|
|
|
|
voucherCode,
|
|
|
|
channelName: defaultChannel.name,
|
|
|
|
dataForCheckout,
|
2022-06-27 16:49:35 +00:00
|
|
|
usageLimit,
|
2022-08-18 13:14:29 +00:00
|
|
|
}).then(({ checkout, addPromoCodeResp }) => {
|
|
|
|
expect(addPromoCodeResp.errors).to.be.empty;
|
|
|
|
firstCheckout = checkout;
|
|
|
|
dataForCheckout.voucherCode = voucherCode;
|
|
|
|
|
|
|
|
addPayment(firstCheckout.id);
|
|
|
|
completeCheckout(firstCheckout.id);
|
|
|
|
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-06-06 10:27:18 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to create voucher with limit to one use per customer. TC: SALEOR_1908",
|
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2022-06-06 10:27:18 +00:00
|
|
|
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
2022-07-11 09:14:23 +00:00
|
|
|
dataForCheckout.auth = "auth";
|
2022-06-06 10:27:18 +00:00
|
|
|
let firstCheckout;
|
|
|
|
|
|
|
|
loginAndCreateCheckoutForVoucherWithDiscount({
|
|
|
|
discount: discountOptions.PERCENTAGE,
|
|
|
|
voucherValue,
|
|
|
|
voucherCode,
|
|
|
|
channelName: defaultChannel.name,
|
|
|
|
dataForCheckout,
|
2022-06-27 16:49:35 +00:00
|
|
|
applyOnePerCustomer: true,
|
2022-08-18 13:14:29 +00:00
|
|
|
}).then(({ checkout, addPromoCodeResp }) => {
|
|
|
|
expect(addPromoCodeResp.errors).to.be.empty;
|
|
|
|
firstCheckout = checkout;
|
|
|
|
dataForCheckout.voucherCode = voucherCode;
|
|
|
|
|
|
|
|
addPayment(firstCheckout.id);
|
|
|
|
completeCheckout(firstCheckout.id);
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors.0")
|
|
|
|
.should("include", { field: "promoCode" })
|
|
|
|
.and("include", {
|
|
|
|
message: "Voucher is not applicable to this checkout.",
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create new checkout as other not logged in customer - voucher should be available for other customer
|
|
|
|
|
|
|
|
window.sessionStorage.setItem("token", "");
|
|
|
|
dataForCheckout.auth = "token";
|
|
|
|
dataForCheckout.email = "newUser@example.com";
|
|
|
|
|
|
|
|
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-06-06 10:27:18 +00:00
|
|
|
|
2022-08-18 13:14:29 +00:00
|
|
|
it(
|
2022-06-27 09:30:51 +00:00
|
|
|
"should be able to create voucher with limit to staff only. TC: SALEOR_1909",
|
2022-08-18 13:14:29 +00:00
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-06-06 10:27:18 +00:00
|
|
|
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
dataForCheckout.auth = "auth";
|
|
|
|
let firstCheckout;
|
|
|
|
|
|
|
|
loginAndCreateCheckoutForVoucherWithDiscount({
|
|
|
|
discount: discountOptions.PERCENTAGE,
|
|
|
|
voucherValue,
|
|
|
|
voucherCode,
|
|
|
|
channelName: defaultChannel.name,
|
|
|
|
dataForCheckout,
|
2022-06-27 16:49:35 +00:00
|
|
|
onlyStaff: true,
|
2022-08-18 13:14:29 +00:00
|
|
|
}).then(({ checkout, addPromoCodeResp }) => {
|
|
|
|
expect(addPromoCodeResp.errors).to.be.empty;
|
|
|
|
firstCheckout = checkout;
|
|
|
|
dataForCheckout.voucherCode = voucherCode;
|
|
|
|
|
|
|
|
addPayment(firstCheckout.id);
|
|
|
|
completeCheckout(firstCheckout.id);
|
|
|
|
|
|
|
|
// Create new checkout as other not logged in customer - voucher should be not available for other customer
|
|
|
|
|
|
|
|
window.sessionStorage.setItem("token", "");
|
|
|
|
dataForCheckout.auth = "token";
|
|
|
|
dataForCheckout.email = "newUser@example.com";
|
|
|
|
|
|
|
|
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-06-06 10:27:18 +00:00
|
|
|
|
2022-08-18 13:14:29 +00:00
|
|
|
it(
|
2022-06-27 09:30:51 +00:00
|
|
|
"should be able to create voucher with minimum value of order. TC: SALEOR_1910",
|
2022-08-18 13:14:29 +00:00
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
2022-06-27 09:30:51 +00:00
|
|
|
() => {
|
2022-06-06 10:27:18 +00:00
|
|
|
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
const minOrderValue = productPrice * 1.5;
|
|
|
|
dataForCheckout.productQuantity = 1;
|
|
|
|
|
|
|
|
loginAndCreateCheckoutForVoucherWithDiscount({
|
|
|
|
discount: discountOptions.PERCENTAGE,
|
|
|
|
voucherValue,
|
|
|
|
voucherCode,
|
|
|
|
channelName: defaultChannel.name,
|
|
|
|
dataForCheckout,
|
2022-06-27 16:49:35 +00:00
|
|
|
minOrderValue,
|
2022-06-06 10:27:18 +00:00
|
|
|
})
|
2022-08-18 13:14:29 +00:00
|
|
|
.its("addPromoCodeResp.errors.0")
|
|
|
|
.should("include", { field: "promoCode" })
|
|
|
|
.and("include", {
|
|
|
|
message: "Voucher is not applicable to this checkout.",
|
2022-06-06 10:27:18 +00:00
|
|
|
});
|
2022-08-18 13:14:29 +00:00
|
|
|
dataForCheckout.voucherCode = voucherCode;
|
|
|
|
dataForCheckout.productQuantity = 2;
|
|
|
|
|
|
|
|
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-08-18 13:14:29 +00:00
|
|
|
it(
|
|
|
|
"should create voucher with min product quantity. TC: SALEOR_1911",
|
|
|
|
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
|
|
|
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
dataForCheckout.productQuantity = 1;
|
2022-06-27 09:30:51 +00:00
|
|
|
|
2022-08-18 13:14:29 +00:00
|
|
|
loginAndCreateCheckoutForVoucherWithDiscount({
|
|
|
|
discount: discountOptions.PERCENTAGE,
|
|
|
|
voucherValue,
|
|
|
|
voucherCode,
|
|
|
|
channelName: defaultChannel.name,
|
|
|
|
dataForCheckout,
|
|
|
|
minAmountOfItems: 2,
|
2022-06-06 10:27:18 +00:00
|
|
|
})
|
2022-08-18 13:14:29 +00:00
|
|
|
.its("addPromoCodeResp.errors.0")
|
|
|
|
.should("include", { field: "promoCode" })
|
|
|
|
.and("include", {
|
|
|
|
message: "Voucher is not applicable to this checkout.",
|
|
|
|
});
|
|
|
|
dataForCheckout.voucherCode = voucherCode;
|
|
|
|
dataForCheckout.productQuantity = 2;
|
|
|
|
|
|
|
|
createCheckoutWithVoucher(dataForCheckout)
|
|
|
|
.its("addPromoCodeResp.errors")
|
|
|
|
.should("be.be.empty");
|
|
|
|
},
|
|
|
|
);
|
2022-06-06 10:27:18 +00:00
|
|
|
});
|