From 39c1e8e208c5d731c93f7086c148c28873f0bcd7 Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Thu, 21 Oct 2021 12:45:38 +0200 Subject: [PATCH] tests for click & collect (#1488) --- cypress/fixtures/addresses.json | 2 +- cypress/integration/checkout/warehouses.js | 71 ++++++++++++++++--- .../{ => warehouses}/warehouse.js | 22 +++--- cypress/support/api/requests/Checkout.js | 13 ++++ cypress/support/api/requests/Order.js | 18 +++++ cypress/support/api/requests/Warehouse.js | 18 +++++ 6 files changed, 121 insertions(+), 23 deletions(-) rename cypress/integration/configuration/{ => warehouses}/warehouse.js (81%) diff --git a/cypress/fixtures/addresses.json b/cypress/fixtures/addresses.json index ece8d029a..d819479a5 100644 --- a/cypress/fixtures/addresses.json +++ b/cypress/fixtures/addresses.json @@ -37,7 +37,7 @@ "postalCode": "70958", "country": "US", "countryArea": "LA", - "phone": "2025550189", + "phone": "+12025550169", "currency": "USD", "countryFullName": "United States of America" } diff --git a/cypress/integration/checkout/warehouses.js b/cypress/integration/checkout/warehouses.js index aa343c8e0..8e2bcb7d3 100644 --- a/cypress/integration/checkout/warehouses.js +++ b/cypress/integration/checkout/warehouses.js @@ -3,8 +3,16 @@ import faker from "faker"; -import { createCheckout } from "../../support/api/requests/Checkout"; +import { WAREHOUSES_DETAILS } from "../../elements/warehouses/warehouse-details"; +import { + completeCheckout, + createCheckout, + deliveryMethodUpdate +} from "../../support/api/requests/Checkout"; +import { getOrder } from "../../support/api/requests/Order"; +import { updateWarehouse } from "../../support/api/requests/Warehouse"; import { getDefaultChannel } from "../../support/api/utils/channelsUtils"; +import { addPayment } from "../../support/api/utils/ordersUtils"; import { createProductInChannel, createTypeAttributeAndCategoryForProduct, @@ -16,6 +24,7 @@ import { } from "../../support/api/utils/shippingUtils"; import filterTests from "../../support/filterTests"; import { + createWarehouse, pickupOptions, visitAndEnablePickup, visitSetPublicStockAndEnablePickup @@ -26,6 +35,7 @@ filterTests({ definedTags: ["all"] }, () => { const startsWith = `CyWarehouseCheckout`; let defaultChannel; let usAddress; + let secondUsAddress; let plAddress; let productData; let checkoutData; @@ -38,6 +48,7 @@ filterTests({ definedTags: ["all"] }, () => { cy.fixture("addresses") .then(addresses => { usAddress = addresses.usAddress; + secondUsAddress = addresses.secondUsAddress; plAddress = addresses.plAddress; getDefaultChannel(); }) @@ -57,17 +68,18 @@ filterTests({ definedTags: ["all"] }, () => { returnAvailableCollectionPoints: true, channelSlug: defaultChannel.slug, email: "example@example.com", - address: plAddress + address: secondUsAddress }; createShipping({ channelId: defaultChannel.id, name: startsWith, - address: plAddress + address: secondUsAddress }); }) .then(({ warehouse: warehouseResp }) => { productData.name = startsWith; productData.warehouseId = warehouseResp.id; + updateWarehouse({ id: productData.warehouseId, isPrivate: false }); createProductInChannel(productData); }) .then(({ variantsList }) => { @@ -86,7 +98,7 @@ filterTests({ definedTags: ["all"] }, () => { createShipping({ channelId: defaultChannel.id, name, - address: plAddress + address: secondUsAddress }) .then(({ warehouse: warehouseResp }) => { warehouse = warehouseResp; @@ -102,7 +114,9 @@ filterTests({ definedTags: ["all"] }, () => { createCheckout(checkoutData); }) .then(({ checkout }) => { - const clickAndCollectOption = checkout.availableCollectionPoints[0]; + const clickAndCollectOption = checkout.availableCollectionPoints.find( + element => element.id === warehouse.id + ); expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL"); expect(clickAndCollectOption.id).to.eq(warehouse.id); expect(clickAndCollectOption.isPrivate).to.eq(true); @@ -117,7 +131,7 @@ filterTests({ definedTags: ["all"] }, () => { createShipping({ channelId: defaultChannel.id, name, - address: plAddress + address: secondUsAddress }) .then(({ warehouse: warehouseResp }) => { warehouse = warehouseResp; @@ -133,7 +147,9 @@ filterTests({ definedTags: ["all"] }, () => { createCheckout(checkoutData); }) .then(({ checkout }) => { - const clickAndCollectOption = checkout.availableCollectionPoints[0]; + const clickAndCollectOption = checkout.availableCollectionPoints.find( + element => element.id === warehouse.id + ); expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL"); expect(clickAndCollectOption.id).to.eq(warehouse.id); expect(clickAndCollectOption.isPrivate).to.eq(false); @@ -149,7 +165,7 @@ filterTests({ definedTags: ["all"] }, () => { createShipping({ channelId: defaultChannel.id, name, - address: plAddress + address: secondUsAddress }) .then(({ warehouse: warehouseResp }) => { warehouse = warehouseResp; @@ -167,8 +183,8 @@ filterTests({ definedTags: ["all"] }, () => { }) .then(({ checkout }) => { expect(checkout.availableCollectionPoints).to.have.length( - 0, - "there should be no available collection point" + 1, + "there should be no available collection point for local stock" ); checkoutData.variantsList = variantsInLocalStock; createCheckout(checkoutData); @@ -182,6 +198,39 @@ filterTests({ definedTags: ["all"] }, () => { }); }); + it("should not be possible to set local pickup when private stock", () => { + const name = `${startsWith}${faker.datatype.number()}`; + createWarehouse({ name, address: usAddress }); + cy.get(WAREHOUSES_DETAILS.clickAndCollectLocalStockRadioButton).should( + "not.exist" + ); + }); + + it("should create order with warehouse address", () => { + const name = `${startsWith}${faker.datatype.number()}`; + let checkout; + checkoutData.variantsList = variantsInOtherWarehouse; + createCheckout(checkoutData) + .then(({ checkout: checkoutResp }) => { + checkout = checkoutResp; + const clickAndCollectOption = checkout.availableCollectionPoints[0]; + deliveryMethodUpdate(clickAndCollectOption.id, checkout.token); + }) + .then(() => { + addPayment(checkout.id); + }) + .then(() => { + completeCheckout(checkout.id); + }) + .then(({ order }) => { + getOrder(order.id); + }) + .then(order => { + cy.expectCorrectBasicAddress(order.shippingAddress, secondUsAddress); + cy.expectCorrectBasicAddress(order.billingAddress, usAddress); + }); + }); + it("should not be possible to buy product for country not listed in warehouse", () => { const name = `${startsWith}${faker.datatype.number()}`; let warehouse; @@ -189,7 +238,7 @@ filterTests({ definedTags: ["all"] }, () => { createShipping({ channelId: defaultChannel.id, name, - address: usAddress + address: plAddress }) .then(({ warehouse: warehouseResp }) => { warehouse = warehouseResp; diff --git a/cypress/integration/configuration/warehouse.js b/cypress/integration/configuration/warehouses/warehouse.js similarity index 81% rename from cypress/integration/configuration/warehouse.js rename to cypress/integration/configuration/warehouses/warehouse.js index ceda10f4a..dcf035ac5 100644 --- a/cypress/integration/configuration/warehouse.js +++ b/cypress/integration/configuration/warehouses/warehouse.js @@ -1,25 +1,25 @@ /// -/// +/// import faker from "faker"; -import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; -import { SHIPPING_ZONE_DETAILS } from "../../elements/shipping/shipping-zone-details"; -import { WAREHOUSES_DETAILS } from "../../elements/warehouses/warehouse-details"; -import { WAREHOUSES_LIST } from "../../elements/warehouses/warehouses-list"; +import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; +import { SHIPPING_ZONE_DETAILS } from "../../../elements/shipping/shipping-zone-details"; +import { WAREHOUSES_DETAILS } from "../../../elements/warehouses/warehouse-details"; +import { WAREHOUSES_LIST } from "../../../elements/warehouses/warehouses-list"; import { shippingZoneDetailsUrl, urlList, warehouseDetailsUrl -} from "../../fixtures/urlList"; -import { createShippingZone } from "../../support/api/requests/ShippingMethod"; +} from "../../../fixtures/urlList"; +import { createShippingZone } from "../../../support/api/requests/ShippingMethod"; import { createWarehouse as createWarehouseViaApi, getWarehouse -} from "../../support/api/requests/Warehouse"; -import { getDefaultChannel } from "../../support/api/utils/channelsUtils"; -import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils"; -import filterTests from "../../support/filterTests"; +} from "../../../support/api/requests/Warehouse"; +import { getDefaultChannel } from "../../../support/api/utils/channelsUtils"; +import { deleteShippingStartsWith } from "../../../support/api/utils/shippingUtils"; +import filterTests from "../../../support/filterTests"; filterTests({ definedTags: ["all"] }, () => { describe("Warehouse settings", () => { diff --git a/cypress/support/api/requests/Checkout.js b/cypress/support/api/requests/Checkout.js index 0cc41169c..6ba9f75d0 100644 --- a/cypress/support/api/requests/Checkout.js +++ b/cypress/support/api/requests/Checkout.js @@ -46,6 +46,7 @@ export function createCheckout({ } created checkout{ + token id availableShippingMethods{ name @@ -85,6 +86,18 @@ export function addShippingMethod(checkoutId, shippingMethodId) { .its("body.data.checkoutShippingMethodUpdate"); } +export function deliveryMethodUpdate(deliveryMethodId, checkoutToken) { + const mutation = `mutation{ + checkoutDeliveryMethodUpdate(deliveryMethodId:"${deliveryMethodId}", token:"${checkoutToken}"){ + errors{ + field + message + } + } + }`; + cy.sendRequestWithQuery(mutation); +} + export function addPayment({ checkoutId, gateway, token, amount }) { const tokenLine = getValueWithDefault(token, `token:"${token}"`); const amountLine = getValueWithDefault(amount, `amount: ${amount}`); diff --git a/cypress/support/api/requests/Order.js b/cypress/support/api/requests/Order.js index 800945a8a..ea4c658cc 100644 --- a/cypress/support/api/requests/Order.js +++ b/cypress/support/api/requests/Order.js @@ -108,6 +108,24 @@ export function getOrder(orderId) { key value } + shippingAddress{ + companyName + streetAddress1 + streetAddress2 + city + postalCode + countryArea + phone + } + billingAddress{ + companyName + streetAddress1 + streetAddress2 + city + postalCode + countryArea + phone + } } }`; cy.sendRequestWithQuery(query).its("body.data.order"); diff --git a/cypress/support/api/requests/Warehouse.js b/cypress/support/api/requests/Warehouse.js index 2687f3f8a..b052924df 100644 --- a/cypress/support/api/requests/Warehouse.js +++ b/cypress/support/api/requests/Warehouse.js @@ -83,3 +83,21 @@ export function getWarehouse(warehouseId) { }`; return cy.sendRequestWithQuery(query).its("body.data.warehouse"); } +export function updateWarehouse({ + id, + isPrivate, + clickAndCollectOption = "ALL" +}) { + const mutation = `mutation{ + updateWarehouse(id:"${id}" input:{ + isPrivate:${isPrivate} + clickAndCollectOption:${clickAndCollectOption} + }){ + errors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation).its("body.data"); +}