From f7b452cb12d954390e70551e74845bf09b43e763 Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Tue, 5 Oct 2021 13:46:58 +0200 Subject: [PATCH] tests for warehouses in checkout (#1379) * tests for warehouses in checkout * fix puchase product with type --- .../elements/warehouses/warehouse-details.js | 8 +- cypress/integration/checkout/warehouses.js | 175 ++++++++++++++++-- .../integration/configuration/warehouse.js | 6 +- cypress/support/api/requests/Checkout.js | 15 +- cypress/support/api/requests/Warehouse.js | 1 + cypress/support/pages/warehousePage.js | 64 +++++++ 6 files changed, 243 insertions(+), 26 deletions(-) create mode 100644 cypress/support/pages/warehousePage.js diff --git a/cypress/elements/warehouses/warehouse-details.js b/cypress/elements/warehouses/warehouse-details.js index 1a634cabb..80ec23047 100644 --- a/cypress/elements/warehouses/warehouse-details.js +++ b/cypress/elements/warehouses/warehouse-details.js @@ -1,3 +1,9 @@ export const WAREHOUSES_DETAILS = { - nameInput: '[name="name"]' + nameInput: '[name="name"]', + privateRadioButton: '[name="isPrivate"][value=true]', + publicRadioButton: '[name="isPrivate"][value=false]', + clickAndCollectAllWarehousesRadioButton: + '[name="clickAndCollectOption"][value="ALL"]', + clickAndCollectLocalStockRadioButton: + '[name="clickAndCollectOption"][value="LOCAL"]' }; diff --git a/cypress/integration/checkout/warehouses.js b/cypress/integration/checkout/warehouses.js index f6a89ae20..aa343c8e0 100644 --- a/cypress/integration/checkout/warehouses.js +++ b/cypress/integration/checkout/warehouses.js @@ -15,6 +15,11 @@ import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils"; import filterTests from "../../support/filterTests"; +import { + pickupOptions, + visitAndEnablePickup, + visitSetPublicStockAndEnablePickup +} from "../../support/pages/warehousePage"; filterTests({ definedTags: ["all"] }, () => { describe("Warehouses in checkout", () => { @@ -22,13 +27,14 @@ filterTests({ definedTags: ["all"] }, () => { let defaultChannel; let usAddress; let plAddress; - let warehouse; + let productData; + let checkoutData; + let variantsInOtherWarehouse; - it("should not be possible to buy product for country not listed in warehouse", () => { + before(() => { cy.clearSessionData().loginUserViaRequest(); deleteShippingStartsWith(startsWith); deleteProductsStartsWith(startsWith); - const name = `${startsWith}${faker.datatype.number()}`; cy.fixture("addresses") .then(addresses => { usAddress = addresses.usAddress; @@ -37,35 +43,164 @@ filterTests({ definedTags: ["all"] }, () => { }) .then(channelResp => { defaultChannel = channelResp; - createShipping({ - channelId: defaultChannel.id, - name, - address: usAddress - }); - }) - .then(({ warehouse: warehouseResp }) => { - warehouse = warehouseResp; - createTypeAttributeAndCategoryForProduct({ name }); + createTypeAttributeAndCategoryForProduct({ name: startsWith }); }) .then(({ attribute, productType, category }) => { - createProductInChannel({ - name, + productData = { attributeId: attribute.id, categoryId: category.id, channelId: defaultChannel.id, productTypeId: productType.id, - warehouseId: warehouse.id, quantityInWarehouse: 100 - }); - }) - .then(({ variantsList }) => { - createCheckout({ + }; + checkoutData = { + returnAvailableCollectionPoints: true, channelSlug: defaultChannel.slug, email: "example@example.com", - variantsList, + address: plAddress + }; + createShipping({ + channelId: defaultChannel.id, + name: startsWith, address: plAddress }); }) + .then(({ warehouse: warehouseResp }) => { + productData.name = startsWith; + productData.warehouseId = warehouseResp.id; + createProductInChannel(productData); + }) + .then(({ variantsList }) => { + variantsInOtherWarehouse = variantsList; + }); + }); + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + }); + + it("should create warehouse with all warehouses pickup and private stock", () => { + const name = `${startsWith}${faker.datatype.number()}`; + let warehouse; + + createShipping({ + channelId: defaultChannel.id, + name, + address: plAddress + }) + .then(({ warehouse: warehouseResp }) => { + warehouse = warehouseResp; + visitAndEnablePickup(warehouse.id); + productData.name = name; + productData.warehouseId = warehouse.id; + createProductInChannel(productData); + }) + .then(({ variantsList }) => { + checkoutData.variantsList = variantsList.concat( + variantsInOtherWarehouse + ); + createCheckout(checkoutData); + }) + .then(({ checkout }) => { + const clickAndCollectOption = checkout.availableCollectionPoints[0]; + expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL"); + expect(clickAndCollectOption.id).to.eq(warehouse.id); + expect(clickAndCollectOption.isPrivate).to.eq(true); + expect(clickAndCollectOption.name).to.eq(warehouse.name); + }); + }); + + it("should create warehouse with all warehouses pickup and public stock", () => { + const name = `${startsWith}${faker.datatype.number()}`; + let warehouse; + + createShipping({ + channelId: defaultChannel.id, + name, + address: plAddress + }) + .then(({ warehouse: warehouseResp }) => { + warehouse = warehouseResp; + visitSetPublicStockAndEnablePickup(warehouse.id); + productData.name = name; + productData.warehouseId = warehouse.id; + createProductInChannel(productData); + }) + .then(({ variantsList }) => { + checkoutData.variantsList = variantsList.concat( + variantsInOtherWarehouse + ); + createCheckout(checkoutData); + }) + .then(({ checkout }) => { + const clickAndCollectOption = checkout.availableCollectionPoints[0]; + expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL"); + expect(clickAndCollectOption.id).to.eq(warehouse.id); + expect(clickAndCollectOption.isPrivate).to.eq(false); + expect(clickAndCollectOption.name).to.eq(warehouse.name); + }); + }); + + it("should create warehouse with local stock only pickup and public stock", () => { + const name = `${startsWith}${faker.datatype.number()}`; + let warehouse; + let variantsInLocalStock; + + createShipping({ + channelId: defaultChannel.id, + name, + address: plAddress + }) + .then(({ warehouse: warehouseResp }) => { + warehouse = warehouseResp; + visitSetPublicStockAndEnablePickup(warehouse.id, pickupOptions.local); + productData.name = name; + productData.warehouseId = warehouse.id; + createProductInChannel(productData); + }) + .then(({ variantsList }) => { + variantsInLocalStock = variantsList; + checkoutData.variantsList = variantsInLocalStock.concat( + variantsInOtherWarehouse + ); + createCheckout(checkoutData); + }) + .then(({ checkout }) => { + expect(checkout.availableCollectionPoints).to.have.length( + 0, + "there should be no available collection point" + ); + checkoutData.variantsList = variantsInLocalStock; + createCheckout(checkoutData); + }) + .then(({ checkout }) => { + const clickAndCollectOption = checkout.availableCollectionPoints[0]; + expect(clickAndCollectOption.clickAndCollectOption).to.eq("LOCAL"); + expect(clickAndCollectOption.id).to.eq(warehouse.id); + expect(clickAndCollectOption.isPrivate).to.eq(false); + expect(clickAndCollectOption.name).to.eq(warehouse.name); + }); + }); + + it("should not be possible to buy product for country not listed in warehouse", () => { + const name = `${startsWith}${faker.datatype.number()}`; + let warehouse; + + createShipping({ + channelId: defaultChannel.id, + name, + address: usAddress + }) + .then(({ warehouse: warehouseResp }) => { + warehouse = warehouseResp; + productData.name = name; + productData.warehouseId = warehouse.id; + createProductInChannel(productData); + }) + .then(({ variantsList }) => { + checkoutData.variantsList = variantsList; + createCheckout(checkoutData); + }) .then(({ errors }) => { expect(errors[0]).to.have.property("field", "quantity"); }); diff --git a/cypress/integration/configuration/warehouse.js b/cypress/integration/configuration/warehouse.js index f7145adba..ceda10f4a 100644 --- a/cypress/integration/configuration/warehouse.js +++ b/cypress/integration/configuration/warehouse.js @@ -14,7 +14,7 @@ import { } from "../../fixtures/urlList"; import { createShippingZone } from "../../support/api/requests/ShippingMethod"; import { - createWarehouse, + createWarehouse as createWarehouseViaApi, getWarehouse } from "../../support/api/requests/Warehouse"; import { getDefaultChannel } from "../../support/api/utils/channelsUtils"; @@ -70,7 +70,7 @@ filterTests({ definedTags: ["all"] }, () => { getDefaultChannel() .then(channelResp => { defaultChannel = channelResp; - createWarehouse({ + createWarehouseViaApi({ name, address: usAddress }); @@ -101,7 +101,7 @@ filterTests({ definedTags: ["all"] }, () => { it("should delete warehouse", () => { const name = `${startsWith}${faker.datatype.number()}`; - createWarehouse({ + createWarehouseViaApi({ name, address: usAddress }).then(warehouse => { diff --git a/cypress/support/api/requests/Checkout.js b/cypress/support/api/requests/Checkout.js index b48355db0..0cc41169c 100644 --- a/cypress/support/api/requests/Checkout.js +++ b/cypress/support/api/requests/Checkout.js @@ -12,7 +12,8 @@ export function createCheckout({ variantsList, address, billingAddress, - auth = "auth" + auth = "auth", + returnAvailableCollectionPoints = false }) { const lines = getVariantsLines(variantsList, productQuantity); const shippingAddress = getDefaultAddress(address, "shippingAddress"); @@ -21,6 +22,16 @@ export function createCheckout({ "billingAddress" ); + const availableCollectionPointsLines = getValueWithDefault( + returnAvailableCollectionPoints, + `availableCollectionPoints{ + id + name + clickAndCollectOption + isPrivate + }` + ); + const mutation = `mutation{ checkoutCreate(input:{ channel:"${channelSlug}" @@ -33,13 +44,13 @@ export function createCheckout({ field message } - created checkout{ id availableShippingMethods{ name } + ${availableCollectionPointsLines} } } }`; diff --git a/cypress/support/api/requests/Warehouse.js b/cypress/support/api/requests/Warehouse.js index ec2f9c320..2687f3f8a 100644 --- a/cypress/support/api/requests/Warehouse.js +++ b/cypress/support/api/requests/Warehouse.js @@ -62,6 +62,7 @@ export function getWarehouse(warehouseId) { warehouse(id:"${warehouseId}"){ id name + clickAndCollectOption address{ companyName streetAddress1 diff --git a/cypress/support/pages/warehousePage.js b/cypress/support/pages/warehousePage.js new file mode 100644 index 000000000..abee9d73a --- /dev/null +++ b/cypress/support/pages/warehousePage.js @@ -0,0 +1,64 @@ +import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; +import { WAREHOUSES_DETAILS } from "../../elements/warehouses/warehouse-details"; +import { WAREHOUSES_LIST } from "../../elements/warehouses/warehouses-list"; +import { urlList, warehouseDetailsUrl } from "../../fixtures/urlList"; + +export function createWarehouse({ name, address }) { + return cy + .visit(urlList.warehouses) + .get(WAREHOUSES_LIST.createNewButton) + .click() + .get(WAREHOUSES_DETAILS.nameInput) + .type(name) + .fillUpBasicAddress(address) + .addAliasToGraphRequest("WarehouseCreate") + .get(BUTTON_SELECTORS.confirm) + .click() + .wait("@WarehouseCreate") + .its("response.body.data.createWarehouse.warehouse"); +} + +export function visitAndEnablePickup( + warehouseId, + pickup = enableAllWarehousesPickup +) { + cy.visit(warehouseDetailsUrl(warehouseId)); + pickup(); + return saveWarehouseAfterUpdate(); +} + +export function visitSetPublicStockAndEnablePickup( + warehouseId, + pickup = enableAllWarehousesPickup +) { + cy.visit(warehouseDetailsUrl(warehouseId)) + .get(WAREHOUSES_DETAILS.publicRadioButton) + .click(); + pickup(); + return saveWarehouseAfterUpdate(); +} + +export function enableAllWarehousesPickup() { + return cy + .get(WAREHOUSES_DETAILS.clickAndCollectAllWarehousesRadioButton) + .click(); +} + +export function enableLocalStockOnlyPickup() { + return cy + .get(WAREHOUSES_DETAILS.clickAndCollectLocalStockRadioButton) + .click(); +} + +function saveWarehouseAfterUpdate() { + return cy + .addAliasToGraphRequest("WarehouseUpdate") + .get(BUTTON_SELECTORS.confirm) + .click() + .wait("@WarehouseUpdate"); +} + +export const pickupOptions = { + allWarehouses: enableAllWarehousesPickup, + local: enableLocalStockOnlyPickup +};