saleor-dashboard/cypress/utils/storeFront/storeFrontProductUtils.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

import ProductDetails from "../../apiRequests/storeFront/ProductDetails";
import Search from "../../apiRequests/storeFront/Search";
2021-03-04 12:35:45 +00:00
import { isVisible } from "./utils";
2021-02-12 14:36:13 +00:00
2021-03-04 12:35:45 +00:00
const productDetails = new ProductDetails();
const search = new Search();
2021-02-25 10:40:07 +00:00
2021-03-04 12:35:45 +00:00
export const isProductVisible = (productId, channelSlug, name) =>
isVisible({
request: productDetails.getProductDetails(productId, channelSlug),
respObjectKey: ["product"],
responseValueKey: ["name"],
value: name
});
export const isProductAvailableForPurchase = (productId, channelSlug) =>
isVisible({
request: productDetails.getProductDetails(productId, channelSlug),
respObjectKey: ["product"],
responseValueKey: ["isAvailableForPurchase"]
});
export const isProductVisibleInSearchResult = (productName, channelSlug) =>
isVisible({
request: search.searchInShop(productName, channelSlug),
respObjectKey: ["products"],
responseValueKey: ["edges", 0, "node", "name"],
value: productName
});
2021-03-01 11:54:08 +00:00
2021-03-04 12:58:01 +00:00
export const getProductVariants = (productId, channelSlug) =>
productDetails.getProductDetails(productId, channelSlug).then(resp => {
2021-03-02 17:26:57 +00:00
const variantsList = resp.body.data.product.variants;
return variantsList.map(element => ({
name: element.name,
price: element.pricing.price.gross.amount
}));
});