From 75d85e66cbaa77659bcf8c80f0be571bba1dd9fc Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Tue, 6 Jul 2021 12:33:04 +0200 Subject: [PATCH] test for product without shipping option (#1154) * test for product without shipping option * fix broken tests --- cypress/apiRequests/Checkout.js | 3 + cypress/apiRequests/ShippingMethod.js | 20 ++- .../allEnv/checkout/productWithoutShipping.js | 118 ++++++++++++++++++ .../allEnv/homePage/homePageAnalitics.js | 14 +-- .../productTypes/purchaseWithProductTypes.js | 8 +- cypress/utils/ordersUtils.js | 12 +- cypress/utils/shippingUtils.js | 17 ++- 7 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 cypress/integration/allEnv/checkout/productWithoutShipping.js diff --git a/cypress/apiRequests/Checkout.js b/cypress/apiRequests/Checkout.js index c131aa354..85c75347f 100644 --- a/cypress/apiRequests/Checkout.js +++ b/cypress/apiRequests/Checkout.js @@ -182,6 +182,9 @@ export function addProductsToCheckout( checkoutLinesUpdate(checkoutId:"${checkoutId}" lines:[${lines.join()}]){ checkout{ id + availableShippingMethods{ + name + } } errors{ field diff --git a/cypress/apiRequests/ShippingMethod.js b/cypress/apiRequests/ShippingMethod.js index 0e6ab0a65..91bc3c88c 100644 --- a/cypress/apiRequests/ShippingMethod.js +++ b/cypress/apiRequests/ShippingMethod.js @@ -1,15 +1,19 @@ import { getValueWithDefault } from "./utils/Utils"; -export function createShippingRate(name, shippingZone) { +export function createShippingRate({ name, shippingZoneId }) { const mutation = `mutation{ shippingPriceCreate(input:{ name: "${name}" - shippingZone: "${shippingZone}" + shippingZone: "${shippingZoneId}" type: PRICE }){ shippingMethod{ id } + errors{ + field + message + } } }`; return cy.sendRequestWithQuery(mutation); @@ -31,8 +35,8 @@ export function createShippingZone(name, country, channelId) { name } errors{ - message field + message } } }`; @@ -53,18 +57,24 @@ export function addChannelToShippingZone(shippingZoneId, channelId) { }`; return cy.sendRequestWithQuery(mutation); } -export function addChannelToShippingMethod(shippingRateId, channelId, price) { +export function addChannelToShippingMethod( + shippingRateId, + channelId, + price, + minProductPrice = 0 +) { const mutation = `mutation{ shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{ addChannels: { channelId:"${channelId}" price: ${price} + minimumOrderPrice:${minProductPrice} } }){ shippingMethod{ id } - shippingErrors{ + errors{ code message } diff --git a/cypress/integration/allEnv/checkout/productWithoutShipping.js b/cypress/integration/allEnv/checkout/productWithoutShipping.js new file mode 100644 index 000000000..aceafa7e0 --- /dev/null +++ b/cypress/integration/allEnv/checkout/productWithoutShipping.js @@ -0,0 +1,118 @@ +// + +import faker from "faker"; + +import { createChannel } from "../../../apiRequests/Channels"; +import { + addProductsToCheckout, + addShippingMethod, + createCheckout +} from "../../../apiRequests/Checkout"; +import { + createProductInChannel, + createTypeAttributeAndCategoryForProduct, + deleteProductsStartsWith +} from "../../../utils/products/productsUtils"; +import { + createShipping, + deleteShippingStartsWith +} from "../../../utils/shippingUtils"; + +describe("Products without shipment option", () => { + const startsWith = "WithoutShipmentCheckout-"; + const name = `${startsWith}${faker.datatype.number()}`; + const nameProdWithoutShipping = `${startsWith}${faker.datatype.number()}`; + + let channel; + let address; + let warehouse; + let shippingMethod; + let productWithShipping; + let productWithoutShipping; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + + deleteProductsStartsWith(startsWith); + deleteShippingStartsWith(startsWith); + + createChannel({ + name + }) + .then(channelResp => { + channel = channelResp; + cy.fixture("addresses"); + }) + .then(({ usAddress }) => { + address = usAddress; + createShipping({ + channelId: channel.id, + name, + address, + minProductPrice: 100 + }); + }) + .then( + ({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => { + warehouse = warehouseResp; + shippingMethod = shippingMethodResp; + createTypeAttributeAndCategoryForProduct(name); + } + ) + .then( + ({ + attribute: attributeResp, + productType: productTypeResp, + category: categoryResp + }) => { + createProductInChannel({ + attributeId: attributeResp.id, + categoryId: categoryResp.id, + channelId: channel.id, + name, + productTypeId: productTypeResp.id, + warehouseId: warehouse.id + }).then(({ variantsList }) => (productWithShipping = variantsList)); + createProductInChannel({ + attributeId: attributeResp.id, + categoryId: categoryResp.id, + channelId: channel.id, + name: nameProdWithoutShipping, + productTypeId: productTypeResp.id, + warehouseId: warehouse.id + }).then( + ({ variantsList }) => (productWithoutShipping = variantsList) + ); + } + ); + }); + + it("should be not possible to buy product without shipping option", () => { + createCheckout({ + channelSlug: channel.slug, + email: "example@example.com", + variantsList: productWithoutShipping, + address, + auth: "token" + }) + .then(({ checkout }) => { + expect( + checkout.availableShippingMethods, + "expect no available shipping" + ).to.have.length(0); + addProductsToCheckout(checkout.id, productWithShipping, 1); + }) + .then(({ checkout }) => { + expect( + checkout.availableShippingMethods, + "expect no available shipping" + ).to.have.length(0); + addShippingMethod(checkout.id, shippingMethod.id); + }) + .then(({ errors }) => { + expect(errors[0].field, "expect error in shipping method").to.be.eq( + "shippingMethod" + ); + }); + }); +}); diff --git a/cypress/integration/allEnv/homePage/homePageAnalitics.js b/cypress/integration/allEnv/homePage/homePageAnalitics.js index 41110c169..a5574b23e 100644 --- a/cypress/integration/allEnv/homePage/homePageAnalitics.js +++ b/cypress/integration/allEnv/homePage/homePageAnalitics.js @@ -136,13 +136,13 @@ describe("Homepage analytics", () => { .getOrdersReadyForCapture(defaultChannel.slug) .as("ordersReadyForCapture"); - createWaitingForCaptureOrder( - defaultChannel.slug, - randomEmail, - createdVariants, - shippingMethod.id, - addresses.plAddress - ); + createWaitingForCaptureOrder({ + channelSlug: defaultChannel.slug, + email: randomEmail, + variantsList: createdVariants, + shippingMethodId: shippingMethod.id, + address: addresses.plAddress + }); cy.get("@ordersReadyForCapture").then(ordersReadyForCaptureBefore => { const allOrdersReadyForCapture = ordersReadyForCaptureBefore + 1; diff --git a/cypress/integration/allEnv/productTypes/purchaseWithProductTypes.js b/cypress/integration/allEnv/productTypes/purchaseWithProductTypes.js index 9ccd1dd7c..1aa855fde 100644 --- a/cypress/integration/allEnv/productTypes/purchaseWithProductTypes.js +++ b/cypress/integration/allEnv/productTypes/purchaseWithProductTypes.js @@ -130,13 +130,13 @@ describe("Purchase products with all products types", () => { createProductInChannel(createProductData); }) .then(({ variantsList }) => { - createWaitingForCaptureOrder( - defaultChannel.slug, + createWaitingForCaptureOrder({ + channelSlug: defaultChannel.slug, email, variantsList, - shippingMethod.id, + shippingMethodId: shippingMethod.id, address - ); + }); }) .then(({ order }) => { getOrder(order.id); diff --git a/cypress/utils/ordersUtils.js b/cypress/utils/ordersUtils.js index 0a32b365e..7e2f00c06 100644 --- a/cypress/utils/ordersUtils.js +++ b/cypress/utils/ordersUtils.js @@ -2,13 +2,13 @@ import * as checkoutRequest from "../apiRequests/Checkout"; import * as orderRequest from "../apiRequests/Order"; import { createProductInChannel } from "./products/productsUtils"; -export function createWaitingForCaptureOrder( +export function createWaitingForCaptureOrder({ channelSlug, email, variantsList, shippingMethodId, address -) { +}) { let checkout; const auth = "token"; cy.loginInShop(); @@ -175,12 +175,12 @@ export function createOrderWithNewProduct({ quantityInWarehouse, trackInventory }).then(({ variantsList }) => - createWaitingForCaptureOrder( - channel.slug, - "email@example.com", + createWaitingForCaptureOrder({ + channelSlug: channel.slug, + email: "email@example.com", variantsList, shippingMethodId, address - ) + }) ); } diff --git a/cypress/utils/shippingUtils.js b/cypress/utils/shippingUtils.js index d49cd7b4f..b09ed06c1 100644 --- a/cypress/utils/shippingUtils.js +++ b/cypress/utils/shippingUtils.js @@ -1,7 +1,13 @@ import * as shippingMethodRequest from "../apiRequests/ShippingMethod"; import * as warehouseRequest from "../apiRequests/Warehouse"; -export function createShipping({ channelId, name, address, price = 1 }) { +export function createShipping({ + channelId, + name, + address, + price = 1, + minProductPrice = 0 +}) { let shippingMethod; let shippingZone; let warehouse; @@ -18,21 +24,22 @@ export function createShipping({ channelId, name, address, price = 1 }) { }) .then(warehouseResp => { warehouse = warehouseResp; - createShippingRate(name, shippingZone.id); + createShippingRate({ name, shippingZoneId: shippingZone.id }); }) .then(sippingMethodResp => { shippingMethod = sippingMethodResp; shippingMethodRequest.addChannelToShippingMethod( shippingMethod.id, channelId, - price + price, + minProductPrice ); }) .then(() => ({ shippingMethod, shippingZone, warehouse })); } -export function createShippingRate(name, shippingZoneId) { +export function createShippingRate({ name, shippingZoneId }) { return shippingMethodRequest - .createShippingRate(name, shippingZoneId) + .createShippingRate({ name, shippingZoneId }) .its("body.data.shippingPriceCreate.shippingMethod"); }