From a33b13aaa20914bda12b89ad811cdbc59c21ac5f Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Thu, 18 Feb 2021 19:28:01 +0100 Subject: [PATCH] tests for available for purchase --- cypress/apiRequests/Product.js | 21 +++--- .../products/availableForPurchaseProducts.js | 72 ++++++++++--------- .../integration/products/publishedProducts.js | 27 ++++--- cypress/utils/productsUtils.js | 17 ++++- 4 files changed, 84 insertions(+), 53 deletions(-) diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js index e0b41cdb3..b3cfdcbe0 100644 --- a/cypress/apiRequests/Product.js +++ b/cypress/apiRequests/Product.js @@ -46,6 +46,7 @@ class Product { } } }`; + cy.sendRequestWithQuery(mutation); } updateChannelPriceInVariant(variantId, channelId) { @@ -106,16 +107,16 @@ class Product { warehouse: "${warehouseId}" quantity: ${quantity} } -}) { - productVariants{ - id - name - } - bulkProductErrors{ - field - message - } -} + }) { + productVariants{ + id + name + } + bulkProductErrors{ + field + message + } + } }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/integration/products/availableForPurchaseProducts.js b/cypress/integration/products/availableForPurchaseProducts.js index 44d34d70f..c08b0f103 100644 --- a/cypress/integration/products/availableForPurchaseProducts.js +++ b/cypress/integration/products/availableForPurchaseProducts.js @@ -27,16 +27,24 @@ describe("Products available in listings", () => { shippingUtils.deleteShipping(startsWith); productsUtils.deleteProperProducts(startsWith); - channelsUtils.getDefaultChannel().then(channel => { - defaultChannel = channel; - cy.fixture("addresses").then(json => { - shippingUtils - .createShipping(defaultChannel, name, json.plAddress, 10) - .then(() => { - warehouse = shippingUtils.getWarehouse(); - }); + channelsUtils + .getDefaultChannel() + .then(channel => { + defaultChannel = channel; + cy.fixture("addresses"); + }) + .then(addressesFixture => { + shippingUtils.createShipping( + defaultChannel, + name, + addressesFixture.plAddress, + 10 + ); + }) + .then(() => { + warehouse = shippingUtils.getWarehouse(); }); - }); + productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => { productType = productsUtils.getProductType(); attribute = productsUtils.getAttribute(); @@ -50,7 +58,6 @@ describe("Products available in listings", () => { it("should update product to available for purchase", () => { const productName = `${startsWith}${faker.random.number()}`; - productsUtils.createProductInChannel(productName); productsUtils .createProductInChannel( productName, @@ -59,26 +66,27 @@ describe("Products available in listings", () => { 10, productType.id, attribute.id, - category, + category.id, + 1, true, false, - true, - 1 + true ) .then(() => { - const productUrl = `${ - URL_LIST.products - }${productsUtils.getCreatedProductId()}`; + const productUrl = `${URL_LIST.products}${ + productsUtils.getCreatedProduct().id + }`; productSteps.updateProductIsAvailableForPurchase(productUrl, true); - frontShopProductUtils - .isProductAvailableForPurchase( - productsUtils.getCreatedProductId(), - defaultChannel.slug, - productName - ) - .then(isProductVisible => { - expect(isProductVisible).to.be.eq(true); - }); + }) + .then(() => { + frontShopProductUtils.isProductAvailableForPurchase( + productsUtils.getCreatedProduct().id, + defaultChannel.slug, + productName + ); + }) + .then(isProductVisible => { + expect(isProductVisible).to.be.eq(true); }); }); it("should update product to not available for purchase", () => { @@ -91,20 +99,20 @@ describe("Products available in listings", () => { 10, productType.id, attribute.id, - category, + category.id, + 1, true, true, - true, - 1 + true ) .then(() => { - const productUrl = `${ - URL_LIST.products - }${productsUtils.getCreatedProductId()}`; + const productUrl = `${URL_LIST.products}${ + productsUtils.getCreatedProduct().id + }`; productSteps.updateProductIsAvailableForPurchase(productUrl, false); frontShopProductUtils .isProductAvailableForPurchase( - productsUtils.getCreatedProductId(), + productsUtils.getCreatedProduct().id, defaultChannel.slug, productName ) diff --git a/cypress/integration/products/publishedProducts.js b/cypress/integration/products/publishedProducts.js index 031437342..3e3b441fe 100644 --- a/cypress/integration/products/publishedProducts.js +++ b/cypress/integration/products/publishedProducts.js @@ -38,20 +38,23 @@ describe("Publish products", () => { productsUtils .createProductInChannel( productName, + defaultChannel.id, + null, + null, productType.id, attribute.id, category.id, - defaultChannel.id, + null, false, false, true ) .then(() => { - const productId = productsUtils.getCreatedProductId(); - const productUrl = `${URL_LIST.products}${productId}`; + const product = productsUtils.getCreatedProduct(); + const productUrl = `${URL_LIST.products}${product.id}`; productSteps.updateProductPublish(productUrl, true); frontShopProductUtils - .isProductVisible(productId, defaultChannel.slug, productName) + .isProductVisible(product.id, defaultChannel.slug, productName) .then(isVisible => { expect(isVisible).to.be.eq(true); }); @@ -68,13 +71,21 @@ describe("Publish products", () => { attribute.id, category.id, defaultChannel.id, - true, + productName, + defaultChannel.id, + null, + null, + productType.id, + attribute.id, + category.id, + null, + false, false, true ) .then(() => { - const productId = productsUtils.getCreatedProductId(); - const productUrl = `${URL_LIST.products}${productId}`; + const product = productsUtils.getCreatedProduct(); + const productUrl = `${URL_LIST.products}${product.id}`; productSteps.updateProductPublish(productUrl, false); frontShopProductUtils .isProductVisible(productId, defaultChannel.slug, productName) @@ -83,7 +94,7 @@ describe("Publish products", () => { }); cy.loginInShop().then(() => { frontShopProductUtils - .isProductVisible(productId, defaultChannel.slug, productName) + .isProductVisible(product.id, defaultChannel.slug, productName) .then(isVisible => { expect(isVisible).to.be.eq(true); }); diff --git a/cypress/utils/productsUtils.js b/cypress/utils/productsUtils.js index a134e7c53..c1c633bd1 100644 --- a/cypress/utils/productsUtils.js +++ b/cypress/utils/productsUtils.js @@ -30,11 +30,20 @@ class ProductsUtils { productTypeId, attributeId, categoryId, - price + price, + isPublished = true, + isAvailableForPurchase = true, + visibleInListings = true ) { return this.createProduct(attributeId, name, productTypeId, categoryId) .then(() => - this.productRequest.updateChannelInProduct(this.product.id, channelId) + this.productRequest.updateChannelInProduct( + this.product.id, + channelId, + isPublished, + isAvailableForPurchase, + visibleInListings + ) ) .then(() => { this.createVariant( @@ -101,7 +110,9 @@ class ProductsUtils { resp.body.data.productVariantBulkCreate.productVariants) ); } - + getCreatedProduct() { + return this.product; + } getCreatedVariants() { return this.variants; }