diff --git a/cypress/apiRequests/Channels.js b/cypress/apiRequests/Channels.js index 39e8f8162..6d8872798 100644 --- a/cypress/apiRequests/Channels.js +++ b/cypress/apiRequests/Channels.js @@ -45,7 +45,8 @@ class Channels { channelErrors{ message } - }`; + } + }`; return cy.sendRequestWithQuery(deleteChannelMutation); } } diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js index b3cfdcbe0..16b7d2a30 100644 --- a/cypress/apiRequests/Product.js +++ b/cypress/apiRequests/Product.js @@ -94,19 +94,26 @@ class Product { price = 1, costPrice = 1 ) { + const channelListings = channelId + ? `channelListings:{ + channelId:"${channelId}" + price:"${price}" + costPrice:"${costPrice}" + }` + : ""; + const stocks = warehouseId + ? `stocks:{ + warehouse:"${warehouseId}" + quantity:${quantity} + }` + : ""; + const mutation = `mutation{ productVariantBulkCreate(product: "${productId}", variants: { attributes: [] sku: "${sku}" - channelListings: { - channelId: "${channelId}" - price: "${price}" - costPrice: "${costPrice}" - } - stocks: { - warehouse: "${warehouseId}" - quantity: ${quantity} - } + ${channelListings} + ${stocks} }) { productVariants{ id diff --git a/cypress/integration/products/publishedProducts.js b/cypress/integration/products/publishedProducts.js index 3e3b441fe..7a0a0d8ba 100644 --- a/cypress/integration/products/publishedProducts.js +++ b/cypress/integration/products/publishedProducts.js @@ -34,9 +34,12 @@ describe("Publish products", () => { }); it("should update product to published", () => { const productName = `${startsWith}${faker.random.number()}`; - channelsUtils.getDefaultChannel().then(defaultChannel => { - productsUtils - .createProductInChannel( + let defaultChannel; + channelsUtils + .getDefaultChannel() + .then(channel => { + defaultChannel = channel; + productsUtils.createProductInChannel( productName, defaultChannel.id, null, @@ -44,62 +47,68 @@ describe("Publish products", () => { productType.id, attribute.id, category.id, - null, + 1, false, false, true - ) - .then(() => { - const product = productsUtils.getCreatedProduct(); - const productUrl = `${URL_LIST.products}${product.id}`; - productSteps.updateProductPublish(productUrl, true); - frontShopProductUtils - .isProductVisible(product.id, defaultChannel.slug, productName) - .then(isVisible => { - expect(isVisible).to.be.eq(true); - }); - }); - }); + ); + }) + .then(() => { + const product = productsUtils.getCreatedProduct(); + const productUrl = `${URL_LIST.products}${product.id}`; + productSteps.updateProductPublish(productUrl, true); + frontShopProductUtils.isProductVisible( + product.id, + defaultChannel.slug, + productName + ); + }) + .then(isVisible => { + expect(isVisible).to.be.eq(true); + }); }); it("should update product to not published", () => { const productName = `${startsWith}${faker.random.number()}`; - channelsUtils.getDefaultChannel().then(defaultChannel => { - productsUtils - .createProductInChannel( - productName, - productType.id, - attribute.id, - category.id, - defaultChannel.id, + let defaultChannel; + let product; + + channelsUtils + .getDefaultChannel() + .then(channel => { + defaultChannel = channel; + productsUtils.createProductInChannel( productName, defaultChannel.id, null, null, productType.id, attribute.id, - category.id, - null, - false, - false, - true - ) - .then(() => { - const product = productsUtils.getCreatedProduct(); - const productUrl = `${URL_LIST.products}${product.id}`; - productSteps.updateProductPublish(productUrl, false); - frontShopProductUtils - .isProductVisible(productId, defaultChannel.slug, productName) - .then(isVisible => { - expect(isVisible).to.be.eq(false); - }); - cy.loginInShop().then(() => { - frontShopProductUtils - .isProductVisible(product.id, defaultChannel.slug, productName) - .then(isVisible => { - expect(isVisible).to.be.eq(true); - }); - }); - }); - }); + category.id + ); + }) + .then(() => { + product = productsUtils.getCreatedProduct(); + const productUrl = `${URL_LIST.products}${product.id}`; + productSteps.updateProductPublish(productUrl, false); + frontShopProductUtils.isProductVisible( + product.id, + defaultChannel.slug, + productName + ); + }) + .then(isVisible => { + expect(isVisible).to.be.eq(false); + cy.loginInShop(); + }) + .then(() => { + frontShopProductUtils.isProductVisible( + product.id, + defaultChannel.slug, + productName + ); + }) + .then(isVisible => { + expect(isVisible).to.be.eq(true); + }); }); }); diff --git a/cypress/integration/products/visibleInListingsProducts.js b/cypress/integration/products/visibleInListingsProducts.js index 321bc1969..e55aa9fa8 100644 --- a/cypress/integration/products/visibleInListingsProducts.js +++ b/cypress/integration/products/visibleInListingsProducts.js @@ -34,61 +34,78 @@ describe("Products displayed in listings", () => { }); it("should update product to visible in listings", () => { const productName = `${startsWith}${faker.random.number()}`; - channelsUtils.getDefaultChannel().then(defaultChannel => { - productsUtils - .createProductInChannel( + let defaultChannel; + channelsUtils + .getDefaultChannel() + .then(channel => { + defaultChannel = channel; + productsUtils.createProductInChannel( productName, + defaultChannel.id, + null, + null, productType.id, attribute.id, category.id, - defaultChannel.id, + 1, true, false, false - ) - .then(() => { - const productId = productsUtils.getCreatedProductId(); - const productUrl = `${URL_LIST.products}${productId}`; - productSteps.updateProductVisibleInListings(productUrl); - frontShopProductUtils - .isProductVisibleInSearchResult(productName, defaultChannel.slug) - .then(isProductVisible => { - expect(isProductVisible).to.be.eq(true); - }); - }); - }); + ); + }) + .then(() => { + const product = productsUtils.getCreatedProduct(); + const productUrl = `${URL_LIST.products}${product.id}`; + productSteps.updateProductVisibleInListings(productUrl); + frontShopProductUtils.isProductVisibleInSearchResult( + productName, + defaultChannel.slug + ); + }) + .then(isProductVisible => { + expect(isProductVisible).to.be.eq(true); + }); }); it("should update product to not visible in listings", () => { const productName = `${startsWith}${faker.random.number()}`; - channelsUtils.getDefaultChannel().then(defaultChannel => { - productsUtils - .createProductInChannel( + let defaultChannel; + channelsUtils + .getDefaultChannel() + .then(channel => { + defaultChannel = channel; + productsUtils.createProductInChannel( productName, + defaultChannel.id, + null, + null, productType.id, attribute.id, category.id, - defaultChannel.id, + 1, true, false, true - ) - .then(() => { - const productId = productsUtils.getCreatedProductId(); - const productUrl = `${URL_LIST.products}${productId}`; - productSteps.updateProductVisibleInListings(productUrl); - frontShopProductUtils - .isProductVisibleInSearchResult(productName, defaultChannel.slug) - .then(isProductVisible => { - expect(isProductVisible).to.be.eq(false); - }); - cy.loginInShop().then(() => { - frontShopProductUtils - .isProductVisibleInSearchResult(productName, defaultChannel.slug) - .then(isProductVisible => { - expect(isProductVisible).to.be.eq(true); - }); + ); + }) + .then(() => { + const product = productsUtils.getCreatedProduct(); + const productUrl = `${URL_LIST.products}${product.id}`; + productSteps.updateProductVisibleInListings(productUrl); + frontShopProductUtils + .isProductVisibleInSearchResult(productName, defaultChannel.slug) + .then(isProductVisible => { + expect(isProductVisible).to.be.eq(false); }); - }); - }); + cy.loginInShop(); + }) + .then(() => { + frontShopProductUtils.isProductVisibleInSearchResult( + productName, + defaultChannel.slug + ); + }) + .then(isProductVisible => { + expect(isProductVisible).to.be.eq(true); + }); }); });