diff --git a/cypress/integration/checkout/giftCardsInCheckout.js b/cypress/integration/checkout/giftCardsInCheckout.js index 353bb7a93..0037e0d2c 100644 --- a/cypress/integration/checkout/giftCardsInCheckout.js +++ b/cypress/integration/checkout/giftCardsInCheckout.js @@ -100,7 +100,7 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => { address, auth: "token", channelSlug: defaultChannel.slug, - shippingMethodId: shippingMethod.id, + shippingMethodName: shippingMethod.name, variantsList: variants }; }); diff --git a/cypress/integration/checkout/purchaseWithProductTypes.js b/cypress/integration/checkout/purchaseWithProductTypes.js index 0f457bca0..ec8be33e8 100644 --- a/cypress/integration/checkout/purchaseWithProductTypes.js +++ b/cypress/integration/checkout/purchaseWithProductTypes.js @@ -13,7 +13,10 @@ import { createCheckout } from "../../support/api/requests/Checkout"; import { getOrder } from "../../support/api/requests/Order"; -import { createTypeProduct } from "../../support/api/requests/ProductType"; +import { + createDigitalContent, + createTypeProduct +} from "../../support/api/requests/ProductType"; import { getDefaultChannel } from "../../support/api/utils/channelsUtils"; import { addPayment, @@ -21,6 +24,7 @@ import { createWaitingForCaptureOrder } from "../../support/api/utils/ordersUtils"; import { + addDigitalContentAndUpdateProductType, createProductInChannel, deleteProductsStartsWith } from "../../support/api/utils/products/productsUtils"; @@ -94,6 +98,8 @@ filterTests({ definedTags: ["all", "critical"] }, () => { it("should purchase digital product", () => { const digitalName = `${startsWith}${faker.datatype.number()}`; + let variants; + createTypeProduct({ name: digitalName, attributeId: attribute.id, @@ -105,11 +111,19 @@ filterTests({ definedTags: ["all", "critical"] }, () => { createProductInChannel(createProductData); }) .then(({ variantsList }) => { + variants = variantsList; + addDigitalContentAndUpdateProductType( + variants[0].id, + createProductData.productTypeId, + defaultChannel.id + ); + }) + .then(() => { createAndCompleteCheckoutWithoutShipping({ channelSlug: defaultChannel.slug, email, billingAddress: address, - variantsList, + variantsList: variants, auth: "token" }); }) @@ -142,7 +156,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => { channelSlug: defaultChannel.slug, email, variantsList, - shippingMethodId: shippingMethod.id, + shippingMethodName: shippingMethod.name, address }); }) @@ -175,6 +189,9 @@ filterTests({ definedTags: ["all", "critical"] }, () => { }) .then(({ variantsList }) => { digitalProductVariantsList = variantsList; + createDigitalContent(variantsList[0].id); + }) + .then(() => { createCheckout({ channelSlug: defaultChannel.slug, email, diff --git a/cypress/integration/checkout/stocksInCheckout.js b/cypress/integration/checkout/stocksInCheckout.js index 81864b2a4..6619cd1cc 100644 --- a/cypress/integration/checkout/stocksInCheckout.js +++ b/cypress/integration/checkout/stocksInCheckout.js @@ -83,7 +83,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => { channel: defaultChannel, name: productName, warehouseId: warehouse.id, - shippingMethodId: shippingMethod.id, + shippingMethod, address }).then(({ order }) => { expect(order, "order should be created").to.be.ok; @@ -137,7 +137,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => { warehouseId: warehouse.id, quantityInWarehouse: 0, trackInventory: false, - shippingMethodId: shippingMethod.id, + shippingMethod, address }).then(({ order }) => { expect(order, "order should be created").to.be.ok; @@ -156,7 +156,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => { warehouseId: warehouse.id, quantityInWarehouse: 10, trackInventory: true, - shippingMethodId: shippingMethod.id, + shippingMethod, address }) .then(({ variantsList }) => { diff --git a/cypress/integration/discounts/vouchers.js b/cypress/integration/discounts/vouchers.js index a20ee5e59..e0165e13a 100644 --- a/cypress/integration/discounts/vouchers.js +++ b/cypress/integration/discounts/vouchers.js @@ -213,7 +213,7 @@ filterTests({ definedTags: ["all"] }, () => { channelSlug: defaultChannel.slug, variantsList: variants, address, - shippingMethodId: shippingMethod.id, + shippingMethodName: shippingMethod.name, voucherCode, auth: "token" }); diff --git a/cypress/integration/homePage/homePageAnalitics.js b/cypress/integration/homePage/homePageAnalitics.js index e275f611f..cce81c5e1 100644 --- a/cypress/integration/homePage/homePageAnalitics.js +++ b/cypress/integration/homePage/homePageAnalitics.js @@ -153,7 +153,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => { channelSlug: defaultChannel.slug, email: randomEmail, variantsList: createdVariants, - shippingMethodId: shippingMethod.id, + shippingMethodName: shippingMethod.name, address: addresses.plAddress }); diff --git a/cypress/support/api/requests/Checkout.js b/cypress/support/api/requests/Checkout.js index a39299712..1ad5ce50d 100644 --- a/cypress/support/api/requests/Checkout.js +++ b/cypress/support/api/requests/Checkout.js @@ -51,6 +51,7 @@ export function createCheckout({ token availableShippingMethods{ name + id } lines{ variant{ @@ -249,3 +250,7 @@ export function addProductsToCheckout( }`; return cy.sendRequestWithQuery(mutation).its("body.data.checkoutLinesUpdate"); } + +export function getCheckout(checkoutId) { + const mutation = ``; +} diff --git a/cypress/support/api/requests/Product.js b/cypress/support/api/requests/Product.js index 76d7c09fe..adaf4ef44 100644 --- a/cypress/support/api/requests/Product.js +++ b/cypress/support/api/requests/Product.js @@ -313,7 +313,21 @@ export function activatePreorderOnVariant(variantId, threshold, endDate) { preorder:{ ${thresholdLine} ${endDateLine} + }errors{ + field + message } + } + }`; + return cy.sendRequestWithQuery(mutation); +} + +export function updateVariantPrice({ variantId, channelId, price }) { + const mutation = `mutation { + productVariantChannelListingUpdate(id:"${variantId}", input:{ + channelId:"${channelId}" + price:${price} + costPrice:${price} }){ errors{ field diff --git a/cypress/support/api/requests/ProductType.js b/cypress/support/api/requests/ProductType.js index d6e85c604..efe9e6dcc 100644 --- a/cypress/support/api/requests/ProductType.js +++ b/cypress/support/api/requests/ProductType.js @@ -22,6 +22,7 @@ export function createTypeProduct({ productTypeCreate(input: { name: "${name}" slug: "${slug}" + isDigital: ${!shippable} ${productAttributesLine} hasVariants: ${hasVariants} ${variantAttributesLine} @@ -109,3 +110,36 @@ export function getProductType(productTypeId) { }`; return cy.sendRequestWithQuery(query).its("body.data.productType"); } + +export function createDigitalContent(variantId) { + const mutation = `mutation{ + digitalContentCreate(input:{ + useDefaultSettings:true, + automaticFulfillment: true, + contentFile:"" + }, variantId:"${variantId}"){ + content{ + id + } + errors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); +} + +export function setProductTypeAsDigital(productTypeId, isDigital = true) { + const mutation = `mutation updateProductType{ + productTypeUpdate(id:"${productTypeId}", input:{ + isDigital:${isDigital} + }){ + errors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); +} diff --git a/cypress/support/api/requests/ShippingMethod.js b/cypress/support/api/requests/ShippingMethod.js index 9792f67fa..4649e46cb 100644 --- a/cypress/support/api/requests/ShippingMethod.js +++ b/cypress/support/api/requests/ShippingMethod.js @@ -26,6 +26,7 @@ export function createShippingRate({ }){ shippingMethod{ id + name } errors{ field diff --git a/cypress/support/api/requests/storeFront/ProductDetails.js b/cypress/support/api/requests/storeFront/ProductDetails.js index 114bb4899..91f9c0bfc 100644 --- a/cypress/support/api/requests/storeFront/ProductDetails.js +++ b/cypress/support/api/requests/storeFront/ProductDetails.js @@ -1,6 +1,6 @@ import { getValueWithDefault } from "../utils/Utils"; -export function getProductDetails(productId, channelId, auth = "token") { +export function getProductDetails(productId, channelSlug, auth = "token") { const privateMetadataLine = getValueWithDefault( auth === "auth", `privateMetadata{key value}` @@ -36,6 +36,7 @@ export function getProductDetails(productId, channelId, auth = "token") { productType{ id name + isDigital } } @@ -62,7 +63,7 @@ export function getProductDetails(productId, channelId, auth = "token") { } query ProductDetails{ - product(id: "${productId}", channel: "${channelId}") { + product(id: "${productId}", channel: "${channelSlug}") { ...BasicProductFields variants { ...ProductVariantFields diff --git a/cypress/support/api/utils/ordersUtils.js b/cypress/support/api/utils/ordersUtils.js index ccf63ae99..aa8cdcaed 100644 --- a/cypress/support/api/utils/ordersUtils.js +++ b/cypress/support/api/utils/ordersUtils.js @@ -10,7 +10,7 @@ export function createWaitingForCaptureOrder({ channelSlug, email, variantsList, - shippingMethodId, + shippingMethodName, address }) { let checkout; @@ -27,6 +27,10 @@ export function createWaitingForCaptureOrder({ }) .then(({ checkout: checkoutResp }) => { checkout = checkoutResp; + const shippingMethodId = getShippingMethodIdFromCheckout( + checkout, + shippingMethodName + ); checkoutRequest.addShippingMethod(checkout.id, shippingMethodId); }) .then(() => addPayment(checkout.id)) @@ -34,12 +38,18 @@ export function createWaitingForCaptureOrder({ .then(({ order }) => ({ checkout, order })); } +export function getShippingMethodIdFromCheckout(checkout, shippingMethodName) { + return checkout.availableShippingMethods.find( + element => element.name === shippingMethodName + ).id; +} + export function createCheckoutWithVoucher({ channelSlug, email = "email@example.com", variantsList, address, - shippingMethodId, + shippingMethodName, voucherCode, auth }) { @@ -55,6 +65,10 @@ export function createCheckoutWithVoucher({ }) .then(({ checkout: checkoutResp }) => { checkout = checkoutResp; + const shippingMethodId = getShippingMethodIdFromCheckout( + checkout, + shippingMethodName + ); checkoutRequest.addShippingMethod(checkout.id, shippingMethodId); }) .then(() => { @@ -71,7 +85,7 @@ export function purchaseProductWithPromoCode({ email = "email@example.com", variantsList, address, - shippingMethodId, + shippingMethod, voucherCode, auth }) { @@ -82,7 +96,7 @@ export function purchaseProductWithPromoCode({ email, variantsList, address, - shippingMethodId, + shippingMethodName: shippingMethod.name, voucherCode, auth }) @@ -212,7 +226,7 @@ export function createOrderWithNewProduct({ warehouseId, quantityInWarehouse = 1, trackInventory = true, - shippingMethodId, + shippingMethod, address }) { let variantsList; @@ -232,7 +246,7 @@ export function createOrderWithNewProduct({ channelSlug: channel.slug, email: "email@example.com", variantsList, - shippingMethodId, + shippingMethodName: shippingMethod.name, address }); }) diff --git a/cypress/support/api/utils/products/productsUtils.js b/cypress/support/api/utils/products/productsUtils.js index 110b27ca9..15201c4ee 100644 --- a/cypress/support/api/utils/products/productsUtils.js +++ b/cypress/support/api/utils/products/productsUtils.js @@ -4,10 +4,12 @@ import * as categoryRequest from "../../requests/Category"; import { createCollection } from "../../requests/Collections"; import * as productRequest from "../../requests/Product"; import { + createDigitalContent, createTypeProduct, deleteProductType, getProductTypes, - productAttributeAssignmentUpdate + productAttributeAssignmentUpdate, + setProductTypeAsDigital } from "../../requests/ProductType"; import { deleteAttributesStartsWith } from "../attributes/attributeUtils"; import { deleteCollectionsStartsWith } from "../catalog/collectionsUtils"; @@ -251,3 +253,14 @@ export function createProductInChannelWithoutVariants({ }) .then(() => product); } + +export function addDigitalContentAndUpdateProductType( + variantId, + productTypeId, + channelId, + price = 1 +) { + createDigitalContent(variantId); + setProductTypeAsDigital(productTypeId); + productRequest.updateVariantPrice({ variantId, channelId, price }); +}