tests for products
This commit is contained in:
parent
76ef2e6264
commit
4fc9fefa74
8 changed files with 72 additions and 86 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
|
||||
// <reference types="cypress" />
|
||||
describe("Products available in listings", () => {
|
|
@ -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";
|
||||
|
||||
// <reference types="cypress" />
|
||||
describe("Published products", () => {
|
|
@ -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";
|
||||
|
||||
// <reference types="cypress" />
|
||||
describe("Products displayed in listings", () => {
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue