Saleor 7913 fix tests for vouchers (#2242)
* refactor createVoucher tests * fix for tests in updateVoucher folder * fix for updateVouchers, createVouchersWithLimits and siteSettings * remove already declared variable
This commit is contained in:
parent
8e2a3e0c75
commit
cea3ead44b
6 changed files with 315 additions and 373 deletions
|
@ -1,8 +1,6 @@
|
|||
/// <reference types="cypress"/>
|
||||
/// <reference types="../../support"/>
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
||||
import { urlList } from "../../fixtures/urlList";
|
||||
import {
|
||||
|
@ -10,7 +8,7 @@ import {
|
|||
updateShopAddress,
|
||||
} from "../../support/api/requests/ShopSettings";
|
||||
|
||||
xdescribe("Tests for site settings", () => {
|
||||
describe("Tests for site settings", () => {
|
||||
let address;
|
||||
|
||||
before(() => {
|
||||
|
@ -24,7 +22,7 @@ xdescribe("Tests for site settings", () => {
|
|||
|
||||
it(
|
||||
"should change store address",
|
||||
{ tags: ["@siteSettings", "@allEnv"] },
|
||||
{ tags: ["@siteSettings", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest()
|
||||
|
|
|
@ -13,7 +13,6 @@ import {
|
|||
createCheckoutWithVoucher,
|
||||
} from "../../../support/api/utils/ordersUtils";
|
||||
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
|
||||
import filterTests from "../../../support/filterTests";
|
||||
import {
|
||||
createVoucher,
|
||||
discountOptions,
|
||||
|
@ -24,19 +23,17 @@ describe("As an admin I want to create voucher", () => {
|
|||
const startsWith = "CyVou-";
|
||||
const productPrice = 100;
|
||||
const shippingPrice = 100;
|
||||
const voucherValue = 50;
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
let defaultChannel;
|
||||
let createdChannel;
|
||||
let shippingMethod;
|
||||
let variants;
|
||||
let address;
|
||||
let dataForCheckout;
|
||||
let defaultChannel;
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||
deleteVouchersStartsWith(startsWith);
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createProductWithShipping({ name, productPrice, shippingPrice })
|
||||
.then(
|
||||
|
@ -46,30 +43,23 @@ describe("As an admin I want to create voucher", () => {
|
|||
shippingMethod: shippingMethodResp,
|
||||
address: addressResp,
|
||||
}) => {
|
||||
variants = variantsResp;
|
||||
defaultChannel = channel;
|
||||
shippingMethod = shippingMethodResp;
|
||||
address = addressResp;
|
||||
createChannel({ name });
|
||||
},
|
||||
)
|
||||
.then(channel => {
|
||||
createdChannel = channel;
|
||||
|
||||
dataForCheckout = {
|
||||
channelSlug: defaultChannel.slug,
|
||||
variantsList: variants,
|
||||
address,
|
||||
shippingMethodName: shippingMethod.name,
|
||||
variantsList: variantsResp,
|
||||
address: addressResp,
|
||||
shippingMethodName: shippingMethodResp.name,
|
||||
auth: "token",
|
||||
};
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it(
|
||||
"should be able to create fixed price voucher. TC: SALEOR_1901",
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const voucherValue = 50;
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const expectedAmount = productPrice + shippingPrice - voucherValue;
|
||||
let checkout;
|
||||
|
@ -80,20 +70,17 @@ describe("As an admin I want to create voucher", () => {
|
|||
voucherCode,
|
||||
channelName: defaultChannel.name,
|
||||
dataForCheckout,
|
||||
})
|
||||
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
|
||||
}).then(({ addPromoCodeResp, checkout: checkoutResp }) => {
|
||||
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
|
||||
expectedAmount,
|
||||
);
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
checkout = checkoutResp;
|
||||
|
||||
addPayment(checkout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(checkout.id);
|
||||
})
|
||||
.then(({ order }) => {
|
||||
expect(order.id).to.be.ok;
|
||||
completeCheckout(checkout.id)
|
||||
.its("order.total.gross.amount")
|
||||
.should("eq", expectedAmount);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
@ -102,7 +89,6 @@ describe("As an admin I want to create voucher", () => {
|
|||
"should be able to create percentage voucher. TC: SALEOR_1902",
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const voucherValue = 50;
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const expectedAmount =
|
||||
(productPrice * voucherValue) / 100 + shippingPrice;
|
||||
|
@ -114,20 +100,17 @@ describe("As an admin I want to create voucher", () => {
|
|||
voucherCode,
|
||||
channelName: defaultChannel.name,
|
||||
dataForCheckout,
|
||||
})
|
||||
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
|
||||
}).then(({ addPromoCodeResp, checkout: checkoutResp }) => {
|
||||
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
|
||||
expectedAmount,
|
||||
);
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
checkout = checkoutResp;
|
||||
|
||||
addPayment(checkout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(checkout.id);
|
||||
})
|
||||
.then(({ order }) => {
|
||||
expect(order.id).to.be.ok;
|
||||
completeCheckout(checkout.id)
|
||||
.its("order.total.gross.amount")
|
||||
.should("eq", expectedAmount);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
@ -145,20 +128,17 @@ describe("As an admin I want to create voucher", () => {
|
|||
voucherCode,
|
||||
channelName: defaultChannel.name,
|
||||
dataForCheckout,
|
||||
})
|
||||
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
|
||||
}).then(({ addPromoCodeResp, checkout: checkoutResp }) => {
|
||||
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
|
||||
expectedAmount,
|
||||
);
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
checkout = checkoutResp;
|
||||
|
||||
addPayment(checkout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(checkout.id);
|
||||
})
|
||||
.then(({ order }) => {
|
||||
expect(order.id).to.be.ok;
|
||||
completeCheckout(checkout.id)
|
||||
.its("order.total.gross.amount")
|
||||
.should("eq", productPrice);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
@ -167,26 +147,30 @@ describe("As an admin I want to create voucher", () => {
|
|||
"should be able to create voucher not available for selected channel. TC: SALEOR_1904",
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const randomName = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest()
|
||||
.visit(urlList.vouchers);
|
||||
cy.expectSkeletonIsVisible();
|
||||
createChannel({ name }).then(channel => {
|
||||
createdChannel = channel;
|
||||
|
||||
cy.reload();
|
||||
createVoucher({
|
||||
voucherCode: randomName,
|
||||
voucherCode,
|
||||
voucherValue,
|
||||
discountOption: discountOptions.PERCENTAGE,
|
||||
channelName: createdChannel.name,
|
||||
});
|
||||
dataForCheckout.voucherCode = randomName;
|
||||
createCheckoutWithVoucher(dataForCheckout).then(
|
||||
({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors.0")
|
||||
.should("include", { field: "promoCode" })
|
||||
.and("include", { message: "Promo code is invalid" });
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
|
@ -20,18 +20,17 @@ describe("As an admin I want to create voucher", () => {
|
|||
const startsWith = "CyVouLimit-";
|
||||
const productPrice = 100;
|
||||
const shippingPrice = 100;
|
||||
const voucherValue = 50;
|
||||
|
||||
let defaultChannel;
|
||||
let shippingMethod;
|
||||
let variants;
|
||||
let address;
|
||||
let dataForCheckout;
|
||||
|
||||
before(() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||
deleteVouchersStartsWith(startsWith);
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createProductWithShipping({ name, productPrice, shippingPrice })
|
||||
.then(
|
||||
|
@ -41,15 +40,13 @@ describe("As an admin I want to create voucher", () => {
|
|||
shippingMethod: shippingMethodResp,
|
||||
address: addressResp,
|
||||
}) => {
|
||||
variants = variantsResp;
|
||||
defaultChannel = channel;
|
||||
shippingMethod = shippingMethodResp;
|
||||
address = addressResp;
|
||||
|
||||
dataForCheckout = {
|
||||
channelSlug: defaultChannel.slug,
|
||||
variantsList: variants,
|
||||
address,
|
||||
shippingMethodName: shippingMethod.name,
|
||||
variantsList: variantsResp,
|
||||
address: addressResp,
|
||||
shippingMethodName: shippingMethodResp.name,
|
||||
auth: "token",
|
||||
};
|
||||
cy.clearSessionData();
|
||||
|
@ -62,7 +59,6 @@ describe("As an admin I want to create voucher", () => {
|
|||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
const usageLimit = 1;
|
||||
dataForCheckout.auth = "auth";
|
||||
let firstCheckout;
|
||||
|
@ -74,24 +70,17 @@ describe("As an admin I want to create voucher", () => {
|
|||
channelName: defaultChannel.name,
|
||||
dataForCheckout,
|
||||
usageLimit,
|
||||
})
|
||||
.then(({ checkout, addPromoCodeResp }) => {
|
||||
}).then(({ checkout, addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
firstCheckout = checkout;
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
|
||||
addPayment(firstCheckout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(firstCheckout.id);
|
||||
})
|
||||
.then(() => {
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField, "error in promo code should occur").to.be.eq(
|
||||
"promoCode",
|
||||
);
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors.0")
|
||||
.should("include", { field: "promoCode" })
|
||||
.and("include", { message: "Promo code is invalid" });
|
||||
});
|
||||
},
|
||||
);
|
||||
|
@ -101,7 +90,6 @@ describe("As an admin I want to create voucher", () => {
|
|||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
dataForCheckout.auth = "auth";
|
||||
let firstCheckout;
|
||||
|
||||
|
@ -112,46 +100,38 @@ describe("As an admin I want to create voucher", () => {
|
|||
channelName: defaultChannel.name,
|
||||
dataForCheckout,
|
||||
applyOnePerCustomer: true,
|
||||
})
|
||||
.then(({ checkout, addPromoCodeResp }) => {
|
||||
}).then(({ checkout, addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
firstCheckout = checkout;
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
|
||||
addPayment(firstCheckout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(firstCheckout.id);
|
||||
})
|
||||
.then(() => {
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField, "error in promo code should occur").to.be.eq(
|
||||
"promoCode",
|
||||
);
|
||||
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);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors;
|
||||
expect(errorField, "No errors when adding promo code").to.be.empty;
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors")
|
||||
.should("be.be.empty");
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
xit(
|
||||
it(
|
||||
"should be able to create voucher with limit to staff only. TC: SALEOR_1909",
|
||||
{ tags: ["@vouchers", "@allEnv"] },
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
dataForCheckout.auth = "auth";
|
||||
let firstCheckout;
|
||||
|
||||
|
@ -162,35 +142,35 @@ describe("As an admin I want to create voucher", () => {
|
|||
channelName: defaultChannel.name,
|
||||
dataForCheckout,
|
||||
onlyStaff: true,
|
||||
})
|
||||
.then(({ checkout, addPromoCodeResp }) => {
|
||||
}).then(({ checkout, addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
firstCheckout = checkout;
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
|
||||
addPayment(firstCheckout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(firstCheckout.id);
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
// Create new checkout as other not logged in customer - voucher should be not available for other customer
|
||||
|
||||
window.sessionStorage.setItem("token", "");
|
||||
dataForCheckout.auth = "token";
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField, "error in promo code should occur").to.be.eq(
|
||||
"promoCode",
|
||||
);
|
||||
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.",
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
xit(
|
||||
it(
|
||||
"should be able to create voucher with minimum value of order. TC: SALEOR_1910",
|
||||
{ tags: ["@vouchers", "@allEnv"] },
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
const minOrderValue = productPrice * 1.5;
|
||||
dataForCheckout.productQuantity = 1;
|
||||
|
||||
|
@ -202,27 +182,25 @@ describe("As an admin I want to create voucher", () => {
|
|||
dataForCheckout,
|
||||
minOrderValue,
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
|
||||
expect(errorField, "error in promo code should occur").to.be.eq(
|
||||
"promoCode",
|
||||
);
|
||||
dataForCheckout.productQuantity = 2;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors;
|
||||
expect(errorField, "No errors when adding promo code").to.be.empty;
|
||||
.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");
|
||||
},
|
||||
);
|
||||
|
||||
xit("should create voucher with min product quantity. TC: SALEOR_1911", () => {
|
||||
it(
|
||||
"should create voucher with min product quantity. TC: SALEOR_1911",
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
const minAmountOfItems = 2;
|
||||
dataForCheckout.productQuantity = 1;
|
||||
|
||||
loginAndCreateCheckoutForVoucherWithDiscount({
|
||||
|
@ -231,21 +209,19 @@ describe("As an admin I want to create voucher", () => {
|
|||
voucherCode,
|
||||
channelName: defaultChannel.name,
|
||||
dataForCheckout,
|
||||
minAmountOfItems,
|
||||
minAmountOfItems: 2,
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
.its("addPromoCodeResp.errors.0")
|
||||
.should("include", { field: "promoCode" })
|
||||
.and("include", {
|
||||
message: "Voucher is not applicable to this checkout.",
|
||||
});
|
||||
dataForCheckout.voucherCode = voucherCode;
|
||||
|
||||
expect(errorField, "error in promo code should occur").to.be.eq(
|
||||
"promoCode",
|
||||
);
|
||||
dataForCheckout.productQuantity = 2;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors;
|
||||
expect(errorField, "No errors when adding promo code").to.be.empty;
|
||||
});
|
||||
});
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors")
|
||||
.should("be.be.empty");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
|
@ -19,15 +19,17 @@ describe("As an admin I want to update vouchers", () => {
|
|||
const startsWith = "UpdateVou-";
|
||||
const productPrice = 100;
|
||||
const shippingPrice = 100;
|
||||
const voucherValue = 50;
|
||||
|
||||
let defaultChannel;
|
||||
let product;
|
||||
let dataForCheckout;
|
||||
|
||||
before(() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteVouchersStartsWith(startsWith);
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createProductWithShipping({ name, productPrice, shippingPrice })
|
||||
.then(
|
||||
|
@ -54,12 +56,9 @@ describe("As an admin I want to update vouchers", () => {
|
|||
|
||||
it(
|
||||
"should delete voucher. TC: SALEOR_1905",
|
||||
{ tags: ["@vouchers", "@allEnv"] },
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
|
||||
let voucherCreate;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
|
@ -67,54 +66,50 @@ describe("As an admin I want to update vouchers", () => {
|
|||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue,
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucherCreate = voucherResp;
|
||||
expect(voucherCreate.voucher.id).to.be.ok;
|
||||
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id))
|
||||
}).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 = voucherCreate.code;
|
||||
|
||||
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
||||
window.sessionStorage.setItem("token", "");
|
||||
dataForCheckout.auth = "token";
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors.0")
|
||||
.should("include", { field: "promoCode" })
|
||||
.and("include", { message: "Promo code is invalid" });
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"should update voucher. TC: SALEOR_1906",
|
||||
{ tags: ["@vouchers", "@allEnv"] },
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
const voucherUpdatedValue = 20;
|
||||
const expectedOrderAmount =
|
||||
productPrice +
|
||||
shippingPrice -
|
||||
(productPrice * voucherUpdatedValue) / 100;
|
||||
|
||||
let voucherCreate;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
name,
|
||||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue,
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucherCreate = voucherResp;
|
||||
expect(voucherCreate.voucher.id).to.be.ok;
|
||||
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id))
|
||||
}).then(voucherResp => {
|
||||
expect(voucherResp.voucher.id).to.be.ok;
|
||||
|
||||
cy.visit(voucherDetailsUrl(voucherResp.voucher.id))
|
||||
.addAliasToGraphRequest("VoucherUpdate")
|
||||
.get(VOUCHERS_SELECTORS.percentageDiscountRadioButton)
|
||||
.click()
|
||||
|
@ -123,14 +118,14 @@ describe("As an admin I want to update vouchers", () => {
|
|||
.get(BUTTON_SELECTORS.confirm)
|
||||
.click()
|
||||
.wait("@VoucherUpdate");
|
||||
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||
|
||||
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
||||
window.sessionStorage.setItem("token", "");
|
||||
dataForCheckout.auth = "token";
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const amount = addPromoCodeResp.checkout.totalPrice.gross.amount;
|
||||
expect(amount).to.be.eq(expectedOrderAmount);
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.checkout.totalPrice.gross.amount")
|
||||
.should("eq", expectedOrderAmount);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
@ -140,13 +135,10 @@ describe("As an admin I want to update vouchers", () => {
|
|||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
const today = new Date();
|
||||
const tomorrow = new Date(today);
|
||||
const todayDate = formatDate(today);
|
||||
const tomorrowDate = formatDate(tomorrow.setDate(tomorrow.getDate() + 1));
|
||||
|
||||
let voucherCreate;
|
||||
const todayDate = formatDate(new Date());
|
||||
const tomorrowDate = formatDate(
|
||||
new Date().setDate(new Date().getDate() + 1),
|
||||
);
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
|
@ -154,47 +146,42 @@ describe("As an admin I want to update vouchers", () => {
|
|||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue,
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucherCreate = voucherResp;
|
||||
expect(voucherCreate.voucher.id).to.be.ok;
|
||||
}).then(voucherResp => {
|
||||
expect(voucherResp.voucher.id).to.be.ok;
|
||||
|
||||
setVoucherDate({
|
||||
voucherId: voucherCreate.voucher.id,
|
||||
voucherId: voucherResp.voucher.id,
|
||||
startDate: tomorrowDate,
|
||||
});
|
||||
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors.0")
|
||||
.should("include", { field: "promoCode" })
|
||||
.and("include", { message: "Promo code is invalid" });
|
||||
setVoucherDate({
|
||||
voucherId: voucherCreate.voucher.id,
|
||||
voucherId: voucherResp.voucher.id,
|
||||
startDate: todayDate,
|
||||
});
|
||||
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||
window.sessionStorage.setItem("token", "");
|
||||
dataForCheckout.auth = "token";
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors")
|
||||
.should("be.be.empty");
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"should set end date on voucher. TC: SALEOR_1913",
|
||||
{ tags: ["@vouchers", "@allEnv"] },
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
const today = new Date();
|
||||
const todayDate = formatDate(today);
|
||||
const tomorrow = new Date(today);
|
||||
const tomorrowDate = formatDate(tomorrow.setDate(tomorrow.getDate() + 1));
|
||||
|
||||
let voucherCreate;
|
||||
const todayDate = formatDate(new Date());
|
||||
const tomorrowDate = formatDate(
|
||||
new Date().setDate(new Date().getDate() + 1),
|
||||
);
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
|
@ -202,46 +189,40 @@ describe("As an admin I want to update vouchers", () => {
|
|||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue,
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucherCreate = voucherResp;
|
||||
expect(voucherCreate.voucher.id).to.be.ok;
|
||||
}).then(voucherResp => {
|
||||
expect(voucherResp.voucher.id).to.be.ok;
|
||||
|
||||
setVoucherDate({
|
||||
voucherId: voucherCreate.voucher.id,
|
||||
voucherId: voucherResp.voucher.id,
|
||||
endDate: todayDate,
|
||||
endTime: formatTime(today),
|
||||
endTime: formatTime(new Date()),
|
||||
hasEndDate: true,
|
||||
});
|
||||
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
||||
window.sessionStorage.setItem("token", "");
|
||||
dataForCheckout.auth = "token";
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors.0")
|
||||
.should("include", { field: "promoCode" })
|
||||
.and("include", { message: "Promo code is invalid" });
|
||||
setVoucherDate({
|
||||
voucherId: voucherCreate.voucher.id,
|
||||
voucherId: voucherResp.voucher.id,
|
||||
endDate: tomorrowDate,
|
||||
endTime: formatTime(tomorrow),
|
||||
endTime: formatTime(new Date()),
|
||||
});
|
||||
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors")
|
||||
.should("be.be.empty");
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it(
|
||||
"should set country on voucher. TC: SALEOR_1914",
|
||||
{ tags: ["@vouchers", "@allEnv"] },
|
||||
{ tags: ["@vouchers", "@allEnv", "@stable"] },
|
||||
() => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
|
||||
let voucherCreate;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
|
@ -251,18 +232,16 @@ describe("As an admin I want to update vouchers", () => {
|
|||
value: voucherValue,
|
||||
type: "SHIPPING",
|
||||
country: "US",
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucherCreate = voucherResp;
|
||||
expect(voucherCreate.voucher.id).to.be.ok;
|
||||
dataForCheckout.voucherCode = voucherCreate.voucher.code;
|
||||
}).then(voucherResp => {
|
||||
expect(voucherResp.voucher.id).to.be.ok;
|
||||
dataForCheckout.voucherCode = voucherResp.voucher.code;
|
||||
window.sessionStorage.setItem("token", "");
|
||||
dataForCheckout.auth = "token";
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id))
|
||||
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors")
|
||||
.should("be.be.empty");
|
||||
cy.visit(voucherDetailsUrl(voucherResp.voucher.id))
|
||||
.get(VOUCHERS_SELECTORS.shippingDiscountRadioButton)
|
||||
.click()
|
||||
.get(VOUCHERS_SELECTORS.countriesDropdownIcon)
|
||||
|
@ -278,11 +257,12 @@ describe("As an admin I want to update vouchers", () => {
|
|||
.get(BUTTON_SELECTORS.confirm)
|
||||
.click()
|
||||
.wait("@VoucherUpdate");
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
createCheckoutWithVoucher(dataForCheckout)
|
||||
.its("addPromoCodeResp.errors.0")
|
||||
.should("include", { field: "promoCode" })
|
||||
.and("include", {
|
||||
message: "Voucher is not applicable to this checkout.",
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
|
@ -2,7 +2,7 @@ import {
|
|||
getDefaultAddress,
|
||||
getPaymentDataLine,
|
||||
getValueWithDefault,
|
||||
getVariantsLines
|
||||
getVariantsLines,
|
||||
} from "./utils/Utils";
|
||||
|
||||
export function createCheckout({
|
||||
|
@ -13,13 +13,13 @@ export function createCheckout({
|
|||
address,
|
||||
billingAddress,
|
||||
auth = "auth",
|
||||
returnAvailableCollectionPoints = false
|
||||
returnAvailableCollectionPoints = false,
|
||||
}) {
|
||||
const lines = getVariantsLines(variantsList, productQuantity);
|
||||
const shippingAddress = getDefaultAddress(address, "shippingAddress");
|
||||
const billingAddressLines = getDefaultAddress(
|
||||
billingAddress,
|
||||
"billingAddress"
|
||||
"billingAddress",
|
||||
);
|
||||
|
||||
const availableCollectionPointsLines = getValueWithDefault(
|
||||
|
@ -29,7 +29,7 @@ export function createCheckout({
|
|||
name
|
||||
clickAndCollectOption
|
||||
isPrivate
|
||||
}`
|
||||
}`,
|
||||
);
|
||||
|
||||
const emailLine = getValueWithDefault(email, `email: "${email}"`);
|
||||
|
@ -233,7 +233,7 @@ export function checkoutShippingAddressUpdate(checkoutId, address) {
|
|||
export function addProductsToCheckout(
|
||||
checkoutId,
|
||||
variantsList,
|
||||
productQuantity
|
||||
productQuantity,
|
||||
) {
|
||||
const lines = getVariantsLines(variantsList, productQuantity);
|
||||
const mutation = `mutation{
|
||||
|
|
|
@ -66,11 +66,15 @@ export function addChannelToVoucher(voucherId, channelId, value) {
|
|||
discountValue:"${value}"
|
||||
}
|
||||
}){
|
||||
voucher{
|
||||
id
|
||||
code
|
||||
}
|
||||
errors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
return cy.sendRequestWithQuery(mutation).its("body.data");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue