diff --git a/cypress/apiRequests/frontShop/ProductDetails.js b/cypress/apiRequests/frontShop/ProductDetails.js index bb6e77c95..def96af89 100644 --- a/cypress/apiRequests/frontShop/ProductDetails.js +++ b/cypress/apiRequests/frontShop/ProductDetails.js @@ -1,32 +1,12 @@ class ProductDetails { getProductDetails(productId, channelId) { - return cy.request({ - method: "POST", - url: Cypress.env("API_URI"), - headers: { - authorization: `JWT ${window.localStorage.getItem("token")}` - }, - body: [ - { - operationName: "ProductDetails", - variables: { - channel: channelId, - id: productId - }, - query: - "fragment BasicProductFields on Product {\n id\n name\n thumbnail {\n url\n alt\n __typename\n }\n thumbnail2x: thumbnail(size: 510) {\n url\n __typename\n }\n __typename\n}\n\nfragment SelectedAttributeFields on SelectedAttribute {\n attribute {\n id\n name\n __typename\n }\n values {\n id\n name\n __typename\n }\n __typename\n}\n\nfragment Price on TaxedMoney {\n gross {\n amount\n currency\n __typename\n }\n net {\n amount\n currency\n __typename\n }\n __typename\n}\n\nfragment ProductVariantFields on ProductVariant {\n id\n sku\n name\n quantityAvailable(countryCode: $countryCode)\n images {\n id\n url\n alt\n __typename\n }\n pricing {\n onSale\n priceUndiscounted {\n ...Price\n __typename\n }\n price {\n ...Price\n __typename\n }\n __typename\n }\n attributes(variantSelection: VARIANT_SELECTION) {\n attribute {\n id\n name\n slug\n __typename\n }\n values {\n id\n name\n value: name\n __typename\n }\n __typename\n }\n __typename\n}\n\nfragment ProductPricingField on Product {\n pricing {\n onSale\n priceRangeUndiscounted {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n priceRange {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n}\n\nquery ProductDetails($id: ID!, $channel: String, $countryCode: CountryCode) {\n product(id: $id, channel: $channel) {\n ...BasicProductFields\n ...ProductPricingField\n description\n category {\n id\n name\n products(first: 3, channel: $channel) {\n edges {\n node {\n ...BasicProductFields\n ...ProductPricingField\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n images {\n id\n alt\n url\n __typename\n }\n attributes {\n ...SelectedAttributeFields\n __typename\n }\n variants {\n ...ProductVariantFields\n __typename\n }\n seoDescription\n seoTitle\n isAvailable\n isAvailableForPurchase\n availableForPurchase\n __typename\n }\n}\n" - } - ] - }); - } - isAvailableForPurchaseFromResp(resp) { - return resp.body[0].data.product.isAvailableForPurchase; - } - isProductExist(resp, name) { - return ( - resp.body[0].data.product !== null && - resp.body[0].data.product.name === name - ); + const variables = { + channel: channelId, + id: productId + }; + const query = + "fragment BasicProductFields on Product {\n id\n name\n thumbnail {\n url\n alt\n __typename\n }\n thumbnail2x: thumbnail(size: 510) {\n url\n __typename\n }\n __typename\n}\n\nfragment SelectedAttributeFields on SelectedAttribute {\n attribute {\n id\n name\n __typename\n }\n values {\n id\n name\n __typename\n }\n __typename\n}\n\nfragment Price on TaxedMoney {\n gross {\n amount\n currency\n __typename\n }\n net {\n amount\n currency\n __typename\n }\n __typename\n}\n\nfragment ProductVariantFields on ProductVariant {\n id\n sku\n name\n quantityAvailable(countryCode: $countryCode)\n images {\n id\n url\n alt\n __typename\n }\n pricing {\n onSale\n priceUndiscounted {\n ...Price\n __typename\n }\n price {\n ...Price\n __typename\n }\n __typename\n }\n attributes(variantSelection: VARIANT_SELECTION) {\n attribute {\n id\n name\n slug\n __typename\n }\n values {\n id\n name\n value: name\n __typename\n }\n __typename\n }\n __typename\n}\n\nfragment ProductPricingField on Product {\n pricing {\n onSale\n priceRangeUndiscounted {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n priceRange {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n}\n\nquery ProductDetails($id: ID!, $channel: String, $countryCode: CountryCode) {\n product(id: $id, channel: $channel) {\n ...BasicProductFields\n ...ProductPricingField\n description\n category {\n id\n name\n products(first: 3, channel: $channel) {\n edges {\n node {\n ...BasicProductFields\n ...ProductPricingField\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n images {\n id\n alt\n url\n __typename\n }\n attributes {\n ...SelectedAttributeFields\n __typename\n }\n variants {\n ...ProductVariantFields\n __typename\n }\n seoDescription\n seoTitle\n isAvailable\n isAvailableForPurchase\n availableForPurchase\n __typename\n }\n}\n"; + return cy.sendFrontShopRequestWithQuery("ProductDetails", variables, query); } } export default ProductDetails; diff --git a/cypress/apiRequests/frontShop/Search.js b/cypress/apiRequests/frontShop/Search.js index 644a698ad..62feb5424 100644 --- a/cypress/apiRequests/frontShop/Search.js +++ b/cypress/apiRequests/frontShop/Search.js @@ -1,34 +1,18 @@ class Search { searchInShop(searchQuery) { - return cy.request({ - method: "POST", - url: Cypress.env("API_URI"), - headers: { - authorization: `JWT ${window.localStorage.getItem("token")}` - }, - body: [ - { - operationName: "SearchProducts", - variables: { - attributes: {}, - channel: "default-channel", - pageSize: 6, - priceGte: null, - priceLte: null, - query: searchQuery, - sortBy: null - }, - query: - "fragment Price on TaxedMoney {\n gross {\n amount\n currency\n __typename\n }\n net {\n amount\n currency\n __typename\n }\n __typename\n}\n\nfragment ProductPricingField on Product {\n pricing {\n onSale\n priceRangeUndiscounted {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n priceRange {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n}\n\nquery SearchProducts($query: String!, $channel: String!, $attributes: [AttributeInput], $pageSize: Int, $sortBy: ProductOrder, $after: String) {\n products(channel: $channel, filter: {search: $query, attributes: $attributes}, first: $pageSize, sortBy: $sortBy, after: $after) {\n totalCount\n edges {\n node {\n ...ProductPricingField\n id\n name\n thumbnail {\n url\n alt\n __typename\n }\n thumbnail2x: thumbnail(size: 510) {\n url\n __typename\n }\n category {\n id\n name\n __typename\n }\n __typename\n }\n __typename\n }\n pageInfo {\n endCursor\n hasNextPage\n __typename\n }\n __typename\n }\n attributes(filter: {filterableInStorefront: true}, first: 100) {\n edges {\n node {\n id\n name\n slug\n values {\n id\n name\n slug\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n}\n" - } - ] - }); - } - isProductExist(resp, name) { - return ( - resp.body[0].data.products.totalCount !== 0 && - resp.body[0].data.products.edges[0].node.name === name - ); + const variables = { + attributes: {}, + channel: "default-channel", + pageSize: 6, + priceGte: null, + priceLte: null, + query: searchQuery, + sortBy: null + }; + const query = + "fragment Price on TaxedMoney {\n gross {\n amount\n currency\n __typename\n }\n net {\n amount\n currency\n __typename\n }\n __typename\n}\n\nfragment ProductPricingField on Product {\n pricing {\n onSale\n priceRangeUndiscounted {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n priceRange {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n}\n\nquery SearchProducts($query: String!, $channel: String!, $attributes: [AttributeInput], $pageSize: Int, $sortBy: ProductOrder, $after: String) {\n products(channel: $channel, filter: {search: $query, attributes: $attributes}, first: $pageSize, sortBy: $sortBy, after: $after) {\n totalCount\n edges {\n node {\n ...ProductPricingField\n id\n name\n thumbnail {\n url\n alt\n __typename\n }\n thumbnail2x: thumbnail(size: 510) {\n url\n __typename\n }\n category {\n id\n name\n __typename\n }\n __typename\n }\n __typename\n }\n pageInfo {\n endCursor\n hasNextPage\n __typename\n }\n __typename\n }\n attributes(filter: {filterableInStorefront: true}, first: 100) {\n edges {\n node {\n id\n name\n slug\n values {\n id\n name\n slug\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n}\n"; + + return cy.sendFrontShopRequestWithQuery("SearchProducts", variables, query); } } export default Search; diff --git a/cypress/integration/products/availableForPurchaseProducts.js b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js similarity index 89% rename from cypress/integration/products/availableForPurchaseProducts.js rename to cypress/integration/products/menageProducts/availableForPurchaseProducts.js index 659bd2c7e..49026d110 100644 --- a/cypress/integration/products/availableForPurchaseProducts.js +++ b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js @@ -1,11 +1,11 @@ import faker from "faker"; -import ProductSteps from "../../steps/productSteps"; -import { urlList } from "../../url/urlList"; -import ChannelsUtils from "../../utils/channelsUtils"; -import FrontShopProductUtils from "../../utils/frontShop/frontShopProductUtils"; -import ProductsUtils from "../../utils/productsUtils"; -import ShippingUtils from "../../utils/shippingUtils"; +import ProductSteps from "../../../steps/productSteps"; +import { urlList } from "../../../url/urlList"; +import ChannelsUtils from "../../../utils/channelsUtils"; +import FrontShopProductUtils from "../../../utils/frontShop/frontShopProductUtils"; +import ProductsUtils from "../../../utils/productsUtils"; +import ShippingUtils from "../../../utils/shippingUtils"; // describe("Products available in listings", () => { diff --git a/cypress/integration/products/publishedProducts.js b/cypress/integration/products/menageProducts/publishedProducts.js similarity index 90% rename from cypress/integration/products/publishedProducts.js rename to cypress/integration/products/menageProducts/publishedProducts.js index f6b23a7ca..046b203ec 100644 --- a/cypress/integration/products/publishedProducts.js +++ b/cypress/integration/products/menageProducts/publishedProducts.js @@ -1,10 +1,10 @@ import faker from "faker"; -import ProductSteps from "../../steps/productSteps"; -import { urlList } from "../../url/urlList"; -import ChannelsUtils from "../../utils/channelsUtils"; -import FrontShopProductUtils from "../../utils/frontShop/frontShopProductUtils"; -import ProductsUtils from "../../utils/productsUtils"; +import ProductSteps from "../../../steps/productSteps"; +import { urlList } from "../../../url/urlList"; +import ChannelsUtils from "../../../utils/channelsUtils"; +import FrontShopProductUtils from "../../../utils/frontShop/frontShopProductUtils"; +import ProductsUtils from "../../../utils/productsUtils"; // describe("Published products", () => { diff --git a/cypress/integration/products/visibleInListingsProducts.js b/cypress/integration/products/menageProducts/visibleInListingsProducts.js similarity index 91% rename from cypress/integration/products/visibleInListingsProducts.js rename to cypress/integration/products/menageProducts/visibleInListingsProducts.js index 9d4729740..b7af5d51c 100644 --- a/cypress/integration/products/visibleInListingsProducts.js +++ b/cypress/integration/products/menageProducts/visibleInListingsProducts.js @@ -1,10 +1,10 @@ import faker from "faker"; -import ProductSteps from "../../steps/productSteps"; -import { urlList } from "../../url/urlList"; -import ChannelsUtils from "../../utils/channelsUtils"; -import FrontShopProductUtils from "../../utils/frontShop/frontShopProductUtils"; -import ProductsUtils from "../../utils/productsUtils"; +import ProductSteps from "../../../steps/productSteps"; +import { urlList } from "../../../url/urlList"; +import ChannelsUtils from "../../../utils/channelsUtils"; +import FrontShopProductUtils from "../../../utils/frontShop/frontShopProductUtils"; +import ProductsUtils from "../../../utils/productsUtils"; // describe("Products displayed in listings", () => { diff --git a/cypress/support/index.js b/cypress/support/index.js index f6115623a..01d098b68 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -40,15 +40,31 @@ Cypress.Commands.add("waitForGraph", operationName => { cy.wait(`@${operationName}`); }); -Cypress.Commands.add("sendRequestWithQuery", query => - cy.request({ - body: { - method: "POST", +Cypress.Commands.add("sendRequestWithQuery", query => { + const body = { + method: "POST", + query, + url: urlList.apiUri + }; + return cy.sendRequest(body, "auth"); +}); + +Cypress.Commands.add( + "sendFrontShopRequestWithQuery", + (operationName, variables, query) => { + const body = { + operationName, query, - url: urlList.apiUri - }, + variables + }; + return cy.sendRequest(body, "token"); + } +); +Cypress.Commands.add("sendRequest", (body, authorization) => + cy.request({ + body, headers: { - Authorization: `JWT ${window.sessionStorage.getItem("auth")}` + Authorization: `JWT ${window.sessionStorage.getItem(authorization)}` }, method: "POST", url: urlList.apiUri diff --git a/cypress/support/user/index.js b/cypress/support/user/index.js index 1019ac4ab..5fdb8d863 100644 --- a/cypress/support/user/index.js +++ b/cypress/support/user/index.js @@ -63,6 +63,6 @@ Cypress.Commands.add("loginInShop", () => { } ] }).then(resp => { - window.localStorage.setItem("token", resp.body[0].data.tokenCreate.token); + window.sessionStorage.setItem("token", resp.body[0].data.tokenCreate.token); }); }); diff --git a/cypress/utils/frontShop/frontShopProductUtils.js b/cypress/utils/frontShop/frontShopProductUtils.js index 1b8411f23..924666ab8 100644 --- a/cypress/utils/frontShop/frontShopProductUtils.js +++ b/cypress/utils/frontShop/frontShopProductUtils.js @@ -6,23 +6,29 @@ class FrontShopProductUtils { const productDetails = new ProductDetails(); return productDetails .getProductDetails(productId, channelSlug) - .then(productDetailsResp => - productDetails.isProductExist(productDetailsResp, name) - ); + .then(productDetailsResp => { + const product = productDetailsResp.body.data.product; + return product !== null && product.name === name; + }); } isProductAvailableForPurchase(productId, channelSlug) { const productDetails = new ProductDetails(); return productDetails .getProductDetails(productId, channelSlug) - .then(productDetailsResp => - productDetails.isAvailableForPurchaseFromResp(productDetailsResp) + .then( + productDetailsResp => + productDetailsResp.body.data.product.isAvailableForPurchase ); } isProductVisibleInSearchResult(productName, channelSlug) { const search = new Search(); return search .searchInShop(productName, channelSlug) - .then(resp => search.isProductExist(resp, productName)); + .then( + resp => + resp.body.data.products.totalCount !== 0 && + resp.body.data.products.edges[0].node.name === productName + ); } } export default FrontShopProductUtils;