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",
url: Cypress.env("API_URI"),
headers: {
authorization: `JWT ${window.localStorage.getItem("token")}`
},
body: [
{
operationName: "ProductDetails",
variables: {
channel: channelId, channel: channelId,
id: productId id: productId
}, };
query: 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" "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);
]
});
}
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,15 +1,6 @@
class Search { class Search {
searchInShop(searchQuery) { searchInShop(searchQuery) {
return cy.request({ const variables = {
method: "POST",
url: Cypress.env("API_URI"),
headers: {
authorization: `JWT ${window.localStorage.getItem("token")}`
},
body: [
{
operationName: "SearchProducts",
variables: {
attributes: {}, attributes: {},
channel: "default-channel", channel: "default-channel",
pageSize: 6, pageSize: 6,
@ -17,18 +8,11 @@ class Search {
priceLte: null, priceLte: null,
query: searchQuery, query: searchQuery,
sortBy: null sortBy: null
}, };
query: 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" "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);
});
}
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, query,
url: urlList.apiUri 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("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;