gift cards in checkout (#1376)
* gift cards in checkout * complete checkout after trying to add gift card * fix gift cards tests * fix gift cards * update snapshots * fix tests * fix gift cards in checkout * delete created channels
This commit is contained in:
parent
c9678c5167
commit
2407ae6f76
45 changed files with 405 additions and 124 deletions
|
@ -3,6 +3,7 @@ export const GIFT_CARD_DIALOG = {
|
|||
currencySelectButton: '[id="mui-component-select-balanceCurrency"]',
|
||||
currenciesOptions: '[data-test="selectFieldOption"]',
|
||||
expirationOptions: {
|
||||
setExpiryDateCheckbox: '[name="expirySelected"]',
|
||||
neverExpireRadioButton: '[value="NEVER_EXPIRE"]',
|
||||
expiryPeriodRadioButton: '[value="EXPIRY_PERIOD"]',
|
||||
expiryDateRadioButton: '[value="EXPIRY_DATE"]',
|
||||
|
|
3
cypress/elements/giftCard/giftCardUpdate.js
Normal file
3
cypress/elements/giftCard/giftCardUpdate.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
export const GIFT_CARD_UPDATE = {
|
||||
changeActiveStatusButton: '[data-test-id="enable-button"]'
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
export const SITE_SETTINGS_DETAILS = {
|
||||
nameInput: '[name="name"]',
|
||||
urlInput: '[name="domain"]',
|
||||
descriptionInput: '[name="description"]'
|
||||
};
|
||||
|
|
|
@ -67,3 +67,6 @@ export const warehouseDetailsUrl = warehouseId =>
|
|||
|
||||
export const productTypeDetailsUrl = productTypeId =>
|
||||
`${urlList.productTypes}${productTypeId}`;
|
||||
|
||||
export const giftCardDetailsUrl = giftCardId =>
|
||||
`${urlList.giftCards}${giftCardId}`;
|
||||
|
|
|
@ -9,7 +9,7 @@ import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
|||
import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements";
|
||||
import { categoryDetailsUrl, urlList } from "../../fixtures/urlList";
|
||||
import { getCategory } from "../../support/api/requests/Category";
|
||||
import { deleteCategoriesStartsWith } from "../../support/api/utils/categoryUtils";
|
||||
import { deleteCategoriesStartsWith } from "../../support/api/utils/catalog/categoryUtils";
|
||||
import * as channelsUtils from "../../support/api/utils/channelsUtils";
|
||||
import * as productsUtils from "../../support/api/utils/products/productsUtils";
|
||||
import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils";
|
||||
|
@ -39,7 +39,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
.getDefaultChannel()
|
||||
.then(channel => {
|
||||
defaultChannel = channel;
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct(name);
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct({ name });
|
||||
})
|
||||
.then(
|
||||
({
|
||||
|
|
|
@ -8,8 +8,8 @@ import { createChannel } from "../../support/api/requests/Channels";
|
|||
import { updateChannelInProduct } from "../../support/api/requests/Product";
|
||||
import { getCollection } from "../../support/api/requests/storeFront/Collections";
|
||||
import { searchInShop } from "../../support/api/requests/storeFront/Search";
|
||||
import { deleteCollectionsStartsWith } from "../../support/api/utils/catalog/collectionsUtils";
|
||||
import * as channelsUtils from "../../support/api/utils/channelsUtils";
|
||||
import { deleteCollectionsStartsWith } from "../../support/api/utils/collectionsUtils";
|
||||
import * as productsUtils from "../../support/api/utils/products/productsUtils";
|
||||
import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils";
|
||||
import {
|
||||
|
@ -46,7 +46,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
.getDefaultChannel()
|
||||
.then(channel => {
|
||||
defaultChannel = channel;
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct(name);
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct({ name });
|
||||
})
|
||||
.then(
|
||||
({
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
import faker from "faker";
|
||||
|
||||
import { getGiftCardWithTag } from "../../support/api/requests/GiftCard";
|
||||
import { deleteGiftCardsWithTagStartsWith } from "../../support/api/utils/catalog/giftCardUtils";
|
||||
import { addToDate } from "../../support/api/utils/misc";
|
||||
import filterTests from "../../support/filterTests";
|
||||
import { formatDate } from "../../support/formatData/formatDate";
|
||||
import {
|
||||
|
@ -11,8 +13,7 @@ import {
|
|||
openAndFillUpCreateGiftCardDialog,
|
||||
saveGiftCard,
|
||||
setExpiryDate,
|
||||
setExpiryPeriod,
|
||||
setNeverExpire
|
||||
setExpiryPeriod
|
||||
} from "../../support/pages/catalog/giftCardPage";
|
||||
|
||||
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
||||
|
@ -23,6 +24,7 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteGiftCardsWithTagStartsWith(startsWith);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -39,11 +41,10 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
amount,
|
||||
currency
|
||||
});
|
||||
setNeverExpire();
|
||||
saveGiftCard()
|
||||
.then(createdGiftCardCode => {
|
||||
giftCardCode = createdGiftCardCode;
|
||||
getGiftCardWithTag(name);
|
||||
getGiftCardWithTag(name, true);
|
||||
})
|
||||
.then(giftCard => {
|
||||
expect(giftCard.code).to.eq(giftCardCode);
|
||||
|
@ -55,6 +56,7 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
it("should create gift card with two moths expiry", () => {
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
let giftCardCode;
|
||||
const expectedExpiryDate = addToDate(new Date(), 2, "M");
|
||||
|
||||
openAndFillUpCreateGiftCardDialog({
|
||||
note: name,
|
||||
|
@ -66,14 +68,13 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
saveGiftCard()
|
||||
.then(createdGiftCardCode => {
|
||||
giftCardCode = createdGiftCardCode;
|
||||
getGiftCardWithTag(name);
|
||||
getGiftCardWithTag(name, true);
|
||||
})
|
||||
.then(giftCard => {
|
||||
expect(giftCard.code).to.eq(giftCardCode);
|
||||
expect(giftCard.initialBalance.amount).to.eq(amount);
|
||||
expect(giftCard.initialBalance.currency).to.eq(currency);
|
||||
expect(giftCard.expiryPeriod.amount).to.eq(2);
|
||||
expect(giftCard.expiryPeriod.type).to.eq("MONTH");
|
||||
expect(giftCard.expiryDate).to.eq(expectedExpiryDate);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -92,7 +93,7 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
|||
saveGiftCard()
|
||||
.then(createdGiftCardCode => {
|
||||
giftCardCode = createdGiftCardCode;
|
||||
getGiftCardWithTag(name);
|
||||
getGiftCardWithTag(name, true);
|
||||
})
|
||||
.then(giftCard => {
|
||||
expect(giftCard.code).to.eq(giftCardCode);
|
||||
|
|
159
cypress/integration/checkout/giftCardsInCheckout.js
Normal file
159
cypress/integration/checkout/giftCardsInCheckout.js
Normal file
|
@ -0,0 +1,159 @@
|
|||
// <reference types="cypress" />
|
||||
import faker from "faker";
|
||||
|
||||
import { completeCheckout } from "../../support/api/requests/Checkout";
|
||||
import {
|
||||
createGiftCard,
|
||||
getGiftCardWithId,
|
||||
getGiftCardWithTag,
|
||||
giftCardDeactivate
|
||||
} from "../../support/api/requests/GiftCard";
|
||||
import { deleteGiftCardsWithTagStartsWith } from "../../support/api/utils/catalog/giftCardUtils";
|
||||
import * as channelsUtils from "../../support/api/utils/channelsUtils";
|
||||
import {
|
||||
addPayment,
|
||||
createCheckoutWithVoucher,
|
||||
purchaseProductWithPromoCode
|
||||
} from "../../support/api/utils/ordersUtils";
|
||||
import * as productsUtils from "../../support/api/utils/products/productsUtils";
|
||||
import {
|
||||
createShipping,
|
||||
deleteShippingStartsWith
|
||||
} from "../../support/api/utils/shippingUtils";
|
||||
import filterTests from "../../support/filterTests";
|
||||
import { changeGiftCardActiveStatus } from "../../support/pages/catalog/giftCardPage";
|
||||
|
||||
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
||||
describe("Gift cards in checkout", () => {
|
||||
const startsWith = "GiftCardsCheckout";
|
||||
const productPrice = 50;
|
||||
const shippingPrice = 50;
|
||||
|
||||
let defaultChannel;
|
||||
let productType;
|
||||
let attribute;
|
||||
let category;
|
||||
let shippingMethod;
|
||||
let variants;
|
||||
let address;
|
||||
let dataForCheckout;
|
||||
const giftCardData = {
|
||||
amount: 150,
|
||||
currency: "USD"
|
||||
};
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
channelsUtils.deleteChannelsStartsWith(startsWith);
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
deleteGiftCardsWithTagStartsWith(startsWith);
|
||||
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct({ name, kind: "GIFT_CARD" })
|
||||
.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(({ variantsList: variantsResp }) => {
|
||||
variants = variantsResp;
|
||||
|
||||
dataForCheckout = {
|
||||
address,
|
||||
auth: "token",
|
||||
channelSlug: defaultChannel.slug,
|
||||
shippingMethodId: shippingMethod.id,
|
||||
variantsList: variants
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should enable gift card", () => {
|
||||
giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
|
||||
let giftCard;
|
||||
|
||||
createGiftCard(giftCardData)
|
||||
.then(giftCardResp => {
|
||||
giftCard = giftCardResp;
|
||||
giftCardDeactivate(giftCard.id);
|
||||
})
|
||||
.then(() => {
|
||||
changeGiftCardActiveStatus(giftCard.id);
|
||||
dataForCheckout.voucherCode = giftCard.code;
|
||||
purchaseProductWithPromoCode(dataForCheckout);
|
||||
})
|
||||
.then(({ order }) => {
|
||||
expect(order.total.gross.amount).to.eq(0);
|
||||
getGiftCardWithTag(giftCardData.tag);
|
||||
})
|
||||
.then(giftCardResp => {
|
||||
expect(giftCardResp.initialBalance.amount).to.eq(giftCardData.amount);
|
||||
expect(giftCardResp.currentBalance.amount).to.eq(
|
||||
giftCardData.amount - productPrice - shippingPrice
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("should disable giftCard", () => {
|
||||
giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
|
||||
let giftCard;
|
||||
|
||||
createGiftCard(giftCardData)
|
||||
.then(giftCardResp => {
|
||||
giftCard = giftCardResp;
|
||||
changeGiftCardActiveStatus(giftCard.id);
|
||||
dataForCheckout.voucherCode = giftCard.code;
|
||||
createCheckoutWithVoucher(dataForCheckout);
|
||||
})
|
||||
.then(({ addPromoCodeResp, checkout }) => {
|
||||
expect(addPromoCodeResp.checkoutErrors[0].field).to.eq("promoCode");
|
||||
addPayment(checkout.id);
|
||||
completeCheckout(checkout.id);
|
||||
})
|
||||
.then(() => {
|
||||
getGiftCardWithId(giftCard.id);
|
||||
})
|
||||
.then(giftCardResp => {
|
||||
expect(giftCardResp.currentBalance.amount).to.eq(giftCardData.amount);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -9,6 +9,7 @@ import {
|
|||
addShippingMethod,
|
||||
createCheckout
|
||||
} from "../../support/api/requests/Checkout";
|
||||
import { deleteChannelsStartsWith } from "../../support/api/utils/channelsUtils";
|
||||
import {
|
||||
createProductInChannel,
|
||||
createTypeAttributeAndCategoryForProduct,
|
||||
|
@ -38,6 +39,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
|
||||
deleteProductsStartsWith(startsWith);
|
||||
deleteShippingStartsWith(startsWith);
|
||||
deleteChannelsStartsWith(startsWith);
|
||||
|
||||
createChannel({
|
||||
name
|
||||
|
@ -62,7 +64,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
}) => {
|
||||
warehouse = warehouseResp;
|
||||
shippingMethod = shippingMethodResp;
|
||||
createTypeAttributeAndCategoryForProduct(name);
|
||||
createTypeAttributeAndCategoryForProduct({ name });
|
||||
}
|
||||
)
|
||||
.then(
|
||||
|
|
|
@ -58,7 +58,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
|
|||
}) => {
|
||||
warehouse = warehouseResp;
|
||||
shippingMethod = shippingMethodResp;
|
||||
createTypeAttributeAndCategoryForProduct(name);
|
||||
createTypeAttributeAndCategoryForProduct({ name });
|
||||
}
|
||||
)
|
||||
.then(
|
||||
|
|
|
@ -45,7 +45,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
})
|
||||
.then(({ warehouse: warehouseResp }) => {
|
||||
warehouse = warehouseResp;
|
||||
createTypeAttributeAndCategoryForProduct(name);
|
||||
createTypeAttributeAndCategoryForProduct({ name });
|
||||
})
|
||||
.then(({ attribute, productType, category }) => {
|
||||
createProductInChannel({
|
||||
|
|
|
@ -28,18 +28,19 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteProductsStartsWith(startsWith);
|
||||
createTypeAttributeAndCategoryForProduct(startsWith, [startsWith]).then(
|
||||
({ attribute: attributeResp, category, productType }) => {
|
||||
attribute = attributeResp;
|
||||
createProduct({
|
||||
attributeId: attribute.id,
|
||||
attributeValue: startsWith,
|
||||
categoryId: category.id,
|
||||
productTypeId: productType.id,
|
||||
name: startsWith
|
||||
});
|
||||
}
|
||||
);
|
||||
createTypeAttributeAndCategoryForProduct({
|
||||
name: startsWith,
|
||||
attributeValues: [startsWith]
|
||||
}).then(({ attribute: attributeResp, category, productType }) => {
|
||||
attribute = attributeResp;
|
||||
createProduct({
|
||||
attributeId: attribute.id,
|
||||
attributeValue: startsWith,
|
||||
categoryId: category.id,
|
||||
productTypeId: productType.id,
|
||||
name: startsWith
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should use attribute as filter", () => {
|
||||
|
|
|
@ -79,7 +79,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
|
||||
it("should not be possible to create checkout with inactive channel", () => {
|
||||
const randomChannel = `${channelStartsWith}${faker.datatype.number()}`;
|
||||
createTypeAttributeAndCategoryForProduct(randomChannel)
|
||||
createTypeAttributeAndCategoryForProduct({ name: randomChannel })
|
||||
.then(({ productType, attribute, category }) => {
|
||||
createProductInChannel({
|
||||
name: randomChannel,
|
||||
|
@ -118,7 +118,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
})
|
||||
.then(channelResp => {
|
||||
channel = channelResp;
|
||||
createTypeAttributeAndCategoryForProduct(randomChannel);
|
||||
createTypeAttributeAndCategoryForProduct({ name: randomChannel });
|
||||
})
|
||||
.then(({ productType, attribute, category }) => {
|
||||
createProductInChannel({
|
||||
|
|
|
@ -74,7 +74,7 @@ filterTests({ definedTags: ["stagedOnly"] }, () => {
|
|||
shippingMethod = shippingMethodResp;
|
||||
}
|
||||
);
|
||||
createTypeAttributeAndCategoryForProduct(name)
|
||||
createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(({ productType, attribute, category }) => {
|
||||
createProductInChannel({
|
||||
name,
|
||||
|
|
|
@ -13,7 +13,10 @@ import {
|
|||
deleteCustomersStartsWith,
|
||||
requestPasswordReset
|
||||
} from "../../../support/api/requests/Customer";
|
||||
import { getDefaultChannel } from "../../../support/api/utils/channelsUtils";
|
||||
import {
|
||||
deleteChannelsStartsWith,
|
||||
getDefaultChannel
|
||||
} from "../../../support/api/utils/channelsUtils";
|
||||
import { getMailsForUser } from "../../../support/api/utils/users";
|
||||
import filterTests from "../../../support/filterTests";
|
||||
|
||||
|
@ -26,6 +29,7 @@ filterTests({ definedTags: ["stagedOnly"], version: "3.1.1" }, () => {
|
|||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteCustomersStartsWith(startsWith);
|
||||
deleteChannelsStartsWith(startsWith);
|
||||
createChannel({ name: randomName });
|
||||
getDefaultChannel().then(channel => (defaultChannel = channel));
|
||||
});
|
||||
|
|
|
@ -46,7 +46,9 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
})
|
||||
.then(warehouseResp => {
|
||||
warehouse = warehouseResp;
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct(startsWith);
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct({
|
||||
name: startsWith
|
||||
});
|
||||
})
|
||||
.then(
|
||||
({
|
||||
|
|
|
@ -66,7 +66,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
})
|
||||
.then(warehouseResp => {
|
||||
warehouse = warehouseResp;
|
||||
createTypeAttributeAndCategoryForProduct(name);
|
||||
createTypeAttributeAndCategoryForProduct({ name });
|
||||
})
|
||||
.then(({ attribute, productType, category }) => {
|
||||
createProductInChannel({
|
||||
|
|
|
@ -59,7 +59,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
})
|
||||
.then(warehouseResp => {
|
||||
warehouse = warehouseResp;
|
||||
createTypeAttributeAndCategoryForProduct(name);
|
||||
createTypeAttributeAndCategoryForProduct({ name });
|
||||
})
|
||||
.then(({ attribute, productType, category }) => {
|
||||
createProductInChannel({
|
||||
|
|
|
@ -44,19 +44,6 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("should change site url", () => {
|
||||
const url = `http://cypress${faker.datatype.number()}.saleor.com`;
|
||||
|
||||
cy.get(SITE_SETTINGS_DETAILS.urlInput)
|
||||
.clearAndType(url)
|
||||
.get(BUTTON_SELECTORS.confirm)
|
||||
.click()
|
||||
.confirmationMessageShouldDisappear();
|
||||
getShopInfo().then(shopInfo => {
|
||||
expect(shopInfo.domain.host).to.eq(url);
|
||||
});
|
||||
});
|
||||
|
||||
it("should change store description", () => {
|
||||
const description = faker.lorem.sentence();
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
createCategory,
|
||||
getCategory
|
||||
} from "../../support/api/requests/Category";
|
||||
import { deleteCategoriesStartsWith } from "../../support/api/utils/categoryUtils";
|
||||
import { deleteCategoriesStartsWith } from "../../support/api/utils/catalog/categoryUtils";
|
||||
import filterTests from "../../support/filterTests";
|
||||
|
||||
filterTests({ definedTags: ["all"], version: "3.1.1" }, () => {
|
||||
|
|
|
@ -40,7 +40,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
|
||||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct(name)
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
({
|
||||
productType: productTypeResp,
|
||||
|
|
|
@ -45,7 +45,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
const name = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct(name)
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
({
|
||||
productType: productTypeResp,
|
||||
|
@ -143,10 +143,12 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
discountOption: discountOptions.PERCENTAGE,
|
||||
channelName: createdChannel.name
|
||||
});
|
||||
createCheckoutForCreatedVoucher(randomName).then(resp => {
|
||||
const errorField = resp.checkoutErrors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
});
|
||||
createCheckoutForCreatedVoucher(randomName).then(
|
||||
({ addPromoCodeResp }) => {
|
||||
const errorField = addPromoCodeResp.checkoutErrors[0].field;
|
||||
expect(errorField).to.be.eq("promoCode");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
function createCheckoutForCreatedVoucher(voucherCode) {
|
||||
|
@ -177,7 +179,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
channelName: defaultChannel.name
|
||||
});
|
||||
return createCheckoutForCreatedVoucher(voucherCode).its(
|
||||
"checkout.totalPrice.gross.amount"
|
||||
"addPromoCodeResp.checkout.totalPrice.gross.amount"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -72,7 +72,9 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
|
|||
}) => {
|
||||
warehouse = warehouseResp;
|
||||
shippingMethod = shippingMethodResp;
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct(randomName);
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct({
|
||||
name: randomName
|
||||
});
|
||||
}
|
||||
)
|
||||
.then(
|
||||
|
|
|
@ -28,7 +28,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
getDefaultChannel()
|
||||
.then(channelResp => {
|
||||
channel = channelResp;
|
||||
createTypeAttributeAndCategoryForProduct(name);
|
||||
createTypeAttributeAndCategoryForProduct({ name });
|
||||
})
|
||||
.then(({ attribute, category, productType }) => {
|
||||
createProductInChannel({
|
||||
|
|
|
@ -60,7 +60,9 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
})
|
||||
.then(({ warehouse: warehouseResp }) => {
|
||||
warehouse = warehouseResp;
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct(randomName);
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct({
|
||||
name: randomName
|
||||
});
|
||||
})
|
||||
.then(
|
||||
({
|
||||
|
|
|
@ -82,7 +82,9 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
}) => {
|
||||
shippingMethod = shippingMethodResp;
|
||||
warehouse = warehouseResp;
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct(randomName);
|
||||
productsUtils.createTypeAttributeAndCategoryForProduct({
|
||||
name: randomName
|
||||
});
|
||||
}
|
||||
)
|
||||
.then(
|
||||
|
|
|
@ -45,7 +45,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
});
|
||||
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct(name)
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
({
|
||||
attribute: attributeResp,
|
||||
|
|
|
@ -25,7 +25,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
cy.clearSessionData().loginUserViaRequest();
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct(name)
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
({
|
||||
attribute: attributeResp,
|
||||
|
|
|
@ -24,7 +24,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
cy.clearSessionData().loginUserViaRequest();
|
||||
productsUtils.deleteProductsStartsWith(startsWith);
|
||||
productsUtils
|
||||
.createTypeAttributeAndCategoryForProduct(name)
|
||||
.createTypeAttributeAndCategoryForProduct({ name })
|
||||
.then(
|
||||
({
|
||||
attribute: attributeResp,
|
||||
|
|
|
@ -41,7 +41,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
cy.clearSessionData().loginUserViaRequest();
|
||||
deleteShippingStartsWith(startsWith);
|
||||
deleteProductsStartsWith(startsWith);
|
||||
createTypeAttributeAndCategoryForProduct(name).then(
|
||||
createTypeAttributeAndCategoryForProduct({ name }).then(
|
||||
({
|
||||
attribute: attributeResp,
|
||||
productType: productTypeResp,
|
||||
|
|
|
@ -63,7 +63,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
|
|||
.then(resp => (newChannel = resp));
|
||||
|
||||
productUtils
|
||||
.createTypeAttributeAndCategoryForProduct(name, attributeValues)
|
||||
.createTypeAttributeAndCategoryForProduct({ name, attributeValues })
|
||||
.then(
|
||||
({
|
||||
attribute: attributeResp,
|
||||
|
|
|
@ -10,8 +10,8 @@ import { ONE_PERMISSION_USERS } from "../../fixtures/users";
|
|||
import { createCategory } from "../../support/api/requests/Category";
|
||||
import { createCollection } from "../../support/api/requests/Collections";
|
||||
import { getProductDetails } from "../../support/api/requests/storeFront/ProductDetails";
|
||||
import { deleteCollectionsStartsWith } from "../../support/api/utils/catalog/collectionsUtils";
|
||||
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
||||
import { deleteCollectionsStartsWith } from "../../support/api/utils/collectionsUtils";
|
||||
import { expectCorrectProductInformation } from "../../support/api/utils/products/checkProductInfo";
|
||||
import {
|
||||
createProductInChannel,
|
||||
|
@ -44,7 +44,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
|||
})
|
||||
.then(collectionResp => {
|
||||
collection = collectionResp;
|
||||
createTypeAttributeAndCategoryForProduct(name);
|
||||
createTypeAttributeAndCategoryForProduct({ name });
|
||||
})
|
||||
.then(({ attribute: attributeResp, category, productType }) => {
|
||||
attribute = attributeResp;
|
||||
|
|
|
@ -101,6 +101,12 @@ export function completeCheckout(checkoutId, paymentData) {
|
|||
checkoutComplete(checkoutId:"${checkoutId}" ${paymentDataLine}){
|
||||
order{
|
||||
id
|
||||
paymentStatus
|
||||
total{
|
||||
gross{
|
||||
amount
|
||||
}
|
||||
}
|
||||
}
|
||||
confirmationNeeded
|
||||
confirmationData
|
||||
|
@ -123,6 +129,7 @@ export function addVoucher(checkoutId, voucherCode) {
|
|||
message
|
||||
}
|
||||
checkout{
|
||||
id
|
||||
totalPrice{
|
||||
gross{
|
||||
amount
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
export function getGiftCardWithTag(tag) {
|
||||
return getGiftCardsWithTag(1, tag)
|
||||
import { getValueWithDefault } from "./utils/Utils";
|
||||
|
||||
export function getGiftCardWithTag(tag, withCode = false) {
|
||||
return getGiftCardsWithTag(1, tag, withCode)
|
||||
.its("body.data.giftCards.edges")
|
||||
.its(0)
|
||||
.its("node");
|
||||
}
|
||||
|
||||
export function getGiftCardsWithTag(first, tag) {
|
||||
export function getGiftCardsWithTag(first, tag, withCode = false) {
|
||||
const codeLine = getValueWithDefault(withCode, `code`);
|
||||
const query = `query{
|
||||
giftCards(first: ${first}, filter: { tag: "${tag}"}){
|
||||
edges{
|
||||
node{
|
||||
${codeLine}
|
||||
displayCode
|
||||
id
|
||||
code
|
||||
isActive
|
||||
expiryType
|
||||
expiryDate
|
||||
expiryPeriod{
|
||||
currentBalance{
|
||||
currency
|
||||
amount
|
||||
type
|
||||
}
|
||||
initialBalance{
|
||||
currency
|
||||
|
@ -29,3 +32,66 @@ export function getGiftCardsWithTag(first, tag) {
|
|||
}`;
|
||||
return cy.sendRequestWithQuery(query);
|
||||
}
|
||||
|
||||
export function getGiftCardWithId(id) {
|
||||
const query = `query{
|
||||
giftCard(id:"${id}"){
|
||||
isActive
|
||||
currentBalance{
|
||||
currency
|
||||
amount
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query).its("body.data.giftCard");
|
||||
}
|
||||
|
||||
export function createGiftCard({ tag, currency, amount }) {
|
||||
const mutation = `mutation{
|
||||
giftCardCreate(input:{
|
||||
tag:"${tag}"
|
||||
isActive: true
|
||||
balance: {
|
||||
currency: "${currency}"
|
||||
amount: ${amount}
|
||||
}
|
||||
}){
|
||||
errors{
|
||||
field
|
||||
message
|
||||
}
|
||||
giftCard{
|
||||
code
|
||||
id
|
||||
isActive
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(mutation)
|
||||
.its("body.data.giftCardCreate.giftCard");
|
||||
}
|
||||
|
||||
export function giftCardDeactivate(giftCardId) {
|
||||
const mutation = `mutation{
|
||||
giftCardDeactivate(id:"${giftCardId}"){
|
||||
errors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function deleteGiftCard(giftCardId) {
|
||||
const mutation = `mutation{
|
||||
giftCardDelete(id:"${giftCardId}"){
|
||||
errors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ export function createTypeProduct({
|
|||
isShippingRequired:${shippable}
|
||||
${kindLines}
|
||||
}){
|
||||
productErrors{
|
||||
errors{
|
||||
field
|
||||
message
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { deleteCategory, getCategories } from "../requests/Category";
|
||||
import { deleteCategory, getCategories } from "../../requests/Category";
|
||||
|
||||
export function deleteCategoriesStartsWith(startsWith) {
|
||||
cy.deleteElementsStartsWith(deleteCategory, getCategories, startsWith);
|
|
@ -1,4 +1,4 @@
|
|||
import { deleteCollection, getCollections } from "../requests/Collections";
|
||||
import { deleteCollection, getCollections } from "../../requests/Collections";
|
||||
|
||||
export function deleteCollectionsStartsWith(startsWith) {
|
||||
cy.deleteElementsStartsWith(deleteCollection, getCollections, startsWith);
|
12
cypress/support/api/utils/catalog/giftCardUtils.js
Normal file
12
cypress/support/api/utils/catalog/giftCardUtils.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { deleteGiftCard, getGiftCardsWithTag } from "../../requests/GiftCard";
|
||||
|
||||
export function deleteGiftCardsWithTagStartsWith(tag) {
|
||||
getGiftCardsWithTag(100, tag).then(resp => {
|
||||
const giftCardArray = resp.body.data.giftCards;
|
||||
if (giftCardArray) {
|
||||
giftCardArray.edges.forEach(element => {
|
||||
deleteGiftCard(element.node.id);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
import moment from "moment-timezone";
|
||||
|
||||
const format = "YYYY-MM-DD";
|
||||
|
||||
export function getDatePeriod(days) {
|
||||
if (days < 1) {
|
||||
return {};
|
||||
|
@ -7,10 +9,15 @@ export function getDatePeriod(days) {
|
|||
|
||||
const end = moment().startOf("day");
|
||||
const start = end.subtract(days - 1);
|
||||
const format = "YYYY-MM-DD";
|
||||
|
||||
return {
|
||||
gte: start.format(format),
|
||||
lte: end.format(format)
|
||||
};
|
||||
}
|
||||
|
||||
export function addToDate(date, amount, periodType) {
|
||||
const currentDate = moment(date);
|
||||
const futureDate = moment(currentDate).add(amount, periodType);
|
||||
return futureDate.format(format);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,14 @@ export function createCheckoutWithVoucher({
|
|||
}) {
|
||||
let checkout;
|
||||
return checkoutRequest
|
||||
.createCheckout({ channelSlug, email, variantsList, address, auth })
|
||||
.createCheckout({
|
||||
channelSlug,
|
||||
email,
|
||||
variantsList,
|
||||
address,
|
||||
billingAddress: address,
|
||||
auth
|
||||
})
|
||||
.then(({ checkout: checkoutResp }) => {
|
||||
checkout = checkoutResp;
|
||||
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
|
||||
|
@ -49,7 +56,38 @@ export function createCheckoutWithVoucher({
|
|||
.then(() => {
|
||||
checkoutRequest.addVoucher(checkout.id, voucherCode);
|
||||
})
|
||||
.its("body.data.checkoutAddPromoCode");
|
||||
.then(resp => ({
|
||||
addPromoCodeResp: resp.body.data.checkoutAddPromoCode,
|
||||
checkout
|
||||
}));
|
||||
}
|
||||
|
||||
export function purchaseProductWithPromoCode({
|
||||
channelSlug,
|
||||
email = "email@example.com",
|
||||
variantsList,
|
||||
address,
|
||||
shippingMethodId,
|
||||
voucherCode,
|
||||
auth
|
||||
}) {
|
||||
let checkout;
|
||||
|
||||
return createCheckoutWithVoucher({
|
||||
channelSlug,
|
||||
email,
|
||||
variantsList,
|
||||
address,
|
||||
shippingMethodId,
|
||||
voucherCode,
|
||||
auth
|
||||
})
|
||||
.then(({ checkout: checkoutResp }) => {
|
||||
checkout = checkoutResp;
|
||||
addPayment(checkout.id);
|
||||
})
|
||||
.then(() => checkoutRequest.completeCheckout(checkout.id))
|
||||
.then(({ order }) => ({ checkout, order }));
|
||||
}
|
||||
|
||||
export function createReadyToFulfillOrder({
|
||||
|
|
|
@ -65,10 +65,11 @@ export function createProductInChannel({
|
|||
});
|
||||
}
|
||||
|
||||
export function createTypeAttributeAndCategoryForProduct(
|
||||
export function createTypeAttributeAndCategoryForProduct({
|
||||
name,
|
||||
attributeValues
|
||||
) {
|
||||
attributeValues,
|
||||
kind = "NORMAL"
|
||||
}) {
|
||||
let attribute;
|
||||
let productType;
|
||||
let category;
|
||||
|
@ -76,7 +77,7 @@ export function createTypeAttributeAndCategoryForProduct(
|
|||
.createAttribute({ name, attributeValues })
|
||||
.then(attributeResp => {
|
||||
attribute = attributeResp;
|
||||
createTypeProduct({ name, attributeId: attributeResp.id });
|
||||
createTypeProduct({ name, attributeId: attributeResp.id, kind });
|
||||
})
|
||||
.then(productTypeResp => {
|
||||
productType = productTypeResp;
|
||||
|
|
|
@ -10,7 +10,10 @@ Cypress.Commands.add("clearAndType", { prevSubject: true }, (subject, text) => {
|
|||
|
||||
Cypress.Commands.add("waitForRequestAndCheckIfNoErrors", alias => {
|
||||
cy.wait(alias).then(resp => {
|
||||
expect(resp.response.body.errors).to.be.undefined;
|
||||
expect(
|
||||
resp.response.body.errors,
|
||||
`There are errors in ${alias} operation in graphql response`
|
||||
).to.be.undefined;
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { GIFT_CARD_DIALOG } from "../../../elements/giftCard/giftCardDialog";
|
||||
import { GIFT_CARD_LIST } from "../../../elements/giftCard/giftCardList";
|
||||
import { GIFT_CARD_UPDATE } from "../../../elements/giftCard/giftCardUpdate";
|
||||
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
||||
import { urlList } from "../../../fixtures/urlList";
|
||||
import { giftCardDetailsUrl, urlList } from "../../../fixtures/urlList";
|
||||
|
||||
export function openAndFillUpCreateGiftCardDialog({
|
||||
note,
|
||||
|
@ -36,16 +37,14 @@ export function saveGiftCard() {
|
|||
});
|
||||
}
|
||||
|
||||
export function setNeverExpire() {
|
||||
cy.get(GIFT_CARD_DIALOG.expirationOptions.neverExpireRadioButton).click();
|
||||
}
|
||||
|
||||
export const expiryPeriods = {
|
||||
MONTH: GIFT_CARD_DIALOG.expirationOptions.expiryPeriodMonthType
|
||||
};
|
||||
|
||||
export function setExpiryPeriod(amount, period) {
|
||||
cy.get(GIFT_CARD_DIALOG.expirationOptions.expiryPeriodRadioButton)
|
||||
cy.get(GIFT_CARD_DIALOG.expirationOptions.setExpiryDateCheckbox)
|
||||
.click()
|
||||
.get(GIFT_CARD_DIALOG.expirationOptions.expiryPeriodRadioButton)
|
||||
.click()
|
||||
.get(GIFT_CARD_DIALOG.expirationOptions.expiryPeriodAmount)
|
||||
.clearAndType(amount)
|
||||
|
@ -56,8 +55,17 @@ export function setExpiryPeriod(amount, period) {
|
|||
}
|
||||
|
||||
export function setExpiryDate(date) {
|
||||
cy.get(GIFT_CARD_DIALOG.expirationOptions.expiryDateRadioButton)
|
||||
cy.get(GIFT_CARD_DIALOG.expirationOptions.setExpiryDateCheckbox)
|
||||
.click()
|
||||
.get(GIFT_CARD_DIALOG.expirationOptions.expiryDateRadioButton)
|
||||
.click()
|
||||
.get(GIFT_CARD_DIALOG.expirationOptions.expiryDateInput)
|
||||
.type(date);
|
||||
}
|
||||
|
||||
export function changeGiftCardActiveStatus(giftCardId) {
|
||||
cy.visit(giftCardDetailsUrl(giftCardId))
|
||||
.get(GIFT_CARD_UPDATE.changeActiveStatusButton)
|
||||
.click()
|
||||
.confirmationMessageShouldDisappear();
|
||||
}
|
||||
|
|
32
package-lock.json
generated
32
package-lock.json
generated
|
@ -6602,15 +6602,6 @@
|
|||
"@types/react": "*"
|
||||
}
|
||||
},
|
||||
"@types/react-responsive": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/react-responsive/-/react-responsive-3.0.3.tgz",
|
||||
"integrity": "sha512-paTAvXIFgv/jG60d7WSV0+yWCjqJ05cG+KOV48SiqYGjGi9kFdss9QnVTTLnFJmbUwWnoM+VD1Iyay1JBy/HPQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/react": "*"
|
||||
}
|
||||
},
|
||||
"@types/react-router": {
|
||||
"version": "5.1.13",
|
||||
"resolved": "https://registry.npmjs.org/@types/react-router/-/react-router-5.1.13.tgz",
|
||||
|
@ -12132,11 +12123,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"css-mediaquery": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/css-mediaquery/-/css-mediaquery-0.1.2.tgz",
|
||||
"integrity": "sha1-aiw3NEkoYYYxxUvTPO3TAdoYvqA="
|
||||
},
|
||||
"css-select": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/css-select/-/css-select-2.1.0.tgz",
|
||||
|
@ -21202,14 +21188,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"matchmediaquery": {
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/matchmediaquery/-/matchmediaquery-0.3.1.tgz",
|
||||
"integrity": "sha512-Hlk20WQHRIm9EE9luN1kjRjYXAQToHOIAHPJn9buxBwuhfTHoKUcX+lXBbxc85DVQfXYbEQ4HcwQdd128E3qHQ==",
|
||||
"requires": {
|
||||
"css-mediaquery": "^0.1.2"
|
||||
}
|
||||
},
|
||||
"math-random": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.4.tgz",
|
||||
|
@ -24720,16 +24698,6 @@
|
|||
"react-popper": "^1.3.7"
|
||||
}
|
||||
},
|
||||
"react-responsive": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/react-responsive/-/react-responsive-7.0.0.tgz",
|
||||
"integrity": "sha512-RukaKD+UI/MIR+P8eUgVGURfiCafRvvcVnq41scT0eEQWHwDGliH/OAlrwIr1oyz8aKLGroZa+U8mTZV5ihPfA==",
|
||||
"requires": {
|
||||
"hyphenate-style-name": "^1.0.0",
|
||||
"matchmediaquery": "^0.3.0",
|
||||
"prop-types": "^15.6.1"
|
||||
}
|
||||
},
|
||||
"react-router": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-5.2.0.tgz",
|
||||
|
|
|
@ -86,6 +86,7 @@ const GiftCardEnableDisableSection: React.FC = () => {
|
|||
|
||||
return (
|
||||
<ConfirmButton
|
||||
data-test-id="enable-button"
|
||||
onClick={handleClick}
|
||||
transitionState={currentOpts?.status}
|
||||
labels={{
|
||||
|
|
Loading…
Reference in a new issue