From 4fc9fefa7409571291b0da2ddbba1893dbc12760 Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Fri, 19 Feb 2021 10:57:25 +0100 Subject: [PATCH 1/6] tests for products --- .../apiRequests/frontShop/ProductDetails.js | 34 ++++----------- cypress/apiRequests/frontShop/Search.js | 42 ++++++------------- .../availableForPurchaseProducts.js | 12 +++--- .../{ => menageProducts}/publishedProducts.js | 10 ++--- .../visibleInListingsProducts.js | 10 ++--- cypress/support/index.js | 30 +++++++++---- cypress/support/user/index.js | 2 +- .../utils/frontShop/frontShopProductUtils.js | 18 +++++--- 8 files changed, 72 insertions(+), 86 deletions(-) rename cypress/integration/products/{ => menageProducts}/availableForPurchaseProducts.js (89%) rename cypress/integration/products/{ => menageProducts}/publishedProducts.js (90%) rename cypress/integration/products/{ => menageProducts}/visibleInListingsProducts.js (91%) 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; From e8c20ae5111b1c1f8ccb511e76bf3de39937b63b Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Tue, 23 Feb 2021 13:09:58 +0100 Subject: [PATCH 2/6] tests for products --- cypress/apiRequests/Product.js | 36 +++++++--- cypress/apiRequests/utils/Utils.js | 6 ++ cypress/integration/channels.js | 24 ++++--- cypress/integration/homePage.js | 52 +++++++------- .../availableForPurchaseProducts.js | 71 ++++++++----------- .../menageProducts/publishedProducts.js | 38 +++++----- .../visibleInListingsProducts.js | 43 +++++------ cypress/steps/homePageSteps.js | 10 +-- cypress/steps/productSteps.js | 39 ++++------ cypress/support/index.js | 3 +- cypress/utils/productsUtils.js | 16 ++--- cypress/utils/shippingUtils.js | 2 +- 12 files changed, 170 insertions(+), 170 deletions(-) create mode 100644 cypress/apiRequests/utils/Utils.js 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)) From ac7f1b19b6997946f080f188c8d5f0efba81459c Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Tue, 23 Feb 2021 15:30:52 +0100 Subject: [PATCH 3/6] tests for products - fix storefront req --- cypress/apiRequests/Product.js | 14 --------- .../apiRequests/frontShop/ProductDetails.js | 12 -------- cypress/apiRequests/frontShop/Search.js | 18 ------------ .../apiRequests/storeFront/ProductDetails.js | 18 ++++++++++++ cypress/apiRequests/storeFront/Search.js | 20 +++++++++++++ .../availableForPurchaseProducts.js | 14 ++++----- .../menageProducts/publishedProducts.js | 10 +++---- .../visibleInListingsProducts.js | 10 +++---- cypress/support/index.js | 29 +++++-------------- cypress/url/urlList.js | 1 + .../storeFrontProductUtils.js} | 8 ++--- 11 files changed, 68 insertions(+), 86 deletions(-) delete mode 100644 cypress/apiRequests/frontShop/ProductDetails.js delete mode 100644 cypress/apiRequests/frontShop/Search.js create mode 100644 cypress/apiRequests/storeFront/ProductDetails.js create mode 100644 cypress/apiRequests/storeFront/Search.js rename cypress/utils/{frontShop/frontShopProductUtils.js => storeFront/storeFrontProductUtils.js} (82%) diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js index 69c10d7e2..8aa6b0ce8 100644 --- a/cypress/apiRequests/Product.js +++ b/cypress/apiRequests/Product.js @@ -97,14 +97,6 @@ class Product { price = 1, costPrice = 1 ) { - // const channelListings = channelId - // ? `channelListings:{ - // channelId:"${channelId}" - // price:"${price}" - // costPrice:"${costPrice}" - // }` - // : ""; - const channelListings = this.utils.getValueWithDefault( channelId, `channelListings:{ @@ -121,12 +113,6 @@ class Product { quantity:${quantity} }` ); - // warehouseId - // ? `stocks:{ - // warehouse:"${warehouseId}" - // quantity:${quantity} - // }` - // : ""; const mutation = `mutation{ productVariantBulkCreate(product: "${productId}", variants: { diff --git a/cypress/apiRequests/frontShop/ProductDetails.js b/cypress/apiRequests/frontShop/ProductDetails.js deleted file mode 100644 index def96af89..000000000 --- a/cypress/apiRequests/frontShop/ProductDetails.js +++ /dev/null @@ -1,12 +0,0 @@ -class ProductDetails { - getProductDetails(productId, channelId) { - 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 deleted file mode 100644 index 62feb5424..000000000 --- a/cypress/apiRequests/frontShop/Search.js +++ /dev/null @@ -1,18 +0,0 @@ -class Search { - searchInShop(searchQuery) { - 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/apiRequests/storeFront/ProductDetails.js b/cypress/apiRequests/storeFront/ProductDetails.js new file mode 100644 index 000000000..9ad18c5fc --- /dev/null +++ b/cypress/apiRequests/storeFront/ProductDetails.js @@ -0,0 +1,18 @@ +class ProductDetails { + getProductDetails(productId, channelId) { + const query = `fragment BasicProductFields on Product { + id + name + } + query ProductDetails{ + product(id: "${productId}", channel: "${channelId}") { + ...BasicProductFields + isAvailable + isAvailableForPurchase + availableForPurchase + } + }`; + return cy.sendFrontShopRequestWithQuery(query); + } +} +export default ProductDetails; diff --git a/cypress/apiRequests/storeFront/Search.js b/cypress/apiRequests/storeFront/Search.js new file mode 100644 index 000000000..107be2560 --- /dev/null +++ b/cypress/apiRequests/storeFront/Search.js @@ -0,0 +1,20 @@ +class Search { + searchInShop(searchQuery) { + const query = `query SearchProducts { + products(channel: "default-channel", filter:{ + search: "${searchQuery}" + }, first:10){ + totalCount + edges{ + node{ + id + name + } + } + } + }`; + + return cy.sendFrontShopRequestWithQuery(query); + } +} +export default Search; diff --git a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js index b72d5aafd..9c4a3c468 100644 --- a/cypress/integration/products/menageProducts/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 { productDetailsUrl } 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 StoreFrontProductUtils from "../../../utils/storeFront/storeFrontProductUtils"; // describe("Products available in listings", () => { @@ -13,7 +13,7 @@ describe("Products available in listings", () => { const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const productSteps = new ProductSteps(); - const frontShopProductUtils = new FrontShopProductUtils(); + const frontShopProductUtils = new StoreFrontProductUtils(); const startsWith = "Cy-"; const name = `${startsWith}${faker.random.number()}`; let productType; @@ -68,9 +68,9 @@ describe("Products available in listings", () => { isAvailableForPurchase: false }) .then(() => { - const productUrl = `${urlList.products}${ + const productUrl = productDetailsUrl( productsUtils.getCreatedProduct().id - }`; + ); productSteps.updateProductIsAvailableForPurchase(productUrl, true); }) .then(() => { @@ -96,9 +96,9 @@ describe("Products available in listings", () => { categoryId: category.id }) .then(() => { - const productUrl = `${urlList.products}${ + const productUrl = productDetailsUrl( productsUtils.getCreatedProduct().id - }`; + ); productSteps.updateProductIsAvailableForPurchase(productUrl, false); }) .then(() => { diff --git a/cypress/integration/products/menageProducts/publishedProducts.js b/cypress/integration/products/menageProducts/publishedProducts.js index 3c1d78f68..48015293f 100644 --- a/cypress/integration/products/menageProducts/publishedProducts.js +++ b/cypress/integration/products/menageProducts/publishedProducts.js @@ -1,17 +1,17 @@ import faker from "faker"; import ProductSteps from "../../../steps/productSteps"; -import { urlList } from "../../../url/urlList"; +import { productDetailsUrl } from "../../../url/urlList"; import ChannelsUtils from "../../../utils/channelsUtils"; -import FrontShopProductUtils from "../../../utils/frontShop/frontShopProductUtils"; import ProductsUtils from "../../../utils/productsUtils"; +import StoreFrontProductUtils from "../../../utils/storeFront/storeFrontProductUtils"; // describe("Published products", () => { const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const productSteps = new ProductSteps(); - const frontShopProductUtils = new FrontShopProductUtils(); + const frontShopProductUtils = new StoreFrontProductUtils(); const startsWith = "Cy-"; const name = `${startsWith}${faker.random.number()}`; @@ -51,7 +51,7 @@ describe("Published products", () => { }) .then(() => { const product = productsUtils.getCreatedProduct(); - const productUrl = `${urlList.products}${product.id}`; + const productUrl = productDetailsUrl(product.id); productSteps.updateProductPublish(productUrl, true); frontShopProductUtils.isProductVisible( product.id, @@ -82,7 +82,7 @@ describe("Published products", () => { }) .then(() => { product = productsUtils.getCreatedProduct(); - const productUrl = `${urlList.products}${product.id}`; + const productUrl = productDetailsUrl(product.id); productSteps.updateProductPublish(productUrl, false); frontShopProductUtils.isProductVisible( product.id, diff --git a/cypress/integration/products/menageProducts/visibleInListingsProducts.js b/cypress/integration/products/menageProducts/visibleInListingsProducts.js index c732a7111..19463c5ce 100644 --- a/cypress/integration/products/menageProducts/visibleInListingsProducts.js +++ b/cypress/integration/products/menageProducts/visibleInListingsProducts.js @@ -1,17 +1,17 @@ import faker from "faker"; import ProductSteps from "../../../steps/productSteps"; -import { urlList } from "../../../url/urlList"; +import { productDetailsUrl } from "../../../url/urlList"; import ChannelsUtils from "../../../utils/channelsUtils"; -import FrontShopProductUtils from "../../../utils/frontShop/frontShopProductUtils"; import ProductsUtils from "../../../utils/productsUtils"; +import StoreFrontProductUtils from "../../../utils/storeFront/storeFrontProductUtils"; // describe("Products displayed in listings", () => { const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const productSteps = new ProductSteps(); - const frontShopProductUtils = new FrontShopProductUtils(); + const frontShopProductUtils = new StoreFrontProductUtils(); const startsWith = "Cy-"; const name = `${startsWith}${faker.random.number()}`; @@ -51,7 +51,7 @@ describe("Products displayed in listings", () => { }) .then(() => { const product = productsUtils.getCreatedProduct(); - const productUrl = `${urlList.products}${product.id}`; + const productUrl = productDetailsUrl(product.id); productSteps.updateProductVisibleInListings(productUrl); frontShopProductUtils.isProductVisibleInSearchResult( productName, @@ -80,7 +80,7 @@ describe("Products displayed in listings", () => { }) .then(() => { const product = productsUtils.getCreatedProduct(); - const productUrl = `${urlList.products}${product.id}`; + const productUrl = productDetailsUrl(product.id); productSteps.updateProductVisibleInListings(productUrl); frontShopProductUtils .isProductVisibleInSearchResult(productName, defaultChannel.slug) diff --git a/cypress/support/index.js b/cypress/support/index.js index 76973c190..2d9dad3db 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -39,29 +39,16 @@ Cypress.Commands.add("addAliasToGraphRequest", operationName => { }); }); -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, - variables - }; - return cy.sendRequest(body, "token"); - } +Cypress.Commands.add("sendFrontShopRequestWithQuery", query => + cy.sendRequestWithQuery(query, "token") ); -Cypress.Commands.add("sendRequest", (body, authorization) => +Cypress.Commands.add("sendRequestWithQuery", (query, authorization = "auth") => cy.request({ - body, + body: { + method: "POST", + query, + url: urlList.apiUri + }, headers: { Authorization: `JWT ${window.sessionStorage.getItem(authorization)}` }, diff --git a/cypress/url/urlList.js b/cypress/url/urlList.js index 2ceb592c5..c469ba6e6 100644 --- a/cypress/url/urlList.js +++ b/cypress/url/urlList.js @@ -7,3 +7,4 @@ export const urlList = { products: "products/", warehouses: "warehouses/" }; +export const productDetailsUrl = productId => `${urlList.products}${productId}`; diff --git a/cypress/utils/frontShop/frontShopProductUtils.js b/cypress/utils/storeFront/storeFrontProductUtils.js similarity index 82% rename from cypress/utils/frontShop/frontShopProductUtils.js rename to cypress/utils/storeFront/storeFrontProductUtils.js index 924666ab8..676075f19 100644 --- a/cypress/utils/frontShop/frontShopProductUtils.js +++ b/cypress/utils/storeFront/storeFrontProductUtils.js @@ -1,7 +1,7 @@ -import ProductDetails from "../../apiRequests/frontShop/ProductDetails"; -import Search from "../../apiRequests/frontShop/Search"; +import ProductDetails from "../../apiRequests/storeFront/ProductDetails"; +import Search from "../../apiRequests/storeFront/Search"; -class FrontShopProductUtils { +class StoreFrontProductUtils { isProductVisible(productId, channelSlug, name) { const productDetails = new ProductDetails(); return productDetails @@ -31,4 +31,4 @@ class FrontShopProductUtils { ); } } -export default FrontShopProductUtils; +export default StoreFrontProductUtils; From f1c86f0a4d084de32cc412b22d12afb721ef7876 Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Wed, 24 Feb 2021 10:27:57 +0100 Subject: [PATCH 4/6] tests for products -change login cy command --- cypress/support/user/index.js | 60 ++++++++++------------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/cypress/support/user/index.js b/cypress/support/user/index.js index 5fdb8d863..11f606ea8 100644 --- a/cypress/support/user/index.js +++ b/cypress/support/user/index.js @@ -1,5 +1,4 @@ import { LOGIN_SELECTORS } from "../../elements/account/login-selectors"; -import { urlList } from "../../url/urlList"; Cypress.Commands.add("loginUser", () => cy @@ -12,57 +11,32 @@ Cypress.Commands.add("loginUser", () => ); Cypress.Commands.add("loginUserViaRequest", () => { - const logInMutationQuery = `mutation TokenAuth($email: String!, $password: String!) { - tokenCreate(email: $email, password: $password) { + cy.sendLoginRequest().then(resp => { + window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token); + }); +}); + +Cypress.Commands.add("loginInShop", () => { + cy.sendLoginRequest("token").then(resp => { + window.sessionStorage.setItem("token", resp.body[0].data.tokenCreate.token); + }); +}); + +Cypress.Commands.add("sendLoginRequest", (authorization = "auth") => { + const mutation = `mutation TokenAuth{ + tokenCreate(email: "${Cypress.env("USER_NAME")}", password: "${Cypress.env( + "USER_PASSWORD" + )}") { token errors: accountErrors { code field message - __typename } user { id - __typename } - __typename } }`; - - return cy - .request({ - body: { - operationName: "TokenAuth", - query: logInMutationQuery, - variables: { - email: Cypress.env("USER_NAME"), - password: Cypress.env("USER_PASSWORD") - } - }, - method: "POST", - url: urlList.apiUri - }) - .then(resp => { - window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token); - }); -}); - -Cypress.Commands.add("loginInShop", () => { - cy.request({ - method: "POST", - url: Cypress.env("API_URI"), - body: [ - { - operationName: "TokenAuth", - variables: { - email: Cypress.env("USER_NAME"), - password: Cypress.env("USER_PASSWORD") - }, - query: - "mutation TokenAuth($email: String!, $password: String!) {\n tokenCreate(email: $email, password: $password) {\n token\n errors: accountErrors {\n code\n field\n message\n __typename\n }\n user {\n id\n __typename\n }\n __typename\n }\n}\n" - } - ] - }).then(resp => { - window.sessionStorage.setItem("token", resp.body[0].data.tokenCreate.token); - }); + return cy.sendRequestWithQuery(mutation, authorization); }); From 3a90d9bdc2332639fcc44c88b847f6d7de915b3f Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Wed, 24 Feb 2021 12:19:17 +0100 Subject: [PATCH 5/6] fix login commands --- cypress/support/user/index.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cypress/support/user/index.js b/cypress/support/user/index.js index 11f606ea8..6e6fa8813 100644 --- a/cypress/support/user/index.js +++ b/cypress/support/user/index.js @@ -10,19 +10,17 @@ Cypress.Commands.add("loginUser", () => .click() ); -Cypress.Commands.add("loginUserViaRequest", () => { - cy.sendLoginRequest().then(resp => { - window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token); - }); -}); +// Cypress.Commands.add("loginUserViaRequest", () => { +// cy.sendLoginRequest().then(resp => { +// window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token); +// }); +// }); Cypress.Commands.add("loginInShop", () => { - cy.sendLoginRequest("token").then(resp => { - window.sessionStorage.setItem("token", resp.body[0].data.tokenCreate.token); - }); + cy.loginUserViaRequest("token"); }); -Cypress.Commands.add("sendLoginRequest", (authorization = "auth") => { +Cypress.Commands.add("loginUserViaRequest", (authorization = "auth") => { const mutation = `mutation TokenAuth{ tokenCreate(email: "${Cypress.env("USER_NAME")}", password: "${Cypress.env( "USER_PASSWORD" @@ -38,5 +36,10 @@ Cypress.Commands.add("sendLoginRequest", (authorization = "auth") => { } } }`; - return cy.sendRequestWithQuery(mutation, authorization); + return cy.sendRequestWithQuery(mutation, authorization).then(resp => { + window.sessionStorage.setItem( + authorization, + resp.body.data.tokenCreate.token + ); + }); }); From 095a5522d38154565682ace5d55fdb547d846380 Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Wed, 24 Feb 2021 12:21:06 +0100 Subject: [PATCH 6/6] fix login commands --- cypress/support/user/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cypress/support/user/index.js b/cypress/support/user/index.js index 6e6fa8813..33fcc4adc 100644 --- a/cypress/support/user/index.js +++ b/cypress/support/user/index.js @@ -10,12 +10,6 @@ Cypress.Commands.add("loginUser", () => .click() ); -// Cypress.Commands.add("loginUserViaRequest", () => { -// cy.sendLoginRequest().then(resp => { -// window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token); -// }); -// }); - Cypress.Commands.add("loginInShop", () => { cy.loginUserViaRequest("token"); });