Saleor 1746 tests for vouchers (#1014)
* tests for vouchers * test for vouchers * test for vouchers * add getDefaultAddress
This commit is contained in:
parent
78ba9f4fe9
commit
0da6012bc4
26 changed files with 400 additions and 82 deletions
|
@ -1,18 +1,24 @@
|
||||||
export function createCheckout(
|
import { getDefaultAddress } from "./utils/Utils";
|
||||||
|
export function createCheckout({
|
||||||
channelSlug,
|
channelSlug,
|
||||||
email,
|
email,
|
||||||
productQuantity,
|
productQuantity = 1,
|
||||||
variantsList
|
variantsList,
|
||||||
) {
|
address,
|
||||||
|
auth = "auth"
|
||||||
|
}) {
|
||||||
const lines = variantsList.map(
|
const lines = variantsList.map(
|
||||||
variant => `{quantity:${productQuantity}
|
variant => `{quantity:${productQuantity}
|
||||||
variantId:"${variant.id}"}`
|
variantId:"${variant.id}"}`
|
||||||
);
|
);
|
||||||
|
const shippingAddress = getDefaultAddress(address, "shippingAddress");
|
||||||
|
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
checkoutCreate(input:{
|
checkoutCreate(input:{
|
||||||
channel:"${channelSlug}"
|
channel:"${channelSlug}"
|
||||||
email:"${email}"
|
email:"${email}"
|
||||||
lines: [${lines.join()}]
|
lines: [${lines.join()}]
|
||||||
|
${shippingAddress}
|
||||||
}){
|
}){
|
||||||
checkoutErrors{
|
checkoutErrors{
|
||||||
field
|
field
|
||||||
|
@ -24,7 +30,7 @@ export function createCheckout(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation, auth);
|
||||||
}
|
}
|
||||||
export function addShippingMethod(checkoutId, shippingMethodId) {
|
export function addShippingMethod(checkoutId, shippingMethodId) {
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
|
@ -69,3 +75,24 @@ export function completeCheckout(checkoutId) {
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(mutation);
|
return cy.sendRequestWithQuery(mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function addVoucher(checkoutId, voucherCode) {
|
||||||
|
const mutation = `mutation addVoucher{
|
||||||
|
checkoutAddPromoCode(checkoutId:"${checkoutId}",
|
||||||
|
promoCode:"${voucherCode}"
|
||||||
|
){
|
||||||
|
checkoutErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
checkout{
|
||||||
|
totalPrice{
|
||||||
|
gross{
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { getDefaultAddress } from "./utils/Utils";
|
||||||
export function createCustomer(email, customerName, address, isActive = false) {
|
export function createCustomer(email, customerName, address, isActive = false) {
|
||||||
const mutation = `
|
const mutation = `
|
||||||
mutation{
|
mutation{
|
||||||
|
@ -6,24 +7,8 @@ export function createCustomer(email, customerName, address, isActive = false) {
|
||||||
lastName: "${customerName}"
|
lastName: "${customerName}"
|
||||||
email: "${email}"
|
email: "${email}"
|
||||||
isActive: ${isActive}
|
isActive: ${isActive}
|
||||||
defaultBillingAddress: {
|
${getDefaultAddress(address, "defaultBillingAddress")}
|
||||||
companyName: "${address.companyName}"
|
${getDefaultAddress(address, "defaultShippingAddress")}
|
||||||
streetAddress1: "${address.streetAddress1}"
|
|
||||||
streetAddress2: "${address.streetAddress2}"
|
|
||||||
city: "${address.city}"
|
|
||||||
postalCode: "${address.postalCode}"
|
|
||||||
country: ${address.country}
|
|
||||||
phone: "${address.phone}"
|
|
||||||
}
|
|
||||||
defaultShippingAddress: {
|
|
||||||
companyName: "${address.companyName}"
|
|
||||||
streetAddress1: "${address.streetAddress1}"
|
|
||||||
streetAddress2: "${address.streetAddress2}"
|
|
||||||
city: "${address.city}"
|
|
||||||
postalCode: "${address.postalCode}"
|
|
||||||
country: ${address.country}
|
|
||||||
phone: "${address.phone}"
|
|
||||||
}
|
|
||||||
}){
|
}){
|
||||||
user{
|
user{
|
||||||
id
|
id
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { getValueWithDefault } from "./utils/Utils";
|
import { getValueWithDefault } from "../utils/Utils";
|
||||||
|
|
||||||
export function getSales(first, searchQuery) {
|
export function getSales(first, searchQuery) {
|
||||||
const filter = getValueWithDefault(
|
const filter = getValueWithDefault(
|
28
cypress/apiRequests/Discounts/Vouchers.js
Normal file
28
cypress/apiRequests/Discounts/Vouchers.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
export function getVouchers(first, startsWith) {
|
||||||
|
const query = `query getVouchers{
|
||||||
|
vouchers(first:${first}, filter:{
|
||||||
|
search:"${startsWith}"
|
||||||
|
}){
|
||||||
|
edges{
|
||||||
|
node{
|
||||||
|
id
|
||||||
|
code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy
|
||||||
|
.sendRequestWithQuery(query)
|
||||||
|
.then(resp => resp.body.data.vouchers.edges);
|
||||||
|
}
|
||||||
|
export function deleteVouchers(voucherId) {
|
||||||
|
const mutation = `mutation deleteVouchers{
|
||||||
|
voucherDelete(id:"${voucherId}"){
|
||||||
|
discountErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(mutation);
|
||||||
|
}
|
|
@ -1,17 +1,12 @@
|
||||||
|
import { getDefaultAddress } from "./utils/Utils";
|
||||||
|
|
||||||
export function createWarehouse(name, shippingZone, address, slug = name) {
|
export function createWarehouse(name, shippingZone, address, slug = name) {
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
createWarehouse(input:{
|
createWarehouse(input:{
|
||||||
name:"${name}"
|
name:"${name}"
|
||||||
slug:"${slug}"
|
slug:"${slug}"
|
||||||
shippingZones:"${shippingZone}"
|
shippingZones:"${shippingZone}"
|
||||||
address:{
|
${getDefaultAddress(address, "address", false)}
|
||||||
streetAddress1: "${address.streetAddress1}"
|
|
||||||
streetAddress2: "${address.streetAddress2}"
|
|
||||||
city: "${address.city}"
|
|
||||||
postalCode: "${address.postalCode}"
|
|
||||||
country: ${address.country}
|
|
||||||
phone: "${address.phone}"
|
|
||||||
}
|
|
||||||
}){
|
}){
|
||||||
warehouseErrors{
|
warehouseErrors{
|
||||||
field
|
field
|
||||||
|
|
|
@ -1,2 +1,21 @@
|
||||||
export const getValueWithDefault = (condition, value, defaultValue = "") =>
|
export const getValueWithDefault = (condition, value, defaultValue = "") =>
|
||||||
condition ? value : defaultValue;
|
condition ? value : defaultValue;
|
||||||
|
|
||||||
|
export function getDefaultAddress(address, addressType, withName = true) {
|
||||||
|
if (!address) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const defaultAddress = `city: "${address.city}"
|
||||||
|
country: ${address.country}
|
||||||
|
countryArea: "${address.countryArea}"
|
||||||
|
phone: "${address.phone}"
|
||||||
|
postalCode: "${address.postalCode}"
|
||||||
|
streetAddress1: "${address.streetAddress1}"
|
||||||
|
streetAddress2: "${address.streetAddress2}"`;
|
||||||
|
if (withName) {
|
||||||
|
defaultAddress.concat(`firstName: "Test"
|
||||||
|
lastName: "Test"
|
||||||
|
companyName: "${address.companyName}"`);
|
||||||
|
}
|
||||||
|
return `${addressType}:{${defaultAddress}}`;
|
||||||
|
}
|
||||||
|
|
|
@ -12,5 +12,6 @@ export const MENAGE_CHANNEL_AVAILABILITY = {
|
||||||
radioButtonsValueTrue: "[value='true']",
|
radioButtonsValueTrue: "[value='true']",
|
||||||
radioButtonsValueFalse: "[value='false']",
|
radioButtonsValueFalse: "[value='false']",
|
||||||
visibleInListingsButton: "[name*='visibleInListings']",
|
visibleInListingsButton: "[name*='visibleInListings']",
|
||||||
allChannelsInput: "[name='allChannels']"
|
allChannelsInput: "[name='allChannels']",
|
||||||
|
dialog: "[role='dialog']"
|
||||||
};
|
};
|
||||||
|
|
9
cypress/elements/discounts/vouchers.js
Normal file
9
cypress/elements/discounts/vouchers.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export const VOUCHERS_SELECTORS = {
|
||||||
|
createVoucherButton: "[data-test-id='create-voucher']",
|
||||||
|
voucherCodeInput: "[name='code']",
|
||||||
|
discountRadioButtons: "[name='discountType']",
|
||||||
|
percentageDiscountRadioButton: "[name='discountType'][value='PERCENTAGE']",
|
||||||
|
fixedDiscountRadioButton: "[name='discountType'][value='FIXED']",
|
||||||
|
shippingDiscountRadioButton: "[name='discountType'][value='SHIPPING']",
|
||||||
|
discountValueInputs: "[name='value']"
|
||||||
|
};
|
|
@ -1,5 +1,6 @@
|
||||||
export const BUTTON_SELECTORS = {
|
export const BUTTON_SELECTORS = {
|
||||||
back: '[data-test="back"]',
|
back: '[data-test="back"]',
|
||||||
submit: '[data-test="submit"]',
|
submit: '[data-test="submit"]',
|
||||||
|
confirm: '[data-test="button-bar-confirm"]',
|
||||||
checkbox: "[type='checkbox']"
|
checkbox: "[type='checkbox']"
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,11 +7,11 @@ import {
|
||||||
assignProducts,
|
assignProducts,
|
||||||
createSale,
|
createSale,
|
||||||
discountOptions
|
discountOptions
|
||||||
} from "../../steps/salesSteps";
|
} from "../../steps/discounts/salesSteps";
|
||||||
import { urlList } from "../../url/urlList";
|
import { urlList } from "../../url/urlList";
|
||||||
import * as channelsUtils from "../../utils/channelsUtils";
|
import * as channelsUtils from "../../utils/channelsUtils";
|
||||||
|
import { deleteSalesStartsWith } from "../../utils/discounts/salesUtils";
|
||||||
import * as productsUtils from "../../utils/productsUtils";
|
import * as productsUtils from "../../utils/productsUtils";
|
||||||
import { deleteSalesStartsWith } from "../../utils/salesUtils";
|
|
||||||
import {
|
import {
|
||||||
createShipping,
|
createShipping,
|
||||||
deleteShippingStartsWith
|
deleteShippingStartsWith
|
||||||
|
|
172
cypress/integration/discounts/vouchers.js
Normal file
172
cypress/integration/discounts/vouchers.js
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
// <reference types="cypress" />
|
||||||
|
import faker from "faker";
|
||||||
|
|
||||||
|
import {
|
||||||
|
createVoucher,
|
||||||
|
discountOptions
|
||||||
|
} from "../../steps/discounts/vouchersSteps";
|
||||||
|
import { urlList } from "../../url/urlList";
|
||||||
|
import * as channelsUtils from "../../utils/channelsUtils";
|
||||||
|
import { deleteVouchersStartsWith } from "../../utils/discounts/vouchersUtils";
|
||||||
|
import { createCheckoutWithVoucher } from "../../utils/ordersUtils";
|
||||||
|
import * as productsUtils from "../../utils/productsUtils";
|
||||||
|
import {
|
||||||
|
createShipping,
|
||||||
|
deleteShippingStartsWith
|
||||||
|
} from "../../utils/shippingUtils";
|
||||||
|
|
||||||
|
describe("Vouchers discounts", () => {
|
||||||
|
const startsWith = "Cy-";
|
||||||
|
const productPrice = 100;
|
||||||
|
const shippingPrice = 100;
|
||||||
|
|
||||||
|
let defaultChannel;
|
||||||
|
let productType;
|
||||||
|
let attribute;
|
||||||
|
let category;
|
||||||
|
let shippingMethod;
|
||||||
|
let variants;
|
||||||
|
let address;
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||||
|
productsUtils.deleteProductsStartsWith(startsWith);
|
||||||
|
deleteShippingStartsWith(startsWith);
|
||||||
|
deleteVouchersStartsWith(startsWith);
|
||||||
|
|
||||||
|
const name = `${startsWith}${faker.random.number()}`;
|
||||||
|
|
||||||
|
productsUtils
|
||||||
|
.createTypeAttributeAndCategoryForProduct(name)
|
||||||
|
.then(
|
||||||
|
({
|
||||||
|
productType: productTypeResp,
|
||||||
|
attribute: attributeResp,
|
||||||
|
category: categoryResp
|
||||||
|
}) => {
|
||||||
|
productType = productTypeResp;
|
||||||
|
attribute = attributeResp;
|
||||||
|
category = categoryResp;
|
||||||
|
|
||||||
|
channelsUtils.getDefaultChannel();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(channel => {
|
||||||
|
defaultChannel = channel;
|
||||||
|
cy.fixture("addresses");
|
||||||
|
})
|
||||||
|
.then(addresses => {
|
||||||
|
address = addresses.plAddress;
|
||||||
|
createShipping({
|
||||||
|
channelId: defaultChannel.id,
|
||||||
|
name,
|
||||||
|
address,
|
||||||
|
price: shippingPrice
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(({ shippingMethod: shippingMethodResp, warehouse: warehouse }) => {
|
||||||
|
shippingMethod = shippingMethodResp;
|
||||||
|
productsUtils.createProductInChannel({
|
||||||
|
name,
|
||||||
|
channelId: defaultChannel.id,
|
||||||
|
warehouseId: warehouse.id,
|
||||||
|
productTypeId: productType.id,
|
||||||
|
attributeId: attribute.id,
|
||||||
|
categoryId: category.id,
|
||||||
|
price: productPrice
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(({ variants: variantsResp }) => (variants = variantsResp));
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
cy.visit(urlList.vouchers);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create percentage voucher", () => {
|
||||||
|
const voucherCode = `${startsWith}${faker.random.number()}`;
|
||||||
|
const voucherValue = 50;
|
||||||
|
|
||||||
|
createVoucher({
|
||||||
|
voucherCode,
|
||||||
|
voucherValue,
|
||||||
|
discountOption: discountOptions.PERCENTAGE,
|
||||||
|
channelName: defaultChannel.name
|
||||||
|
});
|
||||||
|
createCheckoutForCreatedVoucher(voucherCode)
|
||||||
|
.its("checkout.totalPrice.gross.amount")
|
||||||
|
.then(amount => {
|
||||||
|
const expectedAmount =
|
||||||
|
(productPrice * voucherValue) / 100 + shippingPrice;
|
||||||
|
expect(amount).to.be.eq(expectedAmount);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should create fixed price voucher", () => {
|
||||||
|
const voucherCode = `${startsWith}${faker.random.number()}`;
|
||||||
|
const voucherValue = 50;
|
||||||
|
|
||||||
|
createVoucher({
|
||||||
|
voucherCode,
|
||||||
|
voucherValue,
|
||||||
|
discountOption: discountOptions.FIXED,
|
||||||
|
channelName: defaultChannel.name
|
||||||
|
});
|
||||||
|
createCheckoutForCreatedVoucher(voucherCode)
|
||||||
|
.its("checkout.totalPrice.gross.amount")
|
||||||
|
.then(amount => {
|
||||||
|
const expectedAmount = productPrice + shippingPrice - voucherValue;
|
||||||
|
expect(amount).to.be.eq(expectedAmount);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test should pass after fixing - SALEOR-1629 bug
|
||||||
|
xit("should create free shipping voucher", () => {
|
||||||
|
const voucherCode = `${startsWith}${faker.random.number()}`;
|
||||||
|
|
||||||
|
createVoucher({
|
||||||
|
voucherCode,
|
||||||
|
discountOption: discountOptions.SHIPPING,
|
||||||
|
channelName: defaultChannel.name
|
||||||
|
});
|
||||||
|
createCheckoutForCreatedVoucher(voucherCode)
|
||||||
|
.its("checkout.totalPrice.gross.amount")
|
||||||
|
.then(amount => {
|
||||||
|
const expectedAmount = productPrice;
|
||||||
|
expect(amount).to.be.eq(expectedAmount);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create voucher not available for selected channel", () => {
|
||||||
|
const randomName = `${startsWith}${faker.random.number()}`;
|
||||||
|
const voucherValue = 50;
|
||||||
|
|
||||||
|
channelsUtils
|
||||||
|
.createChannel({ name: randomName })
|
||||||
|
.then(channel => {
|
||||||
|
createVoucher({
|
||||||
|
voucherCode: randomName,
|
||||||
|
voucherValue,
|
||||||
|
discountOption: discountOptions.PERCENTAGE,
|
||||||
|
channelName: channel.name
|
||||||
|
});
|
||||||
|
createCheckoutForCreatedVoucher(randomName);
|
||||||
|
})
|
||||||
|
.then(resp => {
|
||||||
|
const errorField = resp.checkoutErrors[0].field;
|
||||||
|
expect(errorField).to.be.eq("promoCode");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function createCheckoutForCreatedVoucher(voucherCode) {
|
||||||
|
return createCheckoutWithVoucher({
|
||||||
|
channelSlug: defaultChannel.slug,
|
||||||
|
variantsList: variants,
|
||||||
|
address,
|
||||||
|
shippingMethodId: shippingMethod.id,
|
||||||
|
voucherCode,
|
||||||
|
auth: "token"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
|
@ -1,7 +1,9 @@
|
||||||
import { ADD_CHANNEL_FORM_SELECTORS } from "../elements/channels/add-channel-form-selectors";
|
import { ADD_CHANNEL_FORM_SELECTORS } from "../elements/channels/add-channel-form-selectors";
|
||||||
import { CHANNEL_FORM_SELECTORS } from "../elements/channels/channel-form-selectors";
|
import { CHANNEL_FORM_SELECTORS } from "../elements/channels/channel-form-selectors";
|
||||||
import { CHANNELS_SELECTORS } from "../elements/channels/channels-selectors";
|
import { CHANNELS_SELECTORS } from "../elements/channels/channels-selectors";
|
||||||
|
import { MENAGE_CHANNEL_AVAILABILITY } from "../elements/channels/menage-channel-availability";
|
||||||
import { HEADER_SELECTORS } from "../elements/header/header-selectors";
|
import { HEADER_SELECTORS } from "../elements/header/header-selectors";
|
||||||
|
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
|
||||||
|
|
||||||
export function createChannelByView(name, currency, slug = name) {
|
export function createChannelByView(name, currency, slug = name) {
|
||||||
cy.get(CHANNELS_SELECTORS.createChannelButton)
|
cy.get(CHANNELS_SELECTORS.createChannelButton)
|
||||||
|
@ -36,3 +38,15 @@ export function selectChannelInHeader(channelName) {
|
||||||
.contains(channelName)
|
.contains(channelName)
|
||||||
.click();
|
.click();
|
||||||
}
|
}
|
||||||
|
export function selectChannelInDetailsPages(channelName) {
|
||||||
|
cy.get(MENAGE_CHANNEL_AVAILABILITY.availableManageButton)
|
||||||
|
.click()
|
||||||
|
.get(MENAGE_CHANNEL_AVAILABILITY.allChannelsInput)
|
||||||
|
.click()
|
||||||
|
.get(MENAGE_CHANNEL_AVAILABILITY.channelsAvailabilityForm)
|
||||||
|
.contains(channelName)
|
||||||
|
.click()
|
||||||
|
.get(MENAGE_CHANNEL_AVAILABILITY.dialog)
|
||||||
|
.find(BUTTON_SELECTORS.submit)
|
||||||
|
.click();
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/assign-products";
|
import { ASSIGN_PRODUCTS_SELECTORS } from "../../elements/catalog/assign-products";
|
||||||
import { MENAGE_CHANNEL_AVAILABILITY } from "../elements/channels/menage-channel-availability";
|
import { SALES_SELECTORS } from "../../elements/discounts/sales";
|
||||||
import { SALES_SELECTORS } from "../elements/discounts/sales";
|
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
||||||
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
|
import { formatDate } from "../../support/formatDate";
|
||||||
import { formatDate } from "../support/formatDate";
|
import { selectChannelInDetailsPages } from "../channelsSteps";
|
||||||
|
|
||||||
export const discountOptions = {
|
export const discountOptions = {
|
||||||
PERCENTAGE: SALES_SELECTORS.percentageOption,
|
PERCENTAGE: SALES_SELECTORS.percentageOption,
|
||||||
|
@ -22,17 +22,9 @@ export function createSale({
|
||||||
.get(SALES_SELECTORS.nameInput)
|
.get(SALES_SELECTORS.nameInput)
|
||||||
.type(saleName)
|
.type(saleName)
|
||||||
.get(discountOption)
|
.get(discountOption)
|
||||||
.click()
|
.click();
|
||||||
.get(MENAGE_CHANNEL_AVAILABILITY.availableManageButton)
|
selectChannelInDetailsPages(channelName);
|
||||||
.click()
|
cy.get(SALES_SELECTORS.discountValue)
|
||||||
.get(MENAGE_CHANNEL_AVAILABILITY.allChannelsInput)
|
|
||||||
.click()
|
|
||||||
.get(MENAGE_CHANNEL_AVAILABILITY.channelsAvailabilityForm)
|
|
||||||
.contains(channelName)
|
|
||||||
.click()
|
|
||||||
.get(BUTTON_SELECTORS.submit)
|
|
||||||
.click()
|
|
||||||
.get(SALES_SELECTORS.discountValue)
|
|
||||||
.type(discountValue)
|
.type(discountValue)
|
||||||
.get(SALES_SELECTORS.startDateInput)
|
.get(SALES_SELECTORS.startDateInput)
|
||||||
.type(todaysDate);
|
.type(todaysDate);
|
27
cypress/steps/discounts/vouchersSteps.js
Normal file
27
cypress/steps/discounts/vouchersSteps.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { VOUCHERS_SELECTORS } from "../../elements/discounts/vouchers";
|
||||||
|
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
||||||
|
import { selectChannelInDetailsPages } from "../channelsSteps";
|
||||||
|
|
||||||
|
export const discountOptions = {
|
||||||
|
PERCENTAGE: VOUCHERS_SELECTORS.percentageDiscountRadioButton,
|
||||||
|
FIXED: VOUCHERS_SELECTORS.fixedDiscountRadioButton,
|
||||||
|
SHIPPING: VOUCHERS_SELECTORS.shippingDiscountRadioButton
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createVoucher({
|
||||||
|
voucherCode,
|
||||||
|
voucherValue,
|
||||||
|
discountOption,
|
||||||
|
channelName
|
||||||
|
}) {
|
||||||
|
cy.get(VOUCHERS_SELECTORS.createVoucherButton).click();
|
||||||
|
selectChannelInDetailsPages(channelName);
|
||||||
|
cy.get(VOUCHERS_SELECTORS.voucherCodeInput)
|
||||||
|
.type(voucherCode)
|
||||||
|
.get(discountOption)
|
||||||
|
.click();
|
||||||
|
if (discountOption !== discountOptions.SHIPPING) {
|
||||||
|
cy.get(VOUCHERS_SELECTORS.discountValueInputs).type(voucherValue);
|
||||||
|
}
|
||||||
|
cy.get(BUTTON_SELECTORS.confirm).click();
|
||||||
|
}
|
|
@ -1,17 +1,17 @@
|
||||||
Cypress.Commands.add(
|
Cypress.Commands.add(
|
||||||
"handleDeleteElement",
|
"handleDeleteElement",
|
||||||
(element, deleteFunction, startsWith) => {
|
(element, deleteFunction, startsWith, name) => {
|
||||||
if (element.node.name.includes(startsWith)) {
|
if (element.node[name].includes(startsWith)) {
|
||||||
deleteFunction(element.node.id);
|
deleteFunction(element.node.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Cypress.Commands.add(
|
Cypress.Commands.add(
|
||||||
"deleteElementsStartsWith",
|
"deleteElementsStartsWith",
|
||||||
(deleteFunction, getFunction, startsWith, name) => {
|
(deleteFunction, getFunction, startsWith, name = "name") => {
|
||||||
getFunction(100, startsWith).then(elements => {
|
getFunction(100, startsWith).then(elements => {
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
cy.handleDeleteElement(element, deleteFunction, startsWith);
|
cy.handleDeleteElement(element, deleteFunction, startsWith, name);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ export const urlList = {
|
||||||
products: "products/",
|
products: "products/",
|
||||||
warehouses: "warehouses/",
|
warehouses: "warehouses/",
|
||||||
sales: "discounts/sales/",
|
sales: "discounts/sales/",
|
||||||
collections: "collections/"
|
collections: "collections/",
|
||||||
|
vouchers: "discounts/vouchers/"
|
||||||
};
|
};
|
||||||
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
|
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
import { deleteCollection, getCollections } from "../apiRequests/Collections";
|
import { deleteCollection, getCollections } from "../apiRequests/Collections";
|
||||||
|
|
||||||
export function deleteCollectionsStartsWith(startsWith) {
|
export function deleteCollectionsStartsWith(startsWith) {
|
||||||
cy.deleteElementsStartsWith(
|
cy.deleteElementsStartsWith(deleteCollection, getCollections, startsWith);
|
||||||
deleteCollection,
|
|
||||||
getCollections,
|
|
||||||
startsWith,
|
|
||||||
"collection"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
5
cypress/utils/discounts/salesUtils.js
Normal file
5
cypress/utils/discounts/salesUtils.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { deleteSale, getSales } from "../../apiRequests/Discounts/Sales";
|
||||||
|
|
||||||
|
export function deleteSalesStartsWith(startsWith) {
|
||||||
|
cy.deleteElementsStartsWith(deleteSale, getSales, startsWith);
|
||||||
|
}
|
8
cypress/utils/discounts/vouchersUtils.js
Normal file
8
cypress/utils/discounts/vouchersUtils.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import {
|
||||||
|
deleteVouchers,
|
||||||
|
getVouchers
|
||||||
|
} from "../../apiRequests/Discounts/Vouchers";
|
||||||
|
|
||||||
|
export function deleteVouchersStartsWith(startsWith) {
|
||||||
|
cy.deleteElementsStartsWith(deleteVouchers, getVouchers, startsWith, "code");
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ export function createWaitingForCaptureOrder(
|
||||||
shippingMethodId
|
shippingMethodId
|
||||||
) {
|
) {
|
||||||
let checkout;
|
let checkout;
|
||||||
return createCheckout(channelSlug, email, variantsList)
|
return createCheckout({ channelSlug, email, variantsList })
|
||||||
.then(checkoutResp => {
|
.then(checkoutResp => {
|
||||||
checkout = checkoutResp;
|
checkout = checkoutResp;
|
||||||
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
|
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
|
||||||
|
@ -17,6 +17,27 @@ export function createWaitingForCaptureOrder(
|
||||||
.then(() => checkoutRequest.completeCheckout(checkout.id))
|
.then(() => checkoutRequest.completeCheckout(checkout.id))
|
||||||
.then(() => checkout);
|
.then(() => checkout);
|
||||||
}
|
}
|
||||||
|
export function createCheckoutWithVoucher({
|
||||||
|
channelSlug,
|
||||||
|
email = "email@example.com",
|
||||||
|
variantsList,
|
||||||
|
address,
|
||||||
|
shippingMethodId,
|
||||||
|
voucherCode,
|
||||||
|
auth
|
||||||
|
}) {
|
||||||
|
let checkout;
|
||||||
|
return createCheckout({ channelSlug, email, variantsList, address, auth })
|
||||||
|
.then(checkoutResp => {
|
||||||
|
checkout = checkoutResp;
|
||||||
|
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
checkoutRequest.addVoucher(checkout.id, voucherCode);
|
||||||
|
})
|
||||||
|
.its("body.data.checkoutAddPromoCode");
|
||||||
|
}
|
||||||
|
|
||||||
export function createReadyToFulfillOrder(
|
export function createReadyToFulfillOrder(
|
||||||
customerId,
|
customerId,
|
||||||
shippingMethodId,
|
shippingMethodId,
|
||||||
|
@ -60,9 +81,22 @@ export function createDraftOrder(customerId, shippingMethodId, channelId) {
|
||||||
.createDraftOrder(customerId, shippingMethodId, channelId)
|
.createDraftOrder(customerId, shippingMethodId, channelId)
|
||||||
.its("body.data.draftOrderCreate.order");
|
.its("body.data.draftOrderCreate.order");
|
||||||
}
|
}
|
||||||
export function createCheckout(channelSlug, email, variantsList) {
|
export function createCheckout({
|
||||||
|
channelSlug,
|
||||||
|
email,
|
||||||
|
variantsList,
|
||||||
|
address,
|
||||||
|
auth
|
||||||
|
}) {
|
||||||
return checkoutRequest
|
return checkoutRequest
|
||||||
.createCheckout(channelSlug, email, 1, variantsList)
|
.createCheckout({
|
||||||
|
channelSlug,
|
||||||
|
email,
|
||||||
|
productQuantity: 1,
|
||||||
|
variantsList,
|
||||||
|
address,
|
||||||
|
auth
|
||||||
|
})
|
||||||
.its("body.data.checkoutCreate.checkout");
|
.its("body.data.checkoutCreate.checkout");
|
||||||
}
|
}
|
||||||
export function addPayment(checkoutId) {
|
export function addPayment(checkoutId) {
|
||||||
|
|
|
@ -109,19 +109,16 @@ export function deleteProductsStartsWith(startsWith) {
|
||||||
cy.deleteElementsStartsWith(
|
cy.deleteElementsStartsWith(
|
||||||
productRequest.deleteProductType,
|
productRequest.deleteProductType,
|
||||||
productRequest.getProductTypes,
|
productRequest.getProductTypes,
|
||||||
startsWith,
|
startsWith
|
||||||
"productType"
|
|
||||||
);
|
);
|
||||||
cy.deleteElementsStartsWith(
|
cy.deleteElementsStartsWith(
|
||||||
attributeRequest.deleteAttribute,
|
attributeRequest.deleteAttribute,
|
||||||
attributeRequest.getAttributes,
|
attributeRequest.getAttributes,
|
||||||
startsWith,
|
startsWith
|
||||||
"attributes"
|
|
||||||
);
|
);
|
||||||
cy.deleteElementsStartsWith(
|
cy.deleteElementsStartsWith(
|
||||||
categoryRequest.deleteCategory,
|
categoryRequest.deleteCategory,
|
||||||
categoryRequest.getCategories,
|
categoryRequest.getCategories,
|
||||||
startsWith,
|
startsWith
|
||||||
"categories"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
import { deleteSale, getSales } from "../apiRequests/Sales";
|
|
||||||
|
|
||||||
export function deleteSalesStartsWith(startsWith) {
|
|
||||||
cy.deleteElementsStartsWith(deleteSale, getSales, startsWith, "sales");
|
|
||||||
}
|
|
|
@ -46,13 +46,11 @@ export function deleteShippingStartsWith(startsWith) {
|
||||||
cy.deleteElementsStartsWith(
|
cy.deleteElementsStartsWith(
|
||||||
shippingMethodRequest.deleteShippingZone,
|
shippingMethodRequest.deleteShippingZone,
|
||||||
shippingMethodRequest.getShippingZones,
|
shippingMethodRequest.getShippingZones,
|
||||||
startsWith,
|
startsWith
|
||||||
"shippingZONE"
|
|
||||||
);
|
);
|
||||||
cy.deleteElementsStartsWith(
|
cy.deleteElementsStartsWith(
|
||||||
warehouseRequest.deleteWarehouse,
|
warehouseRequest.deleteWarehouse,
|
||||||
warehouseRequest.getWarehouses,
|
warehouseRequest.getWarehouses,
|
||||||
startsWith,
|
startsWith
|
||||||
"Warehouse"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,11 @@ const VoucherInfo = ({
|
||||||
title={intl.formatMessage(commonMessages.generalInformations)}
|
title={intl.formatMessage(commonMessages.generalInformations)}
|
||||||
toolbar={
|
toolbar={
|
||||||
variant === "create" && (
|
variant === "create" && (
|
||||||
<Button color="primary" onClick={onGenerateCode}>
|
<Button
|
||||||
|
color="primary"
|
||||||
|
onClick={onGenerateCode}
|
||||||
|
data-test-id="generate-code"
|
||||||
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Generate Code"
|
defaultMessage="Generate Code"
|
||||||
description="voucher code, button"
|
description="voucher code, button"
|
||||||
|
|
|
@ -53,7 +53,12 @@ const VoucherListPage: React.FC<VoucherListPageProps> = ({
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<PageHeader title={intl.formatMessage(sectionNames.vouchers)}>
|
<PageHeader title={intl.formatMessage(sectionNames.vouchers)}>
|
||||||
<Button onClick={onAdd} variant="contained" color="primary">
|
<Button
|
||||||
|
onClick={onAdd}
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
data-test-id="create-voucher"
|
||||||
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Create voucher"
|
defaultMessage="Create voucher"
|
||||||
description="button"
|
description="button"
|
||||||
|
|
|
@ -81428,6 +81428,7 @@ exports[`Storyshots Views / Discounts / Voucher create default 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
||||||
|
data-test-id="generate-code"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -82844,6 +82845,7 @@ exports[`Storyshots Views / Discounts / Voucher create form errors 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
||||||
|
data-test-id="generate-code"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -90466,6 +90468,7 @@ exports[`Storyshots Views / Discounts / Voucher list default 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="create-voucher"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -90999,6 +91002,7 @@ exports[`Storyshots Views / Discounts / Voucher list loading 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="create-voucher"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -91477,6 +91481,7 @@ exports[`Storyshots Views / Discounts / Voucher list no channels 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="create-voucher"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -92010,6 +92015,7 @@ exports[`Storyshots Views / Discounts / Voucher list no data 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="create-voucher"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue