diff --git a/cypress/elements/giftCard/giftCardDialog.js b/cypress/elements/giftCard/giftCardDialog.js index 095ef76ae..620bda951 100644 --- a/cypress/elements/giftCard/giftCardDialog.js +++ b/cypress/elements/giftCard/giftCardDialog.js @@ -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"]', diff --git a/cypress/elements/giftCard/giftCardUpdate.js b/cypress/elements/giftCard/giftCardUpdate.js new file mode 100644 index 000000000..470899807 --- /dev/null +++ b/cypress/elements/giftCard/giftCardUpdate.js @@ -0,0 +1,3 @@ +export const GIFT_CARD_UPDATE = { + changeActiveStatusButton: '[data-test-id="enable-button"]' +}; diff --git a/cypress/elements/siteSettings/site-settings-details.js b/cypress/elements/siteSettings/site-settings-details.js index 04bda8c53..8272239f8 100644 --- a/cypress/elements/siteSettings/site-settings-details.js +++ b/cypress/elements/siteSettings/site-settings-details.js @@ -1,5 +1,4 @@ export const SITE_SETTINGS_DETAILS = { nameInput: '[name="name"]', - urlInput: '[name="domain"]', descriptionInput: '[name="description"]' }; diff --git a/cypress/fixtures/urlList.js b/cypress/fixtures/urlList.js index ed5664fa4..272c62578 100644 --- a/cypress/fixtures/urlList.js +++ b/cypress/fixtures/urlList.js @@ -67,3 +67,6 @@ export const warehouseDetailsUrl = warehouseId => export const productTypeDetailsUrl = productTypeId => `${urlList.productTypes}${productTypeId}`; + +export const giftCardDetailsUrl = giftCardId => + `${urlList.giftCards}${giftCardId}`; diff --git a/cypress/integration/catalog/categories.js b/cypress/integration/catalog/categories.js index 050749f61..bd1f41f2a 100644 --- a/cypress/integration/catalog/categories.js +++ b/cypress/integration/catalog/categories.js @@ -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( ({ diff --git a/cypress/integration/catalog/collections.js b/cypress/integration/catalog/collections.js index 69a10eaa1..ded8ae284 100644 --- a/cypress/integration/catalog/collections.js +++ b/cypress/integration/catalog/collections.js @@ -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( ({ diff --git a/cypress/integration/catalog/giftCards.js b/cypress/integration/catalog/giftCards.js index e5b65c546..61598a987 100644 --- a/cypress/integration/catalog/giftCards.js +++ b/cypress/integration/catalog/giftCards.js @@ -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); diff --git a/cypress/integration/checkout/giftCardsInCheckout.js b/cypress/integration/checkout/giftCardsInCheckout.js new file mode 100644 index 000000000..353bb7a93 --- /dev/null +++ b/cypress/integration/checkout/giftCardsInCheckout.js @@ -0,0 +1,159 @@ +// +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); + }); + }); + }); +}); diff --git a/cypress/integration/checkout/productWithoutShipping.js b/cypress/integration/checkout/productWithoutShipping.js index c8e4aed09..e4c17c7c3 100644 --- a/cypress/integration/checkout/productWithoutShipping.js +++ b/cypress/integration/checkout/productWithoutShipping.js @@ -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( diff --git a/cypress/integration/checkout/stocksInCheckout.js b/cypress/integration/checkout/stocksInCheckout.js index b1624d728..81864b2a4 100644 --- a/cypress/integration/checkout/stocksInCheckout.js +++ b/cypress/integration/checkout/stocksInCheckout.js @@ -58,7 +58,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => { }) => { warehouse = warehouseResp; shippingMethod = shippingMethodResp; - createTypeAttributeAndCategoryForProduct(name); + createTypeAttributeAndCategoryForProduct({ name }); } ) .then( diff --git a/cypress/integration/checkout/warehouses.js b/cypress/integration/checkout/warehouses.js index 74aab6788..f6a89ae20 100644 --- a/cypress/integration/checkout/warehouses.js +++ b/cypress/integration/checkout/warehouses.js @@ -45,7 +45,7 @@ filterTests({ definedTags: ["all"] }, () => { }) .then(({ warehouse: warehouseResp }) => { warehouse = warehouseResp; - createTypeAttributeAndCategoryForProduct(name); + createTypeAttributeAndCategoryForProduct({ name }); }) .then(({ attribute, productType, category }) => { createProductInChannel({ diff --git a/cypress/integration/configuration/attributes/filters.js b/cypress/integration/configuration/attributes/filters.js index e3a18e060..5a3cb5f31 100644 --- a/cypress/integration/configuration/attributes/filters.js +++ b/cypress/integration/configuration/attributes/filters.js @@ -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", () => { diff --git a/cypress/integration/configuration/channels/inactiveChannel.js b/cypress/integration/configuration/channels/inactiveChannel.js index e22c20acb..6e28bc653 100644 --- a/cypress/integration/configuration/channels/inactiveChannel.js +++ b/cypress/integration/configuration/channels/inactiveChannel.js @@ -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({ diff --git a/cypress/integration/configuration/plugins/adyen.js b/cypress/integration/configuration/plugins/adyen.js index 035b4ca4e..5988d716f 100644 --- a/cypress/integration/configuration/plugins/adyen.js +++ b/cypress/integration/configuration/plugins/adyen.js @@ -74,7 +74,7 @@ filterTests({ definedTags: ["stagedOnly"] }, () => { shippingMethod = shippingMethodResp; } ); - createTypeAttributeAndCategoryForProduct(name) + createTypeAttributeAndCategoryForProduct({ name }) .then(({ productType, attribute, category }) => { createProductInChannel({ name, diff --git a/cypress/integration/configuration/plugins/plugins.js b/cypress/integration/configuration/plugins/plugins.js index 50c98e5ab..51b426d18 100644 --- a/cypress/integration/configuration/plugins/plugins.js +++ b/cypress/integration/configuration/plugins/plugins.js @@ -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)); }); diff --git a/cypress/integration/configuration/shippingMethods/createShippingMethod.js b/cypress/integration/configuration/shippingMethods/createShippingMethod.js index d0f10e436..59515fd68 100644 --- a/cypress/integration/configuration/shippingMethods/createShippingMethod.js +++ b/cypress/integration/configuration/shippingMethods/createShippingMethod.js @@ -46,7 +46,9 @@ filterTests({ definedTags: ["all"] }, () => { }) .then(warehouseResp => { warehouse = warehouseResp; - productsUtils.createTypeAttributeAndCategoryForProduct(startsWith); + productsUtils.createTypeAttributeAndCategoryForProduct({ + name: startsWith + }); }) .then( ({ diff --git a/cypress/integration/configuration/shippingMethods/postalCodes.js b/cypress/integration/configuration/shippingMethods/postalCodes.js index c161921d5..7122fb378 100644 --- a/cypress/integration/configuration/shippingMethods/postalCodes.js +++ b/cypress/integration/configuration/shippingMethods/postalCodes.js @@ -66,7 +66,7 @@ filterTests({ definedTags: ["all"] }, () => { }) .then(warehouseResp => { warehouse = warehouseResp; - createTypeAttributeAndCategoryForProduct(name); + createTypeAttributeAndCategoryForProduct({ name }); }) .then(({ attribute, productType, category }) => { createProductInChannel({ diff --git a/cypress/integration/configuration/shippingMethods/shippingWeights/shippingWeightsLimits.js b/cypress/integration/configuration/shippingMethods/shippingWeights/shippingWeightsLimits.js index 58ce52e45..dfdc809e9 100644 --- a/cypress/integration/configuration/shippingMethods/shippingWeights/shippingWeightsLimits.js +++ b/cypress/integration/configuration/shippingMethods/shippingWeights/shippingWeightsLimits.js @@ -59,7 +59,7 @@ filterTests({ definedTags: ["all"] }, () => { }) .then(warehouseResp => { warehouse = warehouseResp; - createTypeAttributeAndCategoryForProduct(name); + createTypeAttributeAndCategoryForProduct({ name }); }) .then(({ attribute, productType, category }) => { createProductInChannel({ diff --git a/cypress/integration/configuration/siteSettings.js b/cypress/integration/configuration/siteSettings.js index 057d4828d..51e909edd 100644 --- a/cypress/integration/configuration/siteSettings.js +++ b/cypress/integration/configuration/siteSettings.js @@ -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(); diff --git a/cypress/integration/configuration/translations.js b/cypress/integration/configuration/translations.js index 078d7618f..94971de80 100644 --- a/cypress/integration/configuration/translations.js +++ b/cypress/integration/configuration/translations.js @@ -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" }, () => { diff --git a/cypress/integration/discounts/sales.js b/cypress/integration/discounts/sales.js index e7cf022bb..1db94c181 100644 --- a/cypress/integration/discounts/sales.js +++ b/cypress/integration/discounts/sales.js @@ -40,7 +40,7 @@ filterTests({ definedTags: ["all"] }, () => { const name = `${startsWith}${faker.datatype.number()}`; productsUtils - .createTypeAttributeAndCategoryForProduct(name) + .createTypeAttributeAndCategoryForProduct({ name }) .then( ({ productType: productTypeResp, diff --git a/cypress/integration/discounts/vouchers.js b/cypress/integration/discounts/vouchers.js index a41b8b33e..8da728540 100644 --- a/cypress/integration/discounts/vouchers.js +++ b/cypress/integration/discounts/vouchers.js @@ -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" ); } }); diff --git a/cypress/integration/homePage/homePageAnalitics.js b/cypress/integration/homePage/homePageAnalitics.js index 8ad4b3f5e..e275f611f 100644 --- a/cypress/integration/homePage/homePageAnalitics.js +++ b/cypress/integration/homePage/homePageAnalitics.js @@ -72,7 +72,9 @@ filterTests({ definedTags: ["all", "critical"] }, () => { }) => { warehouse = warehouseResp; shippingMethod = shippingMethodResp; - productsUtils.createTypeAttributeAndCategoryForProduct(randomName); + productsUtils.createTypeAttributeAndCategoryForProduct({ + name: randomName + }); } ) .then( diff --git a/cypress/integration/metadata.js b/cypress/integration/metadata.js index 8853b1479..7d3a5d2ed 100644 --- a/cypress/integration/metadata.js +++ b/cypress/integration/metadata.js @@ -28,7 +28,7 @@ filterTests({ definedTags: ["all"] }, () => { getDefaultChannel() .then(channelResp => { channel = channelResp; - createTypeAttributeAndCategoryForProduct(name); + createTypeAttributeAndCategoryForProduct({ name }); }) .then(({ attribute, category, productType }) => { createProductInChannel({ diff --git a/cypress/integration/orders/draftOrders.js b/cypress/integration/orders/draftOrders.js index 916805196..47e0251f7 100644 --- a/cypress/integration/orders/draftOrders.js +++ b/cypress/integration/orders/draftOrders.js @@ -60,7 +60,9 @@ filterTests({ definedTags: ["all"] }, () => { }) .then(({ warehouse: warehouseResp }) => { warehouse = warehouseResp; - productsUtils.createTypeAttributeAndCategoryForProduct(randomName); + productsUtils.createTypeAttributeAndCategoryForProduct({ + name: randomName + }); }) .then( ({ diff --git a/cypress/integration/orders/orders.js b/cypress/integration/orders/orders.js index 34c74bd4e..cb5df7abe 100644 --- a/cypress/integration/orders/orders.js +++ b/cypress/integration/orders/orders.js @@ -82,7 +82,9 @@ filterTests({ definedTags: ["all"] }, () => { }) => { shippingMethod = shippingMethodResp; warehouse = warehouseResp; - productsUtils.createTypeAttributeAndCategoryForProduct(randomName); + productsUtils.createTypeAttributeAndCategoryForProduct({ + name: randomName + }); } ) .then( diff --git a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js index f74e8385d..1b71dccb7 100644 --- a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js +++ b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js @@ -45,7 +45,7 @@ filterTests({ definedTags: ["all"] }, () => { }); productsUtils - .createTypeAttributeAndCategoryForProduct(name) + .createTypeAttributeAndCategoryForProduct({ name }) .then( ({ attribute: attributeResp, diff --git a/cypress/integration/products/menageProducts/publishedProducts.js b/cypress/integration/products/menageProducts/publishedProducts.js index 89a95f1d6..52b8b32a4 100644 --- a/cypress/integration/products/menageProducts/publishedProducts.js +++ b/cypress/integration/products/menageProducts/publishedProducts.js @@ -25,7 +25,7 @@ filterTests({ definedTags: ["all"] }, () => { cy.clearSessionData().loginUserViaRequest(); productsUtils.deleteProductsStartsWith(startsWith); productsUtils - .createTypeAttributeAndCategoryForProduct(name) + .createTypeAttributeAndCategoryForProduct({ name }) .then( ({ attribute: attributeResp, diff --git a/cypress/integration/products/menageProducts/visibleInListingsProducts.js b/cypress/integration/products/menageProducts/visibleInListingsProducts.js index 3810c09f1..4461f6159 100644 --- a/cypress/integration/products/menageProducts/visibleInListingsProducts.js +++ b/cypress/integration/products/menageProducts/visibleInListingsProducts.js @@ -24,7 +24,7 @@ filterTests({ definedTags: ["all"] }, () => { cy.clearSessionData().loginUserViaRequest(); productsUtils.deleteProductsStartsWith(startsWith); productsUtils - .createTypeAttributeAndCategoryForProduct(name) + .createTypeAttributeAndCategoryForProduct({ name }) .then( ({ attribute: attributeResp, diff --git a/cypress/integration/products/productsList/filteringProducts.js b/cypress/integration/products/productsList/filteringProducts.js index 4c5666c84..9df0b555d 100644 --- a/cypress/integration/products/productsList/filteringProducts.js +++ b/cypress/integration/products/productsList/filteringProducts.js @@ -41,7 +41,7 @@ filterTests({ definedTags: ["all"] }, () => { cy.clearSessionData().loginUserViaRequest(); deleteShippingStartsWith(startsWith); deleteProductsStartsWith(startsWith); - createTypeAttributeAndCategoryForProduct(name).then( + createTypeAttributeAndCategoryForProduct({ name }).then( ({ attribute: attributeResp, productType: productTypeResp, diff --git a/cypress/integration/products/productsVariants.js b/cypress/integration/products/productsVariants.js index 15894e5ac..41dd15eb6 100644 --- a/cypress/integration/products/productsVariants.js +++ b/cypress/integration/products/productsVariants.js @@ -63,7 +63,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => { .then(resp => (newChannel = resp)); productUtils - .createTypeAttributeAndCategoryForProduct(name, attributeValues) + .createTypeAttributeAndCategoryForProduct({ name, attributeValues }) .then( ({ attribute: attributeResp, diff --git a/cypress/integration/products/updatingProducts.js b/cypress/integration/products/updatingProducts.js index 61748dda5..8e40bcd74 100644 --- a/cypress/integration/products/updatingProducts.js +++ b/cypress/integration/products/updatingProducts.js @@ -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; diff --git a/cypress/support/api/requests/Checkout.js b/cypress/support/api/requests/Checkout.js index e7847fd68..b48355db0 100644 --- a/cypress/support/api/requests/Checkout.js +++ b/cypress/support/api/requests/Checkout.js @@ -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 diff --git a/cypress/support/api/requests/GiftCard.js b/cypress/support/api/requests/GiftCard.js index 188c90439..3124c415d 100644 --- a/cypress/support/api/requests/GiftCard.js +++ b/cypress/support/api/requests/GiftCard.js @@ -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); +} diff --git a/cypress/support/api/requests/ProductType.js b/cypress/support/api/requests/ProductType.js index 07ff85e82..009c8d43c 100644 --- a/cypress/support/api/requests/ProductType.js +++ b/cypress/support/api/requests/ProductType.js @@ -28,7 +28,7 @@ export function createTypeProduct({ isShippingRequired:${shippable} ${kindLines} }){ - productErrors{ + errors{ field message } diff --git a/cypress/support/api/utils/categoryUtils.js b/cypress/support/api/utils/catalog/categoryUtils.js similarity index 64% rename from cypress/support/api/utils/categoryUtils.js rename to cypress/support/api/utils/catalog/categoryUtils.js index 7fa5afaa3..4f9cbba59 100644 --- a/cypress/support/api/utils/categoryUtils.js +++ b/cypress/support/api/utils/catalog/categoryUtils.js @@ -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); diff --git a/cypress/support/api/utils/collectionsUtils.js b/cypress/support/api/utils/catalog/collectionsUtils.js similarity index 63% rename from cypress/support/api/utils/collectionsUtils.js rename to cypress/support/api/utils/catalog/collectionsUtils.js index 24152ee48..70402fdb2 100644 --- a/cypress/support/api/utils/collectionsUtils.js +++ b/cypress/support/api/utils/catalog/collectionsUtils.js @@ -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); diff --git a/cypress/support/api/utils/catalog/giftCardUtils.js b/cypress/support/api/utils/catalog/giftCardUtils.js new file mode 100644 index 000000000..591189588 --- /dev/null +++ b/cypress/support/api/utils/catalog/giftCardUtils.js @@ -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); + }); + } + }); +} diff --git a/cypress/support/api/utils/misc.js b/cypress/support/api/utils/misc.js index 1d7191466..76122ad8b 100644 --- a/cypress/support/api/utils/misc.js +++ b/cypress/support/api/utils/misc.js @@ -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); +} diff --git a/cypress/support/api/utils/ordersUtils.js b/cypress/support/api/utils/ordersUtils.js index 5282f0433..4f1e0def2 100644 --- a/cypress/support/api/utils/ordersUtils.js +++ b/cypress/support/api/utils/ordersUtils.js @@ -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({ diff --git a/cypress/support/api/utils/products/productsUtils.js b/cypress/support/api/utils/products/productsUtils.js index 2735c15cc..058b6e0e3 100644 --- a/cypress/support/api/utils/products/productsUtils.js +++ b/cypress/support/api/utils/products/productsUtils.js @@ -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; diff --git a/cypress/support/customCommands/basicOperations/index.js b/cypress/support/customCommands/basicOperations/index.js index a2e0a7256..3784e1294 100644 --- a/cypress/support/customCommands/basicOperations/index.js +++ b/cypress/support/customCommands/basicOperations/index.js @@ -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; }); }); diff --git a/cypress/support/pages/catalog/giftCardPage.js b/cypress/support/pages/catalog/giftCardPage.js index e796ebafb..04ea29e5c 100644 --- a/cypress/support/pages/catalog/giftCardPage.js +++ b/cypress/support/pages/catalog/giftCardPage.js @@ -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(); +} diff --git a/package-lock.json b/package-lock.json index 626331617..83bdfafeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/src/giftCards/GiftCardUpdate/GiftCardUpdatePageHeader/GiftCardEnableDisableSection.tsx b/src/giftCards/GiftCardUpdate/GiftCardUpdatePageHeader/GiftCardEnableDisableSection.tsx index fb5fa3ac7..81654ae13 100644 --- a/src/giftCards/GiftCardUpdate/GiftCardUpdatePageHeader/GiftCardEnableDisableSection.tsx +++ b/src/giftCards/GiftCardUpdate/GiftCardUpdatePageHeader/GiftCardEnableDisableSection.tsx @@ -86,6 +86,7 @@ const GiftCardEnableDisableSection: React.FC = () => { return (