tests for products

This commit is contained in:
Karolina Rakoczy 2021-02-19 10:57:25 +01:00
parent 76ef2e6264
commit 4fc9fefa74
8 changed files with 72 additions and 86 deletions

View file

@ -1,32 +1,12 @@
class ProductDetails { class ProductDetails {
getProductDetails(productId, channelId) { getProductDetails(productId, channelId) {
return cy.request({ const variables = {
method: "POST", channel: channelId,
url: Cypress.env("API_URI"), id: productId
headers: { };
authorization: `JWT ${window.localStorage.getItem("token")}` 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";
body: [ return cy.sendFrontShopRequestWithQuery("ProductDetails", variables, query);
{
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
);
} }
} }
export default ProductDetails; export default ProductDetails;

View file

@ -1,34 +1,18 @@
class Search { class Search {
searchInShop(searchQuery) { searchInShop(searchQuery) {
return cy.request({ const variables = {
method: "POST", attributes: {},
url: Cypress.env("API_URI"), channel: "default-channel",
headers: { pageSize: 6,
authorization: `JWT ${window.localStorage.getItem("token")}` priceGte: null,
}, priceLte: null,
body: [ query: searchQuery,
{ sortBy: null
operationName: "SearchProducts", };
variables: { const query =
attributes: {}, "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";
channel: "default-channel",
pageSize: 6, return cy.sendFrontShopRequestWithQuery("SearchProducts", variables, query);
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
);
} }
} }
export default Search; export default Search;

View file

@ -1,11 +1,11 @@
import faker from "faker"; import faker from "faker";
import ProductSteps from "../../steps/productSteps"; import ProductSteps from "../../../steps/productSteps";
import { urlList } from "../../url/urlList"; import { urlList } from "../../../url/urlList";
import ChannelsUtils from "../../utils/channelsUtils"; import ChannelsUtils from "../../../utils/channelsUtils";
import FrontShopProductUtils from "../../utils/frontShop/frontShopProductUtils"; import FrontShopProductUtils from "../../../utils/frontShop/frontShopProductUtils";
import ProductsUtils from "../../utils/productsUtils"; import ProductsUtils from "../../../utils/productsUtils";
import ShippingUtils from "../../utils/shippingUtils"; import ShippingUtils from "../../../utils/shippingUtils";
// <reference types="cypress" /> // <reference types="cypress" />
describe("Products available in listings", () => { describe("Products available in listings", () => {

View file

@ -1,10 +1,10 @@
import faker from "faker"; import faker from "faker";
import ProductSteps from "../../steps/productSteps"; import ProductSteps from "../../../steps/productSteps";
import { urlList } from "../../url/urlList"; import { urlList } from "../../../url/urlList";
import ChannelsUtils from "../../utils/channelsUtils"; import ChannelsUtils from "../../../utils/channelsUtils";
import FrontShopProductUtils from "../../utils/frontShop/frontShopProductUtils"; import FrontShopProductUtils from "../../../utils/frontShop/frontShopProductUtils";
import ProductsUtils from "../../utils/productsUtils"; import ProductsUtils from "../../../utils/productsUtils";
// <reference types="cypress" /> // <reference types="cypress" />
describe("Published products", () => { describe("Published products", () => {

View file

@ -1,10 +1,10 @@
import faker from "faker"; import faker from "faker";
import ProductSteps from "../../steps/productSteps"; import ProductSteps from "../../../steps/productSteps";
import { urlList } from "../../url/urlList"; import { urlList } from "../../../url/urlList";
import ChannelsUtils from "../../utils/channelsUtils"; import ChannelsUtils from "../../../utils/channelsUtils";
import FrontShopProductUtils from "../../utils/frontShop/frontShopProductUtils"; import FrontShopProductUtils from "../../../utils/frontShop/frontShopProductUtils";
import ProductsUtils from "../../utils/productsUtils"; import ProductsUtils from "../../../utils/productsUtils";
// <reference types="cypress" /> // <reference types="cypress" />
describe("Products displayed in listings", () => { describe("Products displayed in listings", () => {

View file

@ -40,15 +40,31 @@ Cypress.Commands.add("waitForGraph", operationName => {
cy.wait(`@${operationName}`); cy.wait(`@${operationName}`);
}); });
Cypress.Commands.add("sendRequestWithQuery", query => Cypress.Commands.add("sendRequestWithQuery", query => {
cy.request({ const body = {
body: { method: "POST",
method: "POST", query,
url: urlList.apiUri
};
return cy.sendRequest(body, "auth");
});
Cypress.Commands.add(
"sendFrontShopRequestWithQuery",
(operationName, variables, query) => {
const body = {
operationName,
query, query,
url: urlList.apiUri variables
}, };
return cy.sendRequest(body, "token");
}
);
Cypress.Commands.add("sendRequest", (body, authorization) =>
cy.request({
body,
headers: { headers: {
Authorization: `JWT ${window.sessionStorage.getItem("auth")}` Authorization: `JWT ${window.sessionStorage.getItem(authorization)}`
}, },
method: "POST", method: "POST",
url: urlList.apiUri url: urlList.apiUri

View file

@ -63,6 +63,6 @@ Cypress.Commands.add("loginInShop", () => {
} }
] ]
}).then(resp => { }).then(resp => {
window.localStorage.setItem("token", resp.body[0].data.tokenCreate.token); window.sessionStorage.setItem("token", resp.body[0].data.tokenCreate.token);
}); });
}); });

View file

@ -6,23 +6,29 @@ class FrontShopProductUtils {
const productDetails = new ProductDetails(); const productDetails = new ProductDetails();
return productDetails return productDetails
.getProductDetails(productId, channelSlug) .getProductDetails(productId, channelSlug)
.then(productDetailsResp => .then(productDetailsResp => {
productDetails.isProductExist(productDetailsResp, name) const product = productDetailsResp.body.data.product;
); return product !== null && product.name === name;
});
} }
isProductAvailableForPurchase(productId, channelSlug) { isProductAvailableForPurchase(productId, channelSlug) {
const productDetails = new ProductDetails(); const productDetails = new ProductDetails();
return productDetails return productDetails
.getProductDetails(productId, channelSlug) .getProductDetails(productId, channelSlug)
.then(productDetailsResp => .then(
productDetails.isAvailableForPurchaseFromResp(productDetailsResp) productDetailsResp =>
productDetailsResp.body.data.product.isAvailableForPurchase
); );
} }
isProductVisibleInSearchResult(productName, channelSlug) { isProductVisibleInSearchResult(productName, channelSlug) {
const search = new Search(); const search = new Search();
return search return search
.searchInShop(productName, channelSlug) .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; export default FrontShopProductUtils;