diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js index 16b7d2a30..69c10d7e2 100644 --- a/cypress/apiRequests/Product.js +++ b/cypress/apiRequests/Product.js @@ -1,4 +1,7 @@ +import Utils from "./utils/Utils"; + class Product { + utils = new Utils(); getFirstProducts(first, search) { const filter = search ? `, filter:{ @@ -23,13 +26,13 @@ class Product { .then(resp => resp.body.data.products.edges); } - updateChannelInProduct( + updateChannelInProduct({ productId, channelId, isPublished = true, isAvailableForPurchase = true, visibleInListings = true - ) { + }) { const mutation = `mutation{ productChannelListingUpdate(id:"${productId}", input:{ @@ -94,19 +97,36 @@ class Product { price = 1, costPrice = 1 ) { - const channelListings = channelId - ? `channelListings:{ + // const channelListings = channelId + // ? `channelListings:{ + // channelId:"${channelId}" + // price:"${price}" + // costPrice:"${costPrice}" + // }` + // : ""; + + const channelListings = this.utils.getValueWithDefault( + channelId, + `channelListings:{ channelId:"${channelId}" price:"${price}" costPrice:"${costPrice}" }` - : ""; - const stocks = warehouseId - ? `stocks:{ + ); + + const stocks = this.utils.getValueWithDefault( + warehouseId, + `stocks:{ warehouse:"${warehouseId}" quantity:${quantity} }` - : ""; + ); + // warehouseId + // ? `stocks:{ + // warehouse:"${warehouseId}" + // quantity:${quantity} + // }` + // : ""; const mutation = `mutation{ productVariantBulkCreate(product: "${productId}", variants: { diff --git a/cypress/apiRequests/utils/Utils.js b/cypress/apiRequests/utils/Utils.js new file mode 100644 index 000000000..cbb37b751 --- /dev/null +++ b/cypress/apiRequests/utils/Utils.js @@ -0,0 +1,6 @@ +class Utils { + getValueWithDefault(condition, value, defaultValue = "") { + return condition ? value : defaultValue; + } +} +export default Utils; diff --git a/cypress/integration/channels.js b/cypress/integration/channels.js index bfee7abae..0f64da273 100644 --- a/cypress/integration/channels.js +++ b/cypress/integration/channels.js @@ -44,10 +44,13 @@ describe("Channels", () => { it("should create new channel", () => { const randomChannel = `${channelStartsWith} ${faker.random.number()}`; - cy.visit(urlList.channels).waitForGraph("Channels"); + cy.addAliasToGraphRequest("Channels"); + cy.visit(urlList.channels); + cy.wait("@Channels"); + cy.addAliasToGraphRequest("Channel"); channelsSteps.createChannelByView(randomChannel, currency); // New channel should be visible in channels list - cy.waitForGraph("Channel") + cy.wait("@Channel") .get(ADD_CHANNEL_FORM_SELECTORS.backToChannelsList) .click() .get(CHANNELS_SELECTORS.channelsTable) @@ -62,7 +65,9 @@ describe("Channels", () => { .click(); // new channel should be visible at product availability form - cy.visit(urlList.products).waitForGraph("InitialProductFilterData"); + cy.addAliasToGraphRequest("InitialProductFilterData"); + cy.visit(urlList.products); + cy.wait("@InitialProductFilterData"); cy.get(PRODUCTS_SELECTORS.productsList) .first() .click() @@ -103,15 +108,18 @@ describe("Channels", () => { randomChannelToDelete, currency ); - cy.visit(urlList.channels).waitForGraph("Channels"); + cy.addAliasToGraphRequest("Channels"); + cy.visit(urlList.channels); + cy.wait("@Channels"); cy.get(CHANNELS_SELECTORS.channelName) .contains(randomChannelToDelete) .parentsUntil(CHANNELS_SELECTORS.channelsTable) .find("button") - .click() - .get(BUTTON_SELECTORS.submit) - .click() - .waitForGraph("Channels"); + .click(); + cy.addAliasToGraphRequest("Channels"); + cy.get(BUTTON_SELECTORS.submit).click(); + cy.wait("@Channels"); + cy.get(CHANNELS_SELECTORS.channelName) .contains(randomChannelToDelete) .should("not.exist"); diff --git a/cypress/integration/homePage.js b/cypress/integration/homePage.js index 483eb49cd..3712afd56 100644 --- a/cypress/integration/homePage.js +++ b/cypress/integration/homePage.js @@ -48,12 +48,12 @@ describe("Homepage analytics", () => { ) .then(resp => { customerId = resp.body.data.customerCreate.user.id; - shippingUtils.createShipping( - defaultChannel.id, - randomName, - addresses.plAddress, - shippingPrice - ); + shippingUtils.createShipping({ + channelId: defaultChannel.id, + name: randomName, + address: addresses.plAddress, + price: shippingPrice + }); }) .then(() => { productsUtils.createTypeAttributeAndCategoryForProduct(randomName); @@ -63,16 +63,16 @@ describe("Homepage analytics", () => { const productType = productsUtils.getProductType(); const attribute = productsUtils.getAttribute(); const category = productsUtils.getCategory(); - productsUtils.createProductInChannel( - randomName, - defaultChannel.id, - warehouse.id, - 20, - productType.id, - attribute.id, - category.id, - productPrice - ); + productsUtils.createProductInChannel({ + name: randomName, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + quantityInWarehouse: 20, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + price: productPrice + }); }); }); @@ -154,16 +154,16 @@ describe("Homepage analytics", () => { const attribute = productsUtils.getAttribute(); const category = productsUtils.getCategory(); - productsOutOfStockUtils.createProductInChannel( - productOutOfStockRandomName, - defaultChannel.id, - warehouse.id, - 0, - productType.id, - attribute.id, - category.id, - productPrice - ); + productsOutOfStockUtils.createProductInChannel({ + name: productOutOfStockRandomName, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + quantityInWarehouse: 0, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + price: productPrice + }); cy.get("@productsOutOfStock").then(productsOutOfStockBefore => { const allProductsOutOfStock = productsOutOfStockBefore + 1; diff --git a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js index 49026d110..b72d5aafd 100644 --- a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js +++ b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js @@ -34,12 +34,11 @@ describe("Products available in listings", () => { cy.fixture("addresses"); }) .then(addressesFixture => { - shippingUtils.createShipping( - defaultChannel, + shippingUtils.createShipping({ + channelId: defaultChannel.id, name, - addressesFixture.plAddress, - 10 - ); + address: addressesFixture.plAddress + }); }) .then(() => { warehouse = shippingUtils.getWarehouse(); @@ -59,19 +58,15 @@ describe("Products available in listings", () => { it("should update product to available for purchase", () => { const productName = `${startsWith}${faker.random.number()}`; productsUtils - .createProductInChannel( - productName, - defaultChannel.id, - warehouse.id, - 10, - productType.id, - attribute.id, - category.id, - 1, - true, - false, - true - ) + .createProductInChannel({ + name: productName, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + isAvailableForPurchase: false + }) .then(() => { const productUrl = `${urlList.products}${ productsUtils.getCreatedProduct().id @@ -92,33 +87,29 @@ describe("Products available in listings", () => { it("should update product to not available for purchase", () => { const productName = `${startsWith}${faker.random.number()}`; productsUtils - .createProductInChannel( - productName, - defaultChannel.id, - warehouse.id, - 10, - productType.id, - attribute.id, - category.id, - 1, - true, - true, - true - ) + .createProductInChannel({ + name: productName, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id + }) .then(() => { const productUrl = `${urlList.products}${ productsUtils.getCreatedProduct().id }`; productSteps.updateProductIsAvailableForPurchase(productUrl, false); - frontShopProductUtils - .isProductAvailableForPurchase( - productsUtils.getCreatedProduct().id, - defaultChannel.slug, - productName - ) - .then(isProductVisible => { - expect(isProductVisible).to.be.eq(false); - }); + }) + .then(() => { + frontShopProductUtils.isProductAvailableForPurchase( + productsUtils.getCreatedProduct().id, + defaultChannel.slug, + productName + ); + }) + .then(isProductVisible => { + expect(isProductVisible).to.be.eq(false); }); }); }); diff --git a/cypress/integration/products/menageProducts/publishedProducts.js b/cypress/integration/products/menageProducts/publishedProducts.js index 046b203ec..3c1d78f68 100644 --- a/cypress/integration/products/menageProducts/publishedProducts.js +++ b/cypress/integration/products/menageProducts/publishedProducts.js @@ -39,19 +39,15 @@ describe("Published products", () => { .getDefaultChannel() .then(channel => { defaultChannel = channel; - productsUtils.createProductInChannel( - productName, - defaultChannel.id, - null, - null, - productType.id, - attribute.id, - category.id, - 1, - false, - false, - true - ); + productsUtils.createProductInChannel({ + name: productName, + channelId: defaultChannel.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + isPublished: false, + isAvailableForPurchase: false + }); }) .then(() => { const product = productsUtils.getCreatedProduct(); @@ -76,15 +72,13 @@ describe("Published products", () => { .getDefaultChannel() .then(channel => { defaultChannel = channel; - productsUtils.createProductInChannel( - productName, - defaultChannel.id, - null, - null, - productType.id, - attribute.id, - category.id - ); + productsUtils.createProductInChannel({ + name: productName, + channelId: defaultChannel.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id + }); }) .then(() => { product = productsUtils.getCreatedProduct(); diff --git a/cypress/integration/products/menageProducts/visibleInListingsProducts.js b/cypress/integration/products/menageProducts/visibleInListingsProducts.js index b7af5d51c..c732a7111 100644 --- a/cypress/integration/products/menageProducts/visibleInListingsProducts.js +++ b/cypress/integration/products/menageProducts/visibleInListingsProducts.js @@ -39,19 +39,15 @@ describe("Products displayed in listings", () => { .getDefaultChannel() .then(channel => { defaultChannel = channel; - productsUtils.createProductInChannel( - productName, - defaultChannel.id, - null, - null, - productType.id, - attribute.id, - category.id, - 1, - true, - false, - false - ); + productsUtils.createProductInChannel({ + name: productName, + channelId: defaultChannel.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + visibleInListings: false, + isAvailableForPurchase: false + }); }) .then(() => { const product = productsUtils.getCreatedProduct(); @@ -73,19 +69,14 @@ describe("Products displayed in listings", () => { .getDefaultChannel() .then(channel => { defaultChannel = channel; - productsUtils.createProductInChannel( - productName, - defaultChannel.id, - null, - null, - productType.id, - attribute.id, - category.id, - 1, - true, - false, - true - ); + productsUtils.createProductInChannel({ + name: productName, + channelId: defaultChannel.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + visibleInListings: true + }); }) .then(() => { const product = productsUtils.getCreatedProduct(); diff --git a/cypress/steps/homePageSteps.js b/cypress/steps/homePageSteps.js index bd53c0972..72b9c6d96 100644 --- a/cypress/steps/homePageSteps.js +++ b/cypress/steps/homePageSteps.js @@ -1,12 +1,12 @@ import { HEADER_SELECTORS } from "../elements/header/header-selectors"; class HomePageSteps { changeChannel(channelName) { - cy.get(HEADER_SELECTORS.channelSelect) - .click() - .get(HEADER_SELECTORS.channelSelectList) + cy.get(HEADER_SELECTORS.channelSelect).click(); + cy.addAliasToGraphRequest("Home"); + cy.get(HEADER_SELECTORS.channelSelectList) .contains(channelName) - .click() - .waitForGraph("Home"); + .click(); + cy.wait("@Home"); } } export default HomePageSteps; diff --git a/cypress/steps/productSteps.js b/cypress/steps/productSteps.js index 244ab8392..eec8c3736 100644 --- a/cypress/steps/productSteps.js +++ b/cypress/steps/productSteps.js @@ -1,30 +1,20 @@ import { PRODUCTS_SELECTORS } from "../elements/catalog/product-selectors"; class ProductSteps { + valueTrue = PRODUCTS_SELECTORS.radioButtonsValueTrue; + valueFalse = PRODUCTS_SELECTORS.radioButtonsValueFalse; + updateProductIsAvailableForPurchase(productUrl, isAvailableForPurchase) { - let isAvailableForPurchaseSelector; - if (isAvailableForPurchase) { - isAvailableForPurchaseSelector = PRODUCTS_SELECTORS.radioButtonsValueTrue; - } else { - isAvailableForPurchaseSelector = - PRODUCTS_SELECTORS.radioButtonsValueFalse; - } - this.updateProductMenageInChannel( - productUrl, - `${PRODUCTS_SELECTORS.availableForPurchaseRadioButtons}${isAvailableForPurchaseSelector}` - ); + const isAvailableForPurchaseSelector = isAvailableForPurchase + ? this.valueTrue + : this.valueFalse; + const availableForPurchaseSelector = `${PRODUCTS_SELECTORS.availableForPurchaseRadioButtons}${isAvailableForPurchaseSelector}`; + this.updateProductMenageInChannel(productUrl, availableForPurchaseSelector); } updateProductPublish(productUrl, isPublished) { - let isPublishedSelector; - if (isPublished) { - isPublishedSelector = PRODUCTS_SELECTORS.radioButtonsValueTrue; - } else { - isPublishedSelector = PRODUCTS_SELECTORS.radioButtonsValueFalse; - } - this.updateProductMenageInChannel( - productUrl, - `${PRODUCTS_SELECTORS.publishedRadioButtons}${isPublishedSelector}` - ); + const isPublishedSelector = isPublished ? this.valueTrue : this.valueFalse; + const publishedSelector = `${PRODUCTS_SELECTORS.publishedRadioButtons}${isPublishedSelector}`; + this.updateProductMenageInChannel(productUrl, publishedSelector); } updateProductVisibleInListings(productUrl) { this.updateProductMenageInChannel( @@ -37,10 +27,11 @@ class ProductSteps { .get(PRODUCTS_SELECTORS.assignedChannels) .click() .get(menageSelector) + .click(); + cy.addAliasToGraphRequest("ProductChannelListingUpdate"); + cy.get(PRODUCTS_SELECTORS.saveBtn) .click() - .get(PRODUCTS_SELECTORS.saveBtn) - .click() - .waitForGraph("ProductChannelListingUpdate"); + .wait("@ProductChannelListingUpdate"); } } export default ProductSteps; diff --git a/cypress/support/index.js b/cypress/support/index.js index 01d098b68..76973c190 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -21,7 +21,7 @@ Cypress.Commands.add("clearSessionData", () => { }); }); -Cypress.Commands.add("waitForGraph", operationName => { +Cypress.Commands.add("addAliasToGraphRequest", operationName => { cy.intercept("POST", urlList.apiUri, req => { req.statusCode = 200; const requestBody = req.body; @@ -37,7 +37,6 @@ Cypress.Commands.add("waitForGraph", operationName => { } } }); - cy.wait(`@${operationName}`); }); Cypress.Commands.add("sendRequestWithQuery", query => { diff --git a/cypress/utils/productsUtils.js b/cypress/utils/productsUtils.js index c1c633bd1..2ac9f0ce7 100644 --- a/cypress/utils/productsUtils.js +++ b/cypress/utils/productsUtils.js @@ -22,28 +22,28 @@ class ProductsUtils { ).then(() => this.createVariant(this.product.id, name)); } - createProductInChannel( + createProductInChannel({ name, channelId, - warehouseId, - quantityInWarehouse, + warehouseId = null, + quantityInWarehouse = 10, productTypeId, attributeId, categoryId, - price, + price = 1, isPublished = true, isAvailableForPurchase = true, visibleInListings = true - ) { + }) { return this.createProduct(attributeId, name, productTypeId, categoryId) .then(() => - this.productRequest.updateChannelInProduct( - this.product.id, + this.productRequest.updateChannelInProduct({ + productId: this.product.id, channelId, isPublished, isAvailableForPurchase, visibleInListings - ) + }) ) .then(() => { this.createVariant( diff --git a/cypress/utils/shippingUtils.js b/cypress/utils/shippingUtils.js index 1fb352907..75eb7501f 100644 --- a/cypress/utils/shippingUtils.js +++ b/cypress/utils/shippingUtils.js @@ -8,7 +8,7 @@ class ShippingUtils { shippingZone; warehouse; - createShipping(channelId, name, address, price) { + createShipping({ channelId, name, address, price = 1 }) { return this.createShippingZone(name, address.country) .then(() => this.createWarehouse(name, this.shippingZone.id, address)) .then(() => this.createShippingRate(name, this.shippingZone.id))