Add tests for updating vouchers (#1845)
This commit is contained in:
parent
f86a3559b0
commit
74508ed93b
12 changed files with 317 additions and 356 deletions
|
@ -7,6 +7,12 @@ export const VOUCHERS_SELECTORS = {
|
|||
fixedDiscountRadioButton: "[name='discountType'][value='VALUE_FIXED']",
|
||||
shippingDiscountRadioButton: "[name='discountType'][value='SHIPPING']",
|
||||
discountValueInputs: "[name='value']",
|
||||
startDateInput: '[name="startDate"]',
|
||||
endDateInput: '[name="endDate"]',
|
||||
hasEndDateCheckbox: '[name="hasEndDate"]',
|
||||
endTimeInput: '[name="endTime"]',
|
||||
assignCountryButton: '[data-test-id="assign-country"]',
|
||||
countriesDropdownIcon: '[data-test-id="countries-drop-down-icon"]',
|
||||
limits: {
|
||||
usageLimitCheckbox: '[data-test-id="has-usage-limit"]',
|
||||
usageLimitTextField: '[data-test-id="usage-limit"]',
|
||||
|
|
|
@ -1,244 +0,0 @@
|
|||
/// <reference types="cypress"/>
|
||||
/// <reference types="../../support"/>
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
||||
import { urlList, voucherDetailsUrl } from "../../fixtures/urlList";
|
||||
import { ONE_PERMISSION_USERS } from "../../fixtures/users";
|
||||
import { createChannel } from "../../support/api/requests/Channels";
|
||||
import { completeCheckout } from "../../support/api/requests/Checkout";
|
||||
import * as channelsUtils from "../../support/api/utils/channelsUtils";
|
||||
import {
|
||||
createVoucherInChannel,
|
||||
deleteVouchersStartsWith
|
||||
} from "../../support/api/utils/discounts/vouchersUtils";
|
||||
import {
|
||||
addPayment,
|
||||
createCheckoutWithVoucher
|
||||
} from "../../support/api/utils/ordersUtils";
|
||||
import * as productsUtils from "../../support/api/utils/products/productsUtils";
|
||||
import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils";
|
||||
import filterTests from "../../support/filterTests";
|
||||
import {
|
||||
createVoucher,
|
||||
discountOptions
|
||||
} from "../../support/pages/discounts/vouchersPage";
|
||||
|
||||
filterTests({ definedTags: ["all"] }, () => {
|
||||
describe("Vouchers discounts", () => {
|
||||
const startsWith = "CyVou-";
|
||||
const productPrice = 100;
|
||||
const shippingPrice = 100;
|
||||
|
||||
let defaultChannel;
|
||||
let createdChannel;
|
||||
let shippingMethod;
|
||||
let variants;
|
||||
let product;
|
||||
let address;
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||
deleteVouchersStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createProductWithShipping({ name, productPrice, shippingPrice })
|
||||
.then(
|
||||
({
|
||||
variantsList: variantsResp,
|
||||
defaultChannel: channel,
|
||||
shippingMethod: shippingMethodResp,
|
||||
address: addressResp,
|
||||
product: productResp
|
||||
}) => {
|
||||
variants = variantsResp;
|
||||
defaultChannel = channel;
|
||||
shippingMethod = shippingMethodResp;
|
||||
address = addressResp;
|
||||
product = productResp;
|
||||
createChannel({ name });
|
||||
}
|
||||
)
|
||||
.then(channel => {
|
||||
createdChannel = channel;
|
||||
});
|
||||
});
|
||||
|
||||
it("should create percentage voucher", () => {
|
||||
const voucherValue = 50;
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const expectedAmount =
|
||||
(productPrice * voucherValue) / 100 + shippingPrice;
|
||||
let checkout;
|
||||
|
||||
loginAndCreateCheckoutForVoucherWithDiscount(
|
||||
discountOptions.PERCENTAGE,
|
||||
voucherValue,
|
||||
voucherCode
|
||||
)
|
||||
.then(amount => {
|
||||
expect(amount).to.be.eq(expectedAmount);
|
||||
createCheckoutForCreatedVoucher(voucherCode);
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.addPromoCodeResp.checkout.totalPrice.gross.amount).to.eq(
|
||||
expectedAmount
|
||||
);
|
||||
checkout = resp.checkout;
|
||||
addPayment(checkout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(checkout.id);
|
||||
})
|
||||
.then(({ order }) => {
|
||||
expect(order.id).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
it("should create fixed price voucher", () => {
|
||||
const voucherValue = 50;
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const expectedAmount = productPrice + shippingPrice - voucherValue;
|
||||
let checkout;
|
||||
|
||||
loginAndCreateCheckoutForVoucherWithDiscount(
|
||||
discountOptions.FIXED,
|
||||
voucherValue,
|
||||
voucherCode
|
||||
)
|
||||
.then(amount => {
|
||||
expect(amount).to.be.eq(expectedAmount);
|
||||
createCheckoutForCreatedVoucher(voucherCode);
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.addPromoCodeResp.checkout.totalPrice.gross.amount).to.eq(
|
||||
expectedAmount
|
||||
);
|
||||
checkout = resp.checkout;
|
||||
addPayment(checkout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(checkout.id);
|
||||
})
|
||||
.then(({ order }) => {
|
||||
expect(order.id).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
it("should create free shipping voucher", () => {
|
||||
const voucherCode = `${startsWith}${faker.datatype.number()}`;
|
||||
const expectedAmount = productPrice;
|
||||
let checkout;
|
||||
|
||||
loginAndCreateCheckoutForVoucherWithDiscount(
|
||||
discountOptions.SHIPPING,
|
||||
null,
|
||||
voucherCode
|
||||
)
|
||||
.then(amount => {
|
||||
expect(amount).to.be.eq(expectedAmount);
|
||||
createCheckoutForCreatedVoucher(voucherCode);
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.addPromoCodeResp.checkout.totalPrice.gross.amount).to.eq(
|
||||
expectedAmount
|
||||
);
|
||||
checkout = resp.checkout;
|
||||
addPayment(checkout.id);
|
||||
})
|
||||
.then(() => {
|
||||
completeCheckout(checkout.id);
|
||||
})
|
||||
.then(({ order }) => {
|
||||
expect(order.id).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
it("should create voucher not available for selected channel", () => {
|
||||
const randomName = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest()
|
||||
.visit(urlList.vouchers);
|
||||
cy.softExpectSkeletonIsVisible();
|
||||
createVoucher({
|
||||
voucherCode: randomName,
|
||||
voucherValue,
|
||||
discountOption: discountOptions.PERCENTAGE,
|
||||
channelName: createdChannel.name
|
||||
});
|
||||
createCheckoutForCreatedVoucher(randomName).then(
|
||||
({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.checkoutErrors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("should delete voucher", () => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
|
||||
let voucher;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
name,
|
||||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucher = voucherResp;
|
||||
expect(voucher.id).to.be.ok;
|
||||
cy.visit(voucherDetailsUrl(voucher.id))
|
||||
.addAliasToGraphRequest("VoucherDelete")
|
||||
.get(BUTTON_SELECTORS.deleteButton)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.submit)
|
||||
.click()
|
||||
.wait("@VoucherDelete");
|
||||
createCheckoutForCreatedVoucher(voucher.code);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.checkoutErrors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
});
|
||||
});
|
||||
|
||||
function createCheckoutForCreatedVoucher(voucherCode) {
|
||||
return createCheckoutWithVoucher({
|
||||
channelSlug: defaultChannel.slug,
|
||||
variantsList: variants,
|
||||
address,
|
||||
shippingMethodName: shippingMethod.name,
|
||||
voucherCode,
|
||||
auth: "token"
|
||||
});
|
||||
}
|
||||
|
||||
function loginAndCreateCheckoutForVoucherWithDiscount(
|
||||
discount,
|
||||
voucherValue,
|
||||
voucherCode
|
||||
) {
|
||||
cy.clearSessionData()
|
||||
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
|
||||
.visit(urlList.vouchers);
|
||||
cy.softExpectSkeletonIsVisible();
|
||||
createVoucher({
|
||||
voucherCode,
|
||||
voucherValue,
|
||||
discountOption: discount,
|
||||
channelName: defaultChannel.name
|
||||
});
|
||||
return createCheckoutForCreatedVoucher(voucherCode).its(
|
||||
"addPromoCodeResp.checkout.totalPrice.gross.amount"
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
// / <reference types="cypress"/>
|
||||
// / <reference types="../../../support"/>
|
||||
/// <reference types="cypress"/>
|
||||
/// <reference types="../../../support"/>
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
|
|
256
cypress/integration/discounts/vouchers/updateVouchers.js
Normal file
256
cypress/integration/discounts/vouchers/updateVouchers.js
Normal file
|
@ -0,0 +1,256 @@
|
|||
/// <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";
|
||||
import {
|
||||
createVoucherInChannel,
|
||||
deleteVouchersStartsWith
|
||||
} from "../../../support/api/utils/discounts/vouchersUtils";
|
||||
import { createCheckoutWithVoucher } from "../../../support/api/utils/ordersUtils";
|
||||
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
|
||||
import filterTests from "../../../support/filterTests";
|
||||
import { formatDate, formatTime } from "../../../support/formatData/formatDate";
|
||||
import { setVoucherDate } from "../../../support/pages/discounts/vouchersPage";
|
||||
|
||||
filterTests({ definedTags: ["all"] }, () => {
|
||||
describe("As an admin I want to update vouchers", () => {
|
||||
const startsWith = "CyVou-";
|
||||
const productPrice = 100;
|
||||
const shippingPrice = 100;
|
||||
|
||||
let defaultChannel;
|
||||
let product;
|
||||
let dataForCheckout;
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteVouchersStartsWith(startsWith);
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createProductWithShipping({ name, productPrice, shippingPrice })
|
||||
.then(
|
||||
({
|
||||
variantsList: variantsResp,
|
||||
defaultChannel: channel,
|
||||
shippingMethod: shippingMethodResp,
|
||||
address: addressResp,
|
||||
product: productResp
|
||||
}) => {
|
||||
defaultChannel = channel;
|
||||
product = productResp;
|
||||
|
||||
dataForCheckout = {
|
||||
channelSlug: defaultChannel.slug,
|
||||
variantsList: variantsResp,
|
||||
address: addressResp,
|
||||
shippingMethodName: shippingMethodResp.name,
|
||||
auth: "token"
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("should delete voucher. TC: SALEOR_1905", () => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
|
||||
let voucher;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
name,
|
||||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucher = voucherResp;
|
||||
expect(voucher.id).to.be.ok;
|
||||
cy.visit(voucherDetailsUrl(voucher.id))
|
||||
.addAliasToGraphRequest("VoucherDelete")
|
||||
.get(BUTTON_SELECTORS.deleteButton)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.submit)
|
||||
.click()
|
||||
.wait("@VoucherDelete");
|
||||
dataForCheckout.voucherCode = voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
});
|
||||
});
|
||||
|
||||
it("should update voucher. TC: SALEOR_1906", () => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
const voucherUpdatedValue = 20;
|
||||
const expectedOrderAmount =
|
||||
productPrice +
|
||||
shippingPrice -
|
||||
(productPrice * voucherUpdatedValue) / 100;
|
||||
|
||||
let voucher;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
name,
|
||||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucher = voucherResp;
|
||||
expect(voucher.id).to.be.ok;
|
||||
cy.visit(voucherDetailsUrl(voucher.id))
|
||||
.addAliasToGraphRequest("VoucherUpdate")
|
||||
.get(VOUCHERS_SELECTORS.percentageDiscountRadioButton)
|
||||
.click()
|
||||
.get(VOUCHERS_SELECTORS.discountValueInputs)
|
||||
.clearAndType(voucherUpdatedValue)
|
||||
.get(BUTTON_SELECTORS.confirm)
|
||||
.click()
|
||||
.wait("@VoucherUpdate");
|
||||
dataForCheckout.voucherCode = voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const amount = addPromoCodeResp.checkout.totalPrice.gross.amount;
|
||||
expect(amount).to.be.eq(expectedOrderAmount);
|
||||
});
|
||||
});
|
||||
|
||||
it("should set date on voucher. TC: SALEOR_1912", () => {
|
||||
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 voucher;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
name,
|
||||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucher = voucherResp;
|
||||
expect(voucher.id).to.be.ok;
|
||||
setVoucherDate({ voucherId: voucher.id, startDate: tomorrowDate });
|
||||
dataForCheckout.voucherCode = voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
setVoucherDate({ voucherId: voucher.id, startDate: todayDate });
|
||||
dataForCheckout.voucherCode = voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
});
|
||||
});
|
||||
|
||||
it("should set end date on voucher. TC: SALEOR_1913", () => {
|
||||
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 voucher;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
name,
|
||||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucher = voucherResp;
|
||||
expect(voucher.id).to.be.ok;
|
||||
setVoucherDate({
|
||||
voucherId: voucher.id,
|
||||
endDate: todayDate,
|
||||
endTime: formatTime(today),
|
||||
hasEndDate: true
|
||||
});
|
||||
dataForCheckout.voucherCode = voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
setVoucherDate({
|
||||
voucherId: voucher.id,
|
||||
endDate: tomorrowDate,
|
||||
endTime: formatTime(tomorrow)
|
||||
});
|
||||
dataForCheckout.voucherCode = voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
});
|
||||
});
|
||||
|
||||
it("should set country on voucher. TC: SALEOR_1914", () => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
|
||||
let voucher;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
name,
|
||||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue,
|
||||
type: "SHIPPING",
|
||||
country: "US"
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucher = voucherResp;
|
||||
expect(voucher.id).to.be.ok;
|
||||
dataForCheckout.voucherCode = voucher.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
expect(addPromoCodeResp.errors).to.be.empty;
|
||||
cy.visit(voucherDetailsUrl(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()
|
||||
.assignElements("Poland", false)
|
||||
.addAliasToGraphRequest("VoucherUpdate")
|
||||
.get(BUTTON_SELECTORS.confirm)
|
||||
.click()
|
||||
.wait("@VoucherUpdate");
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,101 +0,0 @@
|
|||
// / <reference types="cypress"/>
|
||||
// / <reference types="../../../support"/>
|
||||
|
||||
import faker from "faker";
|
||||
|
||||
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
||||
import { voucherDetailsUrl } from "../../../fixtures/urlList";
|
||||
import { createChannel } from "../../../support/api/requests/Channels";
|
||||
import * as channelsUtils from "../../../support/api/utils/channelsUtils";
|
||||
import {
|
||||
createVoucherInChannel,
|
||||
deleteVouchersStartsWith
|
||||
} from "../../../support/api/utils/discounts/vouchersUtils";
|
||||
import { createCheckoutWithVoucher } from "../../../support/api/utils/ordersUtils";
|
||||
import * as productsUtils from "../../../support/api/utils/products/productsUtils";
|
||||
import filterTests from "../../../support/filterTests";
|
||||
|
||||
filterTests({ definedTags: ["all"] }, () => {
|
||||
describe("Vouchers discounts", () => {
|
||||
const startsWith = "CyVou-";
|
||||
const productPrice = 100;
|
||||
const shippingPrice = 100;
|
||||
|
||||
let defaultChannel;
|
||||
let createdChannel;
|
||||
let shippingMethod;
|
||||
let variants;
|
||||
let product;
|
||||
let address;
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||
deleteVouchersStartsWith(startsWith);
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createProductWithShipping({ name, productPrice, shippingPrice })
|
||||
.then(
|
||||
({
|
||||
variantsList: variantsResp,
|
||||
defaultChannel: channel,
|
||||
shippingMethod: shippingMethodResp,
|
||||
address: addressResp,
|
||||
product: productResp
|
||||
}) => {
|
||||
variants = variantsResp;
|
||||
defaultChannel = channel;
|
||||
shippingMethod = shippingMethodResp;
|
||||
address = addressResp;
|
||||
product = productResp;
|
||||
createChannel({ name });
|
||||
}
|
||||
)
|
||||
.then(channel => {
|
||||
createdChannel = channel;
|
||||
});
|
||||
});
|
||||
|
||||
it("should delete voucher", () => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
const voucherValue = 50;
|
||||
|
||||
let voucher;
|
||||
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
createVoucherInChannel({
|
||||
name,
|
||||
productId: product.id,
|
||||
channelId: defaultChannel.id,
|
||||
value: voucherValue
|
||||
})
|
||||
.then(voucherResp => {
|
||||
voucher = voucherResp;
|
||||
expect(voucher.id).to.be.ok;
|
||||
cy.visit(voucherDetailsUrl(voucher.id))
|
||||
.addAliasToGraphRequest("VoucherDelete")
|
||||
.get(BUTTON_SELECTORS.deleteButton)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.submit)
|
||||
.click()
|
||||
.wait("@VoucherDelete");
|
||||
createCheckoutForCreatedVoucher(voucher.code);
|
||||
})
|
||||
.then(({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.errors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
});
|
||||
});
|
||||
|
||||
function createCheckoutForCreatedVoucher(voucherCode) {
|
||||
return createCheckoutWithVoucher({
|
||||
channelSlug: defaultChannel.slug,
|
||||
variantsList: variants,
|
||||
address,
|
||||
shippingMethodName: shippingMethod.name,
|
||||
voucherCode,
|
||||
auth: "token"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,3 +1,5 @@
|
|||
import { getValueWithDefault } from "../utils/Utils";
|
||||
|
||||
export function getVouchers(first, startsWith) {
|
||||
const query = `query getVouchers{
|
||||
vouchers(first:${first}, filter:{
|
||||
|
@ -28,9 +30,14 @@ export function deleteVouchers(voucherId) {
|
|||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function createVoucher({ name, productId, code = name }) {
|
||||
export function createVoucher({ name, productId, code = name, type, country }) {
|
||||
const discountTypeLines = getValueWithDefault(type, `type:${type}`);
|
||||
const countryLine = getValueWithDefault(country, `countries:["${country}"]`);
|
||||
|
||||
const mutation = `mutation{
|
||||
voucherCreate(input:{
|
||||
${discountTypeLines}
|
||||
${countryLine}
|
||||
name:"${name}",
|
||||
code:"${code}"
|
||||
products:["${productId}"]
|
||||
|
|
|
@ -63,7 +63,7 @@ export function createCheckoutWithDisabledGiftCard({
|
|||
voucherCode,
|
||||
auth
|
||||
}).then(({ addPromoCodeResp, checkout }) => {
|
||||
expect(addPromoCodeResp.checkoutErrors[0].field).to.eq("promoCode");
|
||||
expect(addPromoCodeResp.errors[0].field).to.eq("promoCode");
|
||||
return checkout;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,10 +14,12 @@ export function createVoucherInChannel({
|
|||
productId,
|
||||
channelId,
|
||||
value,
|
||||
code = name
|
||||
code = name,
|
||||
type,
|
||||
country
|
||||
}) {
|
||||
let voucher;
|
||||
return createVoucher({ name, productId, code })
|
||||
return createVoucher({ name, productId, code, type, country })
|
||||
.then(({ voucher: voucherResp }) => {
|
||||
voucher = voucherResp;
|
||||
addChannelToVoucher(voucher.id, channelId, value);
|
||||
|
|
|
@ -12,9 +12,9 @@ function getPeriodValue(date, option) {
|
|||
}
|
||||
|
||||
export function formatTime(date) {
|
||||
const formatter = new Intl.DateTimeFormat(["pl-Pl"], {
|
||||
hour: "numeric",
|
||||
minute: "numeric"
|
||||
});
|
||||
return formatter.format(date);
|
||||
const hour = getPeriodValue(date, { hour: "2-digit", hour12: false });
|
||||
const minute = getPeriodValue(date, { minute: "2-digit" });
|
||||
const formattedMinute = minute.length === 1 ? `0${minute}` : minute;
|
||||
|
||||
return new Array(hour, formattedMinute).join(":");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { VOUCHERS_SELECTORS } from "../../../elements/discounts/vouchers";
|
||||
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
||||
import { voucherDetailsUrl } from "../../../fixtures/urlList";
|
||||
import { urlList } from "../../../fixtures/urlList";
|
||||
import { ONE_PERMISSION_USERS } from "../../../fixtures/users";
|
||||
import { createCheckoutWithVoucher } from "../../api/utils/ordersUtils";
|
||||
|
@ -59,6 +60,32 @@ export function createVoucher({
|
|||
.confirmationMessageShouldDisappear();
|
||||
}
|
||||
|
||||
export function setVoucherDate({
|
||||
voucherId,
|
||||
startDate,
|
||||
endDate,
|
||||
endTime,
|
||||
hasEndDate = false
|
||||
}) {
|
||||
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");
|
||||
}
|
||||
|
||||
export function loginAndCreateCheckoutForVoucherWithDiscount({
|
||||
discount,
|
||||
voucherValue,
|
||||
|
|
|
@ -122,6 +122,7 @@ const CountryList: React.FC<CountryListProps> = props => {
|
|||
>
|
||||
<IconButton variant="secondary">
|
||||
<ArrowDropDownIcon
|
||||
data-test-id="countries-drop-down-icon"
|
||||
className={classNames({
|
||||
[classes.rotate]: !isCollapsed
|
||||
})}
|
||||
|
@ -155,6 +156,7 @@ const CountryList: React.FC<CountryListProps> = props => {
|
|||
className={classNames(classes.textRight, classes.iconCell)}
|
||||
>
|
||||
<IconButton
|
||||
data-test-id="delete-icon"
|
||||
color="primary"
|
||||
disabled={!country || disabled}
|
||||
onClick={() => onCountryUnassign(country.code)}
|
||||
|
|
|
@ -227090,6 +227090,7 @@ exports[`Storyshots Views / Shipping / Create shipping zone default 1`] = `
|
|||
<svg
|
||||
aria-hidden="true"
|
||||
class="MuiSvgIcon-root-id"
|
||||
data-test-id="countries-drop-down-icon"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
|
@ -227320,6 +227321,7 @@ exports[`Storyshots Views / Shipping / Create shipping zone form errors 1`] = `
|
|||
<svg
|
||||
aria-hidden="true"
|
||||
class="MuiSvgIcon-root-id"
|
||||
data-test-id="countries-drop-down-icon"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
|
@ -227548,6 +227550,7 @@ exports[`Storyshots Views / Shipping / Create shipping zone loading 1`] = `
|
|||
<svg
|
||||
aria-hidden="true"
|
||||
class="MuiSvgIcon-root-id"
|
||||
data-test-id="countries-drop-down-icon"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
|
@ -233710,6 +233713,7 @@ exports[`Storyshots Views / Shipping / Shipping zone details default 1`] = `
|
|||
<svg
|
||||
aria-hidden="true"
|
||||
class="MuiSvgIcon-root-id"
|
||||
data-test-id="countries-drop-down-icon"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
|
@ -234814,6 +234818,7 @@ exports[`Storyshots Views / Shipping / Shipping zone details form errors 1`] = `
|
|||
<svg
|
||||
aria-hidden="true"
|
||||
class="MuiSvgIcon-root-id"
|
||||
data-test-id="countries-drop-down-icon"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
|
@ -235914,6 +235919,7 @@ exports[`Storyshots Views / Shipping / Shipping zone details loading 1`] = `
|
|||
<svg
|
||||
aria-hidden="true"
|
||||
class="MuiSvgIcon-root-id"
|
||||
data-test-id="countries-drop-down-icon"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue