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:
Ewa Czerniak 2022-08-18 15:14:29 +02:00 committed by GitHub
parent 8e2a3e0c75
commit cea3ead44b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 315 additions and 373 deletions

View file

@ -1,8 +1,6 @@
/// <reference types="cypress"/> /// <reference types="cypress"/>
/// <reference types="../../support"/> /// <reference types="../../support"/>
import faker from "faker";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { urlList } from "../../fixtures/urlList"; import { urlList } from "../../fixtures/urlList";
import { import {
@ -10,7 +8,7 @@ import {
updateShopAddress, updateShopAddress,
} from "../../support/api/requests/ShopSettings"; } from "../../support/api/requests/ShopSettings";
xdescribe("Tests for site settings", () => { describe("Tests for site settings", () => {
let address; let address;
before(() => { before(() => {
@ -24,7 +22,7 @@ xdescribe("Tests for site settings", () => {
it( it(
"should change store address", "should change store address",
{ tags: ["@siteSettings", "@allEnv"] }, { tags: ["@siteSettings", "@allEnv", "@stable"] },
() => { () => {
cy.clearSessionData() cy.clearSessionData()
.loginUserViaRequest() .loginUserViaRequest()

View file

@ -13,7 +13,6 @@ import {
createCheckoutWithVoucher, createCheckoutWithVoucher,
} from "../../../support/api/utils/ordersUtils"; } from "../../../support/api/utils/ordersUtils";
import * as productsUtils from "../../../support/api/utils/products/productsUtils"; import * as productsUtils from "../../../support/api/utils/products/productsUtils";
import filterTests from "../../../support/filterTests";
import { import {
createVoucher, createVoucher,
discountOptions, discountOptions,
@ -24,19 +23,17 @@ describe("As an admin I want to create voucher", () => {
const startsWith = "CyVou-"; const startsWith = "CyVou-";
const productPrice = 100; const productPrice = 100;
const shippingPrice = 100; const shippingPrice = 100;
const voucherValue = 50;
const name = `${startsWith}${faker.datatype.number()}`;
let defaultChannel;
let createdChannel; let createdChannel;
let shippingMethod;
let variants;
let address;
let dataForCheckout; let dataForCheckout;
let defaultChannel;
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
channelsUtils.deleteChannelsStartsWith(startsWith); channelsUtils.deleteChannelsStartsWith(startsWith);
deleteVouchersStartsWith(startsWith); deleteVouchersStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`;
productsUtils productsUtils
.createProductWithShipping({ name, productPrice, shippingPrice }) .createProductWithShipping({ name, productPrice, shippingPrice })
.then( .then(
@ -46,30 +43,23 @@ describe("As an admin I want to create voucher", () => {
shippingMethod: shippingMethodResp, shippingMethod: shippingMethodResp,
address: addressResp, address: addressResp,
}) => { }) => {
variants = variantsResp;
defaultChannel = channel; defaultChannel = channel;
shippingMethod = shippingMethodResp;
address = addressResp;
createChannel({ name });
},
)
.then(channel => {
createdChannel = channel;
dataForCheckout = { dataForCheckout = {
channelSlug: defaultChannel.slug, channelSlug: defaultChannel.slug,
variantsList: variants, variantsList: variantsResp,
address, address: addressResp,
shippingMethodName: shippingMethod.name, shippingMethodName: shippingMethodResp.name,
auth: "token", auth: "token",
}; };
}); },
);
}); });
it( it(
"should be able to create fixed price voucher. TC: SALEOR_1901", "should be able to create fixed price voucher. TC: SALEOR_1901",
{ tags: ["@vouchers", "@allEnv", "@stable"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const voucherValue = 50;
const voucherCode = `${startsWith}${faker.datatype.number()}`; const voucherCode = `${startsWith}${faker.datatype.number()}`;
const expectedAmount = productPrice + shippingPrice - voucherValue; const expectedAmount = productPrice + shippingPrice - voucherValue;
let checkout; let checkout;
@ -80,20 +70,17 @@ describe("As an admin I want to create voucher", () => {
voucherCode, voucherCode,
channelName: defaultChannel.name, channelName: defaultChannel.name,
dataForCheckout, dataForCheckout,
}) }).then(({ addPromoCodeResp, checkout: checkoutResp }) => {
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq( expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
expectedAmount, expectedAmount,
); );
dataForCheckout.voucherCode = voucherCode; dataForCheckout.voucherCode = voucherCode;
checkout = checkoutResp; checkout = checkoutResp;
addPayment(checkout.id); addPayment(checkout.id);
}) completeCheckout(checkout.id)
.then(() => { .its("order.total.gross.amount")
completeCheckout(checkout.id); .should("eq", expectedAmount);
})
.then(({ order }) => {
expect(order.id).to.be.ok;
}); });
}, },
); );
@ -102,7 +89,6 @@ describe("As an admin I want to create voucher", () => {
"should be able to create percentage voucher. TC: SALEOR_1902", "should be able to create percentage voucher. TC: SALEOR_1902",
{ tags: ["@vouchers", "@allEnv", "@stable"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const voucherValue = 50;
const voucherCode = `${startsWith}${faker.datatype.number()}`; const voucherCode = `${startsWith}${faker.datatype.number()}`;
const expectedAmount = const expectedAmount =
(productPrice * voucherValue) / 100 + shippingPrice; (productPrice * voucherValue) / 100 + shippingPrice;
@ -114,20 +100,17 @@ describe("As an admin I want to create voucher", () => {
voucherCode, voucherCode,
channelName: defaultChannel.name, channelName: defaultChannel.name,
dataForCheckout, dataForCheckout,
}) }).then(({ addPromoCodeResp, checkout: checkoutResp }) => {
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq( expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
expectedAmount, expectedAmount,
); );
dataForCheckout.voucherCode = voucherCode; dataForCheckout.voucherCode = voucherCode;
checkout = checkoutResp; checkout = checkoutResp;
addPayment(checkout.id); addPayment(checkout.id);
}) completeCheckout(checkout.id)
.then(() => { .its("order.total.gross.amount")
completeCheckout(checkout.id); .should("eq", expectedAmount);
})
.then(({ order }) => {
expect(order.id).to.be.ok;
}); });
}, },
); );
@ -145,20 +128,17 @@ describe("As an admin I want to create voucher", () => {
voucherCode, voucherCode,
channelName: defaultChannel.name, channelName: defaultChannel.name,
dataForCheckout, dataForCheckout,
}) }).then(({ addPromoCodeResp, checkout: checkoutResp }) => {
.then(({ addPromoCodeResp, checkout: checkoutResp }) => {
expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq( expect(addPromoCodeResp.checkout.totalPrice.gross.amount).to.be.eq(
expectedAmount, expectedAmount,
); );
dataForCheckout.voucherCode = voucherCode; dataForCheckout.voucherCode = voucherCode;
checkout = checkoutResp; checkout = checkoutResp;
addPayment(checkout.id); addPayment(checkout.id);
}) completeCheckout(checkout.id)
.then(() => { .its("order.total.gross.amount")
completeCheckout(checkout.id); .should("eq", productPrice);
})
.then(({ order }) => {
expect(order.id).to.be.ok;
}); });
}, },
); );
@ -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", "should be able to create voucher not available for selected channel. TC: SALEOR_1904",
{ tags: ["@vouchers", "@allEnv", "@stable"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const randomName = `${startsWith}${faker.datatype.number()}`; const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
cy.clearSessionData() cy.clearSessionData()
.loginUserViaRequest() .loginUserViaRequest()
.visit(urlList.vouchers); .visit(urlList.vouchers);
cy.expectSkeletonIsVisible(); cy.expectSkeletonIsVisible();
createChannel({ name }).then(channel => {
createdChannel = channel;
cy.reload();
createVoucher({ createVoucher({
voucherCode: randomName, voucherCode,
voucherValue, voucherValue,
discountOption: discountOptions.PERCENTAGE, discountOption: discountOptions.PERCENTAGE,
channelName: createdChannel.name, channelName: createdChannel.name,
}); });
dataForCheckout.voucherCode = randomName; });
createCheckoutWithVoucher(dataForCheckout).then(
({ addPromoCodeResp }) => { dataForCheckout.voucherCode = voucherCode;
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" });
}, },
); );
}); });

View file

@ -20,18 +20,17 @@ describe("As an admin I want to create voucher", () => {
const startsWith = "CyVouLimit-"; const startsWith = "CyVouLimit-";
const productPrice = 100; const productPrice = 100;
const shippingPrice = 100; const shippingPrice = 100;
const voucherValue = 50;
let defaultChannel; let defaultChannel;
let shippingMethod;
let variants;
let address;
let dataForCheckout; let dataForCheckout;
before(() => { before(() => {
const name = `${startsWith}${faker.datatype.number()}`;
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
channelsUtils.deleteChannelsStartsWith(startsWith); channelsUtils.deleteChannelsStartsWith(startsWith);
deleteVouchersStartsWith(startsWith); deleteVouchersStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`;
productsUtils productsUtils
.createProductWithShipping({ name, productPrice, shippingPrice }) .createProductWithShipping({ name, productPrice, shippingPrice })
.then( .then(
@ -41,15 +40,13 @@ describe("As an admin I want to create voucher", () => {
shippingMethod: shippingMethodResp, shippingMethod: shippingMethodResp,
address: addressResp, address: addressResp,
}) => { }) => {
variants = variantsResp;
defaultChannel = channel; defaultChannel = channel;
shippingMethod = shippingMethodResp;
address = addressResp;
dataForCheckout = { dataForCheckout = {
channelSlug: defaultChannel.slug, channelSlug: defaultChannel.slug,
variantsList: variants, variantsList: variantsResp,
address, address: addressResp,
shippingMethodName: shippingMethod.name, shippingMethodName: shippingMethodResp.name,
auth: "token", auth: "token",
}; };
cy.clearSessionData(); cy.clearSessionData();
@ -62,7 +59,6 @@ describe("As an admin I want to create voucher", () => {
{ tags: ["@vouchers", "@allEnv", "@stable"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`; const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
const usageLimit = 1; const usageLimit = 1;
dataForCheckout.auth = "auth"; dataForCheckout.auth = "auth";
let firstCheckout; let firstCheckout;
@ -74,24 +70,17 @@ describe("As an admin I want to create voucher", () => {
channelName: defaultChannel.name, channelName: defaultChannel.name,
dataForCheckout, dataForCheckout,
usageLimit, usageLimit,
}) }).then(({ checkout, addPromoCodeResp }) => {
.then(({ checkout, addPromoCodeResp }) => {
expect(addPromoCodeResp.errors).to.be.empty; expect(addPromoCodeResp.errors).to.be.empty;
firstCheckout = checkout; firstCheckout = checkout;
dataForCheckout.voucherCode = voucherCode; dataForCheckout.voucherCode = voucherCode;
addPayment(firstCheckout.id); addPayment(firstCheckout.id);
})
.then(() => {
completeCheckout(firstCheckout.id); completeCheckout(firstCheckout.id);
}) createCheckoutWithVoucher(dataForCheckout)
.then(() => { .its("addPromoCodeResp.errors.0")
createCheckoutWithVoucher(dataForCheckout); .should("include", { field: "promoCode" })
}) .and("include", { message: "Promo code is invalid" });
.then(({ addPromoCodeResp }) => {
const errorField = addPromoCodeResp.errors[0].field;
expect(errorField, "error in promo code should occur").to.be.eq(
"promoCode",
);
}); });
}, },
); );
@ -101,7 +90,6 @@ describe("As an admin I want to create voucher", () => {
{ tags: ["@vouchers", "@allEnv", "@stable"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`; const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
dataForCheckout.auth = "auth"; dataForCheckout.auth = "auth";
let firstCheckout; let firstCheckout;
@ -112,46 +100,38 @@ describe("As an admin I want to create voucher", () => {
channelName: defaultChannel.name, channelName: defaultChannel.name,
dataForCheckout, dataForCheckout,
applyOnePerCustomer: true, applyOnePerCustomer: true,
}) }).then(({ checkout, addPromoCodeResp }) => {
.then(({ checkout, addPromoCodeResp }) => {
expect(addPromoCodeResp.errors).to.be.empty; expect(addPromoCodeResp.errors).to.be.empty;
dataForCheckout.voucherCode = voucherCode;
firstCheckout = checkout; firstCheckout = checkout;
dataForCheckout.voucherCode = voucherCode;
addPayment(firstCheckout.id); addPayment(firstCheckout.id);
})
.then(() => {
completeCheckout(firstCheckout.id); completeCheckout(firstCheckout.id);
}) createCheckoutWithVoucher(dataForCheckout)
.then(() => { .its("addPromoCodeResp.errors.0")
createCheckoutWithVoucher(dataForCheckout); .should("include", { field: "promoCode" })
}) .and("include", {
.then(({ addPromoCodeResp }) => { message: "Voucher is not applicable to this checkout.",
const errorField = addPromoCodeResp.errors[0].field; });
expect(errorField, "error in promo code should occur").to.be.eq(
"promoCode",
);
// Create new checkout as other not logged in customer - voucher should be available for other customer // Create new checkout as other not logged in customer - voucher should be available for other customer
window.sessionStorage.setItem("token", ""); window.sessionStorage.setItem("token", "");
dataForCheckout.auth = "token"; dataForCheckout.auth = "token";
dataForCheckout.email = "newUser@example.com"; dataForCheckout.email = "newUser@example.com";
createCheckoutWithVoucher(dataForCheckout);
}) createCheckoutWithVoucher(dataForCheckout)
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors")
const errorField = addPromoCodeResp.errors; .should("be.be.empty");
expect(errorField, "No errors when adding promo code").to.be.empty;
}); });
}, },
); );
xit( it(
"should be able to create voucher with limit to staff only. TC: SALEOR_1909", "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 voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
dataForCheckout.auth = "auth"; dataForCheckout.auth = "auth";
let firstCheckout; let firstCheckout;
@ -162,35 +142,35 @@ describe("As an admin I want to create voucher", () => {
channelName: defaultChannel.name, channelName: defaultChannel.name,
dataForCheckout, dataForCheckout,
onlyStaff: true, onlyStaff: true,
}) }).then(({ checkout, addPromoCodeResp }) => {
.then(({ checkout, addPromoCodeResp }) => {
expect(addPromoCodeResp.errors).to.be.empty; expect(addPromoCodeResp.errors).to.be.empty;
dataForCheckout.voucherCode = voucherCode;
firstCheckout = checkout; firstCheckout = checkout;
dataForCheckout.voucherCode = voucherCode;
addPayment(firstCheckout.id); addPayment(firstCheckout.id);
})
.then(() => {
completeCheckout(firstCheckout.id); 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"; dataForCheckout.auth = "token";
createCheckoutWithVoucher(dataForCheckout); dataForCheckout.email = "newUser@example.com";
})
.then(({ addPromoCodeResp }) => { createCheckoutWithVoucher(dataForCheckout)
const errorField = addPromoCodeResp.errors[0].field; .its("addPromoCodeResp.errors.0")
expect(errorField, "error in promo code should occur").to.be.eq( .should("include", { field: "promoCode" })
"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", "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 voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
const minOrderValue = productPrice * 1.5; const minOrderValue = productPrice * 1.5;
dataForCheckout.productQuantity = 1; dataForCheckout.productQuantity = 1;
@ -202,27 +182,25 @@ describe("As an admin I want to create voucher", () => {
dataForCheckout, dataForCheckout,
minOrderValue, minOrderValue,
}) })
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors.0")
const errorField = addPromoCodeResp.errors[0].field; .should("include", { field: "promoCode" })
dataForCheckout.voucherCode = voucherCode; .and("include", {
message: "Voucher is not applicable to this checkout.",
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;
}); });
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 voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
const minAmountOfItems = 2;
dataForCheckout.productQuantity = 1; dataForCheckout.productQuantity = 1;
loginAndCreateCheckoutForVoucherWithDiscount({ loginAndCreateCheckoutForVoucherWithDiscount({
@ -231,21 +209,19 @@ describe("As an admin I want to create voucher", () => {
voucherCode, voucherCode,
channelName: defaultChannel.name, channelName: defaultChannel.name,
dataForCheckout, dataForCheckout,
minAmountOfItems, minAmountOfItems: 2,
}) })
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors.0")
const errorField = addPromoCodeResp.errors[0].field; .should("include", { field: "promoCode" })
.and("include", {
message: "Voucher is not applicable to this checkout.",
});
dataForCheckout.voucherCode = voucherCode; dataForCheckout.voucherCode = voucherCode;
expect(errorField, "error in promo code should occur").to.be.eq(
"promoCode",
);
dataForCheckout.productQuantity = 2; dataForCheckout.productQuantity = 2;
createCheckoutWithVoucher(dataForCheckout);
}) createCheckoutWithVoucher(dataForCheckout)
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors")
const errorField = addPromoCodeResp.errors; .should("be.be.empty");
expect(errorField, "No errors when adding promo code").to.be.empty; },
}); );
});
}); });

View file

@ -19,15 +19,17 @@ describe("As an admin I want to update vouchers", () => {
const startsWith = "UpdateVou-"; const startsWith = "UpdateVou-";
const productPrice = 100; const productPrice = 100;
const shippingPrice = 100; const shippingPrice = 100;
const voucherValue = 50;
let defaultChannel; let defaultChannel;
let product; let product;
let dataForCheckout; let dataForCheckout;
before(() => { before(() => {
const name = `${startsWith}${faker.datatype.number()}`;
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
deleteVouchersStartsWith(startsWith); deleteVouchersStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`;
productsUtils productsUtils
.createProductWithShipping({ name, productPrice, shippingPrice }) .createProductWithShipping({ name, productPrice, shippingPrice })
.then( .then(
@ -54,12 +56,9 @@ describe("As an admin I want to update vouchers", () => {
it( it(
"should delete voucher. TC: SALEOR_1905", "should delete voucher. TC: SALEOR_1905",
{ tags: ["@vouchers", "@allEnv"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
let voucherCreate;
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
createVoucherInChannel({ createVoucherInChannel({
@ -67,54 +66,50 @@ describe("As an admin I want to update vouchers", () => {
productId: product.id, productId: product.id,
channelId: defaultChannel.id, channelId: defaultChannel.id,
value: voucherValue, value: voucherValue,
}) }).then(voucherResp => {
.then(voucherResp => { expect(voucherResp.voucher.id).to.be.ok;
voucherCreate = voucherResp;
expect(voucherCreate.voucher.id).to.be.ok; cy.visit(voucherDetailsUrl(voucherResp.voucher.id))
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id))
.addAliasToGraphRequest("VoucherDelete") .addAliasToGraphRequest("VoucherDelete")
.get(BUTTON_SELECTORS.deleteButton) .get(BUTTON_SELECTORS.deleteButton)
.click() .click()
.get(BUTTON_SELECTORS.submit) .get(BUTTON_SELECTORS.submit)
.click() .click()
.wait("@VoucherDelete"); .wait("@VoucherDelete");
dataForCheckout.voucherCode = voucherCreate.code;
dataForCheckout.voucherCode = voucherResp.voucher.code;
window.sessionStorage.setItem("token", ""); window.sessionStorage.setItem("token", "");
dataForCheckout.auth = "token"; dataForCheckout.auth = "token";
createCheckoutWithVoucher(dataForCheckout);
}) createCheckoutWithVoucher(dataForCheckout)
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors.0")
const errorField = addPromoCodeResp.errors[0].field; .should("include", { field: "promoCode" })
expect(errorField).to.be.eq("promoCode"); .and("include", { message: "Promo code is invalid" });
}); });
}, },
); );
it( it(
"should update voucher. TC: SALEOR_1906", "should update voucher. TC: SALEOR_1906",
{ tags: ["@vouchers", "@allEnv"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
const voucherUpdatedValue = 20; const voucherUpdatedValue = 20;
const expectedOrderAmount = const expectedOrderAmount =
productPrice + productPrice +
shippingPrice - shippingPrice -
(productPrice * voucherUpdatedValue) / 100; (productPrice * voucherUpdatedValue) / 100;
let voucherCreate;
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
createVoucherInChannel({ createVoucherInChannel({
name, name,
productId: product.id, productId: product.id,
channelId: defaultChannel.id, channelId: defaultChannel.id,
value: voucherValue, value: voucherValue,
}) }).then(voucherResp => {
.then(voucherResp => { expect(voucherResp.voucher.id).to.be.ok;
voucherCreate = voucherResp;
expect(voucherCreate.voucher.id).to.be.ok; cy.visit(voucherDetailsUrl(voucherResp.voucher.id))
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id))
.addAliasToGraphRequest("VoucherUpdate") .addAliasToGraphRequest("VoucherUpdate")
.get(VOUCHERS_SELECTORS.percentageDiscountRadioButton) .get(VOUCHERS_SELECTORS.percentageDiscountRadioButton)
.click() .click()
@ -123,14 +118,14 @@ describe("As an admin I want to update vouchers", () => {
.get(BUTTON_SELECTORS.confirm) .get(BUTTON_SELECTORS.confirm)
.click() .click()
.wait("@VoucherUpdate"); .wait("@VoucherUpdate");
dataForCheckout.voucherCode = voucherCreate.voucher.code;
dataForCheckout.voucherCode = voucherResp.voucher.code;
window.sessionStorage.setItem("token", ""); window.sessionStorage.setItem("token", "");
dataForCheckout.auth = "token"; dataForCheckout.auth = "token";
createCheckoutWithVoucher(dataForCheckout);
}) createCheckoutWithVoucher(dataForCheckout)
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.checkout.totalPrice.gross.amount")
const amount = addPromoCodeResp.checkout.totalPrice.gross.amount; .should("eq", expectedOrderAmount);
expect(amount).to.be.eq(expectedOrderAmount);
}); });
}, },
); );
@ -140,13 +135,10 @@ describe("As an admin I want to update vouchers", () => {
{ tags: ["@vouchers", "@allEnv", "@stable"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50; const todayDate = formatDate(new Date());
const today = new Date(); const tomorrowDate = formatDate(
const tomorrow = new Date(today); new Date().setDate(new Date().getDate() + 1),
const todayDate = formatDate(today); );
const tomorrowDate = formatDate(tomorrow.setDate(tomorrow.getDate() + 1));
let voucherCreate;
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
createVoucherInChannel({ createVoucherInChannel({
@ -154,47 +146,42 @@ describe("As an admin I want to update vouchers", () => {
productId: product.id, productId: product.id,
channelId: defaultChannel.id, channelId: defaultChannel.id,
value: voucherValue, value: voucherValue,
}) }).then(voucherResp => {
.then(voucherResp => { expect(voucherResp.voucher.id).to.be.ok;
voucherCreate = voucherResp;
expect(voucherCreate.voucher.id).to.be.ok;
setVoucherDate({ setVoucherDate({
voucherId: voucherCreate.voucher.id, voucherId: voucherResp.voucher.id,
startDate: tomorrowDate, startDate: tomorrowDate,
}); });
dataForCheckout.voucherCode = voucherCreate.voucher.code; dataForCheckout.voucherCode = voucherResp.voucher.code;
createCheckoutWithVoucher(dataForCheckout);
}) createCheckoutWithVoucher(dataForCheckout)
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors.0")
const errorField = addPromoCodeResp.errors[0].field; .should("include", { field: "promoCode" })
expect(errorField).to.be.eq("promoCode"); .and("include", { message: "Promo code is invalid" });
setVoucherDate({ setVoucherDate({
voucherId: voucherCreate.voucher.id, voucherId: voucherResp.voucher.id,
startDate: todayDate, startDate: todayDate,
}); });
dataForCheckout.voucherCode = voucherCreate.voucher.code;
window.sessionStorage.setItem("token", ""); window.sessionStorage.setItem("token", "");
dataForCheckout.auth = "token"; dataForCheckout.auth = "token";
createCheckoutWithVoucher(dataForCheckout);
}) createCheckoutWithVoucher(dataForCheckout)
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors")
expect(addPromoCodeResp.errors).to.be.empty; .should("be.be.empty");
}); });
}, },
); );
it( it(
"should set end date on voucher. TC: SALEOR_1913", "should set end date on voucher. TC: SALEOR_1913",
{ tags: ["@vouchers", "@allEnv"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50; const todayDate = formatDate(new Date());
const today = new Date(); const tomorrowDate = formatDate(
const todayDate = formatDate(today); new Date().setDate(new Date().getDate() + 1),
const tomorrow = new Date(today); );
const tomorrowDate = formatDate(tomorrow.setDate(tomorrow.getDate() + 1));
let voucherCreate;
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
createVoucherInChannel({ createVoucherInChannel({
@ -202,46 +189,40 @@ describe("As an admin I want to update vouchers", () => {
productId: product.id, productId: product.id,
channelId: defaultChannel.id, channelId: defaultChannel.id,
value: voucherValue, value: voucherValue,
}) }).then(voucherResp => {
.then(voucherResp => { expect(voucherResp.voucher.id).to.be.ok;
voucherCreate = voucherResp;
expect(voucherCreate.voucher.id).to.be.ok;
setVoucherDate({ setVoucherDate({
voucherId: voucherCreate.voucher.id, voucherId: voucherResp.voucher.id,
endDate: todayDate, endDate: todayDate,
endTime: formatTime(today), endTime: formatTime(new Date()),
hasEndDate: true, hasEndDate: true,
}); });
dataForCheckout.voucherCode = voucherCreate.voucher.code; dataForCheckout.voucherCode = voucherResp.voucher.code;
window.sessionStorage.setItem("token", ""); window.sessionStorage.setItem("token", "");
dataForCheckout.auth = "token"; dataForCheckout.auth = "token";
createCheckoutWithVoucher(dataForCheckout);
}) createCheckoutWithVoucher(dataForCheckout)
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors.0")
const errorField = addPromoCodeResp.errors[0].field; .should("include", { field: "promoCode" })
expect(errorField).to.be.eq("promoCode"); .and("include", { message: "Promo code is invalid" });
setVoucherDate({ setVoucherDate({
voucherId: voucherCreate.voucher.id, voucherId: voucherResp.voucher.id,
endDate: tomorrowDate, endDate: tomorrowDate,
endTime: formatTime(tomorrow), endTime: formatTime(new Date()),
}); });
dataForCheckout.voucherCode = voucherCreate.voucher.code; createCheckoutWithVoucher(dataForCheckout)
createCheckoutWithVoucher(dataForCheckout); .its("addPromoCodeResp.errors")
}) .should("be.be.empty");
.then(({ addPromoCodeResp }) => {
expect(addPromoCodeResp.errors).to.be.empty;
}); });
}, },
); );
it( it(
"should set country on voucher. TC: SALEOR_1914", "should set country on voucher. TC: SALEOR_1914",
{ tags: ["@vouchers", "@allEnv"] }, { tags: ["@vouchers", "@allEnv", "@stable"] },
() => { () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50;
let voucherCreate;
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
createVoucherInChannel({ createVoucherInChannel({
@ -251,18 +232,16 @@ describe("As an admin I want to update vouchers", () => {
value: voucherValue, value: voucherValue,
type: "SHIPPING", type: "SHIPPING",
country: "US", country: "US",
}) }).then(voucherResp => {
.then(voucherResp => { expect(voucherResp.voucher.id).to.be.ok;
voucherCreate = voucherResp; dataForCheckout.voucherCode = voucherResp.voucher.code;
expect(voucherCreate.voucher.id).to.be.ok;
dataForCheckout.voucherCode = voucherCreate.voucher.code;
window.sessionStorage.setItem("token", ""); window.sessionStorage.setItem("token", "");
dataForCheckout.auth = "token"; dataForCheckout.auth = "token";
createCheckoutWithVoucher(dataForCheckout);
}) createCheckoutWithVoucher(dataForCheckout)
.then(({ addPromoCodeResp }) => { .its("addPromoCodeResp.errors")
expect(addPromoCodeResp.errors).to.be.empty; .should("be.be.empty");
cy.visit(voucherDetailsUrl(voucherCreate.voucher.id)) cy.visit(voucherDetailsUrl(voucherResp.voucher.id))
.get(VOUCHERS_SELECTORS.shippingDiscountRadioButton) .get(VOUCHERS_SELECTORS.shippingDiscountRadioButton)
.click() .click()
.get(VOUCHERS_SELECTORS.countriesDropdownIcon) .get(VOUCHERS_SELECTORS.countriesDropdownIcon)
@ -278,11 +257,12 @@ describe("As an admin I want to update vouchers", () => {
.get(BUTTON_SELECTORS.confirm) .get(BUTTON_SELECTORS.confirm)
.click() .click()
.wait("@VoucherUpdate"); .wait("@VoucherUpdate");
createCheckoutWithVoucher(dataForCheckout); createCheckoutWithVoucher(dataForCheckout)
}) .its("addPromoCodeResp.errors.0")
.then(({ addPromoCodeResp }) => { .should("include", { field: "promoCode" })
const errorField = addPromoCodeResp.errors[0].field; .and("include", {
expect(errorField).to.be.eq("promoCode"); message: "Voucher is not applicable to this checkout.",
});
}); });
}, },
); );

View file

@ -2,7 +2,7 @@ import {
getDefaultAddress, getDefaultAddress,
getPaymentDataLine, getPaymentDataLine,
getValueWithDefault, getValueWithDefault,
getVariantsLines getVariantsLines,
} from "./utils/Utils"; } from "./utils/Utils";
export function createCheckout({ export function createCheckout({
@ -13,13 +13,13 @@ export function createCheckout({
address, address,
billingAddress, billingAddress,
auth = "auth", auth = "auth",
returnAvailableCollectionPoints = false returnAvailableCollectionPoints = false,
}) { }) {
const lines = getVariantsLines(variantsList, productQuantity); const lines = getVariantsLines(variantsList, productQuantity);
const shippingAddress = getDefaultAddress(address, "shippingAddress"); const shippingAddress = getDefaultAddress(address, "shippingAddress");
const billingAddressLines = getDefaultAddress( const billingAddressLines = getDefaultAddress(
billingAddress, billingAddress,
"billingAddress" "billingAddress",
); );
const availableCollectionPointsLines = getValueWithDefault( const availableCollectionPointsLines = getValueWithDefault(
@ -29,7 +29,7 @@ export function createCheckout({
name name
clickAndCollectOption clickAndCollectOption
isPrivate isPrivate
}` }`,
); );
const emailLine = getValueWithDefault(email, `email: "${email}"`); const emailLine = getValueWithDefault(email, `email: "${email}"`);
@ -233,7 +233,7 @@ export function checkoutShippingAddressUpdate(checkoutId, address) {
export function addProductsToCheckout( export function addProductsToCheckout(
checkoutId, checkoutId,
variantsList, variantsList,
productQuantity productQuantity,
) { ) {
const lines = getVariantsLines(variantsList, productQuantity); const lines = getVariantsLines(variantsList, productQuantity);
const mutation = `mutation{ const mutation = `mutation{

View file

@ -66,11 +66,15 @@ export function addChannelToVoucher(voucherId, channelId, value) {
discountValue:"${value}" discountValue:"${value}"
} }
}){ }){
voucher{
id
code
}
errors{ errors{
field field
message message
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation).its("body.data");
} }