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

35 lines
1.1 KiB
JavaScript
Raw Normal View History

import { getProductDetails } from "../../apiRequests/storeFront/ProductDetails";
2021-02-12 14:36:13 +00:00
2021-03-04 14:51:55 +00:00
export const isProductVisible = (resp, name) => {
const product = resp.body.data.product;
return product !== null && product.name === name;
};
2021-02-25 10:40:07 +00:00
2021-03-04 14:51:55 +00:00
export const isProductAvailableForPurchase = resp => {
const product = resp.body.data.product;
return product.isAvailableForPurchase;
};
2021-03-04 12:35:45 +00:00
2021-03-04 14:51:55 +00:00
export const isProductVisibleInSearchResult = (resp, productName) => {
const productsList = resp.body.data.products;
return (
productsList.totalCount !== 0 &&
productsList.edges[0].node.name === productName
);
};
2021-03-01 11:54:08 +00:00
export const getProductVariants = (productId, channelSlug) => {
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
}));
});
};
export const getProductPrice = (productId, channelSlug) =>
getProductDetails(productId, channelSlug).then(
resp => resp.body.data.product.variants[0].pricing.price.gross.amount
);