@shopgate/pwa-common-commerce 7.30.0-alpha.6 → 7.30.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cart/action-creators/addCouponsToCart.js +9 -2
- package/cart/action-creators/addProductsToCart.js +9 -2
- package/cart/action-creators/deleteCouponsFromCart.js +9 -2
- package/cart/action-creators/deleteProductsFromCart.js +9 -2
- package/cart/action-creators/errorAddCouponsToCart.js +10 -2
- package/cart/action-creators/errorAddProductsToCart.js +10 -2
- package/cart/action-creators/errorCart.js +8 -2
- package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
- package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
- package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
- package/cart/action-creators/receiveCart.js +9 -2
- package/cart/action-creators/requestCart.js +8 -2
- package/cart/action-creators/setCartProductPendingCount.js +9 -2
- package/cart/action-creators/setCouponFieldError.js +9 -2
- package/cart/action-creators/setCouponFieldValue.js +9 -2
- package/cart/action-creators/setFulfillmentSlot.js +9 -2
- package/cart/action-creators/successAddCouponsToCart.js +10 -2
- package/cart/action-creators/successAddProductsToCart.js +8 -2
- package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
- package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
- package/cart/action-creators/successUpdateProductsInCart.js +8 -2
- package/cart/action-creators/updateProductsInCart.js +9 -2
- package/cart/actions/addCouponsToCart.js +52 -8
- package/cart/actions/addProductsToCart.js +80 -11
- package/cart/actions/deleteCouponsFromCart.js +39 -6
- package/cart/actions/deleteProductsFromCart.js +38 -6
- package/cart/actions/fetchCart.js +52 -8
- package/cart/actions/updateProductsInCart.js +44 -6
- package/cart/constants/PipelineErrors.js +6 -1
- package/cart/constants/Pipelines.js +6 -1
- package/cart/constants/Portals.js +85 -1
- package/cart/constants/index.js +39 -2
- package/cart/helpers/config.js +47 -2
- package/cart/helpers/createPipelineErrorList.js +30 -4
- package/cart/helpers/fulfillmentSlots.js +37 -4
- package/cart/helpers/index.js +14 -3
- package/cart/helpers/quantity.js +23 -4
- package/cart/helpers/shipping.js +57 -2
- package/cart/helpers/tax.js +26 -2
- package/cart/index.js +25 -5
- package/cart/mock.js +130 -1
- package/cart/reducers/couponField.js +30 -2
- package/cart/reducers/data.js +98 -6
- package/cart/reducers/index.js +7 -1
- package/cart/selectors/index.js +181 -31
- package/cart/selectors/spec.js +189 -2
- package/cart/streams/index.js +176 -29
- package/cart/subscriptions/index.js +307 -30
- package/category/action-creators/errorCategory.js +10 -2
- package/category/action-creators/errorCategoryChildren.js +9 -2
- package/category/action-creators/errorRootCategories.js +8 -2
- package/category/action-creators/receiveCategory.js +12 -2
- package/category/action-creators/receiveCategoryChildren.js +10 -2
- package/category/action-creators/receiveRootCategories.js +9 -2
- package/category/action-creators/requestCategory.js +9 -2
- package/category/action-creators/requestCategoryChildren.js +9 -2
- package/category/action-creators/requestRootCategories.js +8 -2
- package/category/actions/fetchCategory.js +47 -5
- package/category/actions/fetchCategoryChildren.js +30 -2
- package/category/actions/fetchCategoryOrRootCategories.js +16 -2
- package/category/actions/fetchCategoryProducts.js +36 -2
- package/category/actions/fetchRootCategories.js +31 -2
- package/category/actions/getCategory.js +10 -2
- package/category/constants/Pipelines.js +3 -1
- package/category/constants/Portals.js +56 -3
- package/category/constants/index.js +17 -2
- package/category/helpers/index.js +27 -3
- package/category/index.js +19 -5
- package/category/mock.js +176 -1
- package/category/reducers/categoriesById.js +65 -3
- package/category/reducers/childrenByCategoryId.js +55 -4
- package/category/reducers/helpers/handleCategoryCollection.js +24 -3
- package/category/reducers/helpers/handleReceivedCategories.js +3 -1
- package/category/reducers/index.js +12 -2
- package/category/reducers/rootCategories.js +31 -2
- package/category/selectors/index.js +115 -16
- package/category/streams/index.js +82 -4
- package/category/subscriptions/index.js +96 -3
- package/checkout/action-creators/successCheckout.js +9 -2
- package/checkout/actions/fetchCheckoutUrl.js +28 -3
- package/checkout/constants/Pipelines.js +1 -1
- package/checkout/constants/index.js +3 -2
- package/checkout/index.js +11 -4
- package/checkout/selectors/index.js +7 -2
- package/checkout/streams/index.js +8 -2
- package/checkout/subscriptions/index.js +35 -6
- package/favorites/action-creators/index.js +206 -24
- package/favorites/actions/addFavorites.js +41 -3
- package/favorites/actions/addFavoritesList.js +27 -2
- package/favorites/actions/fetchFavoriteIds.js +49 -5
- package/favorites/actions/fetchFavorites.js +60 -5
- package/favorites/actions/fetchFavoritesList.js +47 -3
- package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
- package/favorites/actions/getFavorites.js +6 -2
- package/favorites/actions/removeFavorites.js +32 -3
- package/favorites/actions/removeFavoritesList.js +24 -2
- package/favorites/actions/toggleFavorites.js +68 -10
- package/favorites/actions/updateFavorites.js +39 -3
- package/favorites/actions/updateFavoritesList.js +26 -2
- package/favorites/constants/Pipelines.js +9 -1
- package/favorites/constants/Portals.js +32 -4
- package/favorites/constants/index.js +37 -5
- package/favorites/index.js +14 -4
- package/favorites/mock.js +89 -4
- package/favorites/reducers/index.js +7 -1
- package/favorites/reducers/lists.js +74 -2
- package/favorites/reducers/products.js +231 -24
- package/favorites/selectors/index.js +188 -24
- package/favorites/streams/index.js +135 -23
- package/favorites/streams/spec.js +517 -8
- package/favorites/subscriptions/index.js +260 -25
- package/favorites/subscriptions/spec.js +701 -28
- package/filter/action-creators/errorFilters.js +9 -2
- package/filter/action-creators/index.js +4 -1
- package/filter/action-creators/receiveFilters.js +10 -2
- package/filter/action-creators/requestFilters.js +9 -2
- package/filter/action-creators/updateFilters.js +8 -2
- package/filter/actions/fetchFilters.js +46 -3
- package/filter/actions/getFilters.js +6 -2
- package/filter/actions/helpers/buildFilterParams.js +34 -2
- package/filter/actions/helpers/buildRequestFilters.js +35 -2
- package/filter/actions/helpers/processFilters.js +10 -2
- package/filter/actions/helpers/processParams.js +26 -2
- package/filter/constants/Pipelines.js +1 -1
- package/filter/constants/Portals.js +39 -3
- package/filter/constants/index.js +8 -1
- package/filter/index.js +12 -4
- package/filter/reducers/helpers/enrichFilters.js +11 -3
- package/filter/reducers/index.js +5 -1
- package/filter/reducers/resultsByHash.js +43 -3
- package/filter/selectors/index.js +47 -6
- package/filter/streams/index.js +30 -1
- package/filter/subscriptions/index.js +34 -2
- package/market/constants/Portals.js +22 -4
- package/market/constants/index.js +2 -1
- package/market/helpers/showReturnPolicy.js +3 -1
- package/market/helpers/showTaxDisclaimer.js +3 -1
- package/market/index.js +6 -2
- package/orders/constants.js +2 -1
- package/package.json +3 -3
- package/product/action-creators/deleteProductsByIds.js +10 -2
- package/product/action-creators/errorProduct.js +10 -2
- package/product/action-creators/errorProductDescription.js +10 -2
- package/product/action-creators/errorProductImages.js +10 -2
- package/product/action-creators/errorProductMedia.js +10 -2
- package/product/action-creators/errorProductOptions.js +10 -2
- package/product/action-creators/errorProductProperties.js +10 -2
- package/product/action-creators/errorProductRelations.js +9 -2
- package/product/action-creators/errorProductShipping.js +10 -2
- package/product/action-creators/errorProductVariants.js +10 -2
- package/product/action-creators/errorProducts.js +9 -2
- package/product/action-creators/expireProductById.js +10 -2
- package/product/action-creators/expireProductData.js +11 -2
- package/product/action-creators/expireProductsByHash.js +9 -2
- package/product/action-creators/productNotAvailable.js +10 -2
- package/product/action-creators/provideProduct.js +9 -2
- package/product/action-creators/receiveProduct.js +10 -2
- package/product/action-creators/receiveProductCached.js +9 -2
- package/product/action-creators/receiveProductDescription.js +10 -2
- package/product/action-creators/receiveProductImages.js +10 -2
- package/product/action-creators/receiveProductMedia.js +10 -2
- package/product/action-creators/receiveProductOptions.js +10 -2
- package/product/action-creators/receiveProductProperties.js +10 -2
- package/product/action-creators/receiveProductRelations.js +12 -2
- package/product/action-creators/receiveProductShipping.js +10 -2
- package/product/action-creators/receiveProductVariants.js +10 -2
- package/product/action-creators/receiveProducts.js +16 -2
- package/product/action-creators/receiveProductsCached.js +9 -2
- package/product/action-creators/refreshExpiredPDPData.js +8 -2
- package/product/action-creators/requestProduct.js +10 -2
- package/product/action-creators/requestProductDescription.js +9 -2
- package/product/action-creators/requestProductImages.js +9 -2
- package/product/action-creators/requestProductMedia.js +9 -2
- package/product/action-creators/requestProductOptions.js +9 -2
- package/product/action-creators/requestProductProperties.js +9 -2
- package/product/action-creators/requestProductRelations.js +10 -2
- package/product/action-creators/requestProductShipping.js +9 -2
- package/product/action-creators/requestProductVariants.js +9 -2
- package/product/action-creators/requestProducts.js +9 -2
- package/product/action-creators/setProductId.js +9 -2
- package/product/action-creators/setProductQuantity.js +9 -2
- package/product/action-creators/setProductVariantId.js +9 -2
- package/product/actions/changeSortOrder.js +21 -2
- package/product/actions/fetchHighlightProducts.js +18 -2
- package/product/actions/fetchLiveshoppingProducts.js +14 -2
- package/product/actions/fetchProduct.js +52 -3
- package/product/actions/fetchProductDescription.js +30 -2
- package/product/actions/fetchProductImages.js +31 -2
- package/product/actions/fetchProductMedia.js +35 -2
- package/product/actions/fetchProductOptions.js +31 -2
- package/product/actions/fetchProductProperties.js +30 -2
- package/product/actions/fetchProductRelations.js +63 -2
- package/product/actions/fetchProductShipping.js +31 -2
- package/product/actions/fetchProductVariants.js +31 -2
- package/product/actions/fetchProducts.js +189 -17
- package/product/actions/fetchProductsById.js +68 -8
- package/product/actions/fetchProductsByQuery.js +102 -18
- package/product/actions/getHighlightProducts.js +6 -2
- package/product/actions/getLiveshoppingProducts.js +6 -2
- package/product/actions/getProduct.js +6 -2
- package/product/actions/getProductDescription.js +6 -2
- package/product/actions/getProductImages.js +6 -2
- package/product/actions/getProductOptions.js +6 -2
- package/product/actions/getProductProperties.js +6 -2
- package/product/actions/getProductRelations.js +6 -2
- package/product/actions/getProductShipping.js +6 -2
- package/product/actions/getProductVariants.js +6 -2
- package/product/actions/getProducts.js +6 -2
- package/product/actions/getProductsById.js +6 -2
- package/product/actions/getProductsByQuery.js +6 -2
- package/product/actions/processProductFlags.js +35 -3
- package/product/actions/updateMetadata.js +17 -2
- package/product/collections/ProductImageFormats.js +48 -8
- package/product/collections/index.js +1 -1
- package/product/constants/Pipelines.js +12 -1
- package/product/constants/Portals.js +200 -33
- package/product/constants/index.js +90 -18
- package/product/helpers/index.js +61 -8
- package/product/index.js +36 -6
- package/product/mock.js +1002 -2
- package/product/reducers/descriptionsByProductId.js +54 -5
- package/product/reducers/helpers/formatOptions.js +17 -2
- package/product/reducers/helpers/handleProductCollection.js +19 -2
- package/product/reducers/imagesByProductId.js +51 -4
- package/product/reducers/index.js +23 -1
- package/product/reducers/mediaByProductId.js +55 -3
- package/product/reducers/optionsByProductId.js +41 -2
- package/product/reducers/productRelationsByHash.js +43 -2
- package/product/reducers/productsById.js +122 -7
- package/product/reducers/propertiesByProductId.js +48 -2
- package/product/reducers/resultsByHash.js +125 -9
- package/product/reducers/shippingByProductId.js +37 -2
- package/product/reducers/variantsByProductId.js +56 -2
- package/product/selectors/options.js +90 -13
- package/product/selectors/page.js +62 -13
- package/product/selectors/price.js +81 -18
- package/product/selectors/product.js +549 -59
- package/product/selectors/product.mock.js +327 -12
- package/product/selectors/relations.js +35 -5
- package/product/selectors/variants.js +91 -15
- package/product/streams/index.js +167 -13
- package/product/subscriptions/index.js +210 -4
- package/reviews/action-creators/errorProductReviews.js +9 -2
- package/reviews/action-creators/errorReviews.js +9 -2
- package/reviews/action-creators/errorSubmitReview.js +9 -2
- package/reviews/action-creators/errorUserReview.js +9 -2
- package/reviews/action-creators/flushUserReview.js +8 -2
- package/reviews/action-creators/receiveProductReviews.js +11 -2
- package/reviews/action-creators/receiveReviews.js +12 -2
- package/reviews/action-creators/receiveSubmitReview.js +9 -2
- package/reviews/action-creators/receiveUserReview.js +10 -2
- package/reviews/action-creators/requestProductReviews.js +10 -2
- package/reviews/action-creators/requestReviews.js +9 -2
- package/reviews/action-creators/requestSubmitReview.js +9 -2
- package/reviews/action-creators/requestUserReview.js +9 -2
- package/reviews/action-creators/resetSubmittedReview.js +9 -2
- package/reviews/action-creators/spec.js +40 -1
- package/reviews/actions/fetchProductReviews.js +37 -2
- package/reviews/actions/fetchReviews.js +38 -2
- package/reviews/actions/fetchUserReview.js +31 -2
- package/reviews/actions/flushUserReview.js +5 -1
- package/reviews/actions/getProductReviews.js +6 -2
- package/reviews/actions/getUserReview.js +6 -2
- package/reviews/actions/spec.js +241 -4
- package/reviews/actions/submitReview.js +63 -3
- package/reviews/constants/Pipelines.js +4 -1
- package/reviews/constants/Portals.js +4 -1
- package/reviews/constants/index.js +26 -7
- package/reviews/index.js +15 -4
- package/reviews/mock.js +172 -11
- package/reviews/reducers/index.js +11 -1
- package/reviews/reducers/mock.js +14 -2
- package/reviews/reducers/reviewsByHash.js +52 -6
- package/reviews/reducers/reviewsById.js +27 -2
- package/reviews/reducers/reviewsByProductId.js +47 -2
- package/reviews/reducers/spec.js +211 -2
- package/reviews/reducers/userReviewsByProductId.js +68 -2
- package/reviews/selectors/index.js +123 -19
- package/reviews/selectors/mock.js +100 -1
- package/reviews/selectors/spec.js +100 -1
- package/reviews/streams/index.js +37 -5
- package/reviews/streams/spec.js +25 -1
- package/reviews/subscriptions/index.js +27 -2
- package/scanner/action-creators/errorHandleScanner.js +11 -2
- package/scanner/action-creators/scannerFinished.js +11 -2
- package/scanner/action-creators/startScanner.js +8 -2
- package/scanner/action-creators/successHandleScanner.js +11 -2
- package/scanner/actions/handleBarCode.js +22 -2
- package/scanner/actions/handleNoResults.js +23 -2
- package/scanner/actions/handleQrCode.js +116 -6
- package/scanner/actions/handleSearch.js +33 -2
- package/scanner/constants/Portals.js +22 -1
- package/scanner/constants/index.js +17 -1
- package/scanner/helpers/index.js +115 -5
- package/scanner/index.js +19 -5
- package/scanner/streams/index.js +36 -1
- package/scanner/subscriptions/index.js +78 -8
- package/search/action-creators/errorSearchResults.js +10 -2
- package/search/action-creators/receiveSearchResults.js +11 -2
- package/search/action-creators/receiveSearchSuggestions.js +10 -2
- package/search/action-creators/requestSearchResults.js +10 -2
- package/search/action-creators/requestSearchSuggestions.js +9 -2
- package/search/actions/fetchSearchResults.js +66 -8
- package/search/actions/fetchSearchSuggestions.js +36 -2
- package/search/constants/Pipelines.js +1 -1
- package/search/constants/Portals.js +9 -2
- package/search/constants/index.js +10 -2
- package/search/helpers/index.js +5 -2
- package/search/helpers/removeHighlightingPlaceholders.js +4 -1
- package/search/helpers/spec.js +19 -1
- package/search/index.js +17 -5
- package/search/reducers/index.js +38 -2
- package/search/selectors/index.js +23 -4
- package/search/streams/index.js +51 -3
- package/search/subscriptions/index.js +132 -5
package/cart/selectors/spec.js
CHANGED
|
@@ -1,2 +1,189 @@
|
|
|
1
|
-
/* eslint-disable extra-rules/no-single-line-objects */
|
|
2
|
-
|
|
1
|
+
/* eslint-disable extra-rules/no-single-line-objects */
|
|
2
|
+
import { mockedState as mockedProductState, mockedProductMetadata, mockedVariantProductMetadata, mockedVariantMetadata } from "../../product/selectors/product.mock";
|
|
3
|
+
import { getFlags, getAddToCartMetadata, hasCouponSupport, getIsFetching, getSubTotal, getDiscounts, getDiscountsAmount, getTax, getGrandTotal } from "./index";
|
|
4
|
+
import { CART_TOTALS_TYPE_DISCOUNT, CART_TOTALS_TYPE_GRAND, CART_TOTALS_TYPE_SUB, CART_TOTALS_TYPE_TAX } from "../constants";
|
|
5
|
+
describe('Cart selectors', () => {
|
|
6
|
+
describe('getFlags()', () => {
|
|
7
|
+
it('should return an empty object if no flags are available', () => {
|
|
8
|
+
const result = getFlags({
|
|
9
|
+
cart: {
|
|
10
|
+
data: {}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
expect(result).toEqual({});
|
|
14
|
+
});
|
|
15
|
+
it('should return the flags if available', () => {
|
|
16
|
+
const flags = {
|
|
17
|
+
coupons: true,
|
|
18
|
+
orderable: true
|
|
19
|
+
};
|
|
20
|
+
const result = getFlags({
|
|
21
|
+
cart: {
|
|
22
|
+
data: {
|
|
23
|
+
flags
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
expect(result).toEqual(flags);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('getAddToCartMetadata()', () => {
|
|
31
|
+
let mockedState;
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
// Create a deep copy of the state to avoid unintended selector caching.
|
|
34
|
+
mockedState = JSON.parse(JSON.stringify(mockedProductState));
|
|
35
|
+
});
|
|
36
|
+
it('should return the metadata of the variant product', () => {
|
|
37
|
+
const productId = 'product_1';
|
|
38
|
+
const variantId = 'product_2';
|
|
39
|
+
const result = getAddToCartMetadata(mockedState, {
|
|
40
|
+
productId,
|
|
41
|
+
variantId
|
|
42
|
+
});
|
|
43
|
+
expect(result).toEqual(mockedVariantProductMetadata);
|
|
44
|
+
});
|
|
45
|
+
it('should return the metadata of the base product', () => {
|
|
46
|
+
const productId = 'product_1';
|
|
47
|
+
const variantId = 'product_2';
|
|
48
|
+
delete mockedState.product.productsById[variantId].productData.metadata;
|
|
49
|
+
const result = getAddToCartMetadata(mockedState, {
|
|
50
|
+
productId,
|
|
51
|
+
variantId
|
|
52
|
+
});
|
|
53
|
+
expect(result).toEqual(mockedProductMetadata);
|
|
54
|
+
});
|
|
55
|
+
it('should return the metadata of the variant data assigned to the variant product', () => {
|
|
56
|
+
const productId = 'product_1';
|
|
57
|
+
const variantId = 'product_3';
|
|
58
|
+
const result = getAddToCartMetadata(mockedState, {
|
|
59
|
+
productId,
|
|
60
|
+
variantId
|
|
61
|
+
});
|
|
62
|
+
expect(result).toEqual(mockedVariantMetadata);
|
|
63
|
+
});
|
|
64
|
+
it('should return null when no metadata can be determined', () => {
|
|
65
|
+
const productId = 'product_10';
|
|
66
|
+
const variantId = 'product_11';
|
|
67
|
+
const result = getAddToCartMetadata(mockedState, {
|
|
68
|
+
productId,
|
|
69
|
+
variantId
|
|
70
|
+
});
|
|
71
|
+
expect(result).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('hasCouponSupport()', () => {
|
|
75
|
+
it('should return true if no flags are available', () => {
|
|
76
|
+
const result = hasCouponSupport({
|
|
77
|
+
cart: {
|
|
78
|
+
data: {}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
expect(result).toEqual(true);
|
|
82
|
+
});
|
|
83
|
+
it('should return true if the coupons flag is not available', () => {
|
|
84
|
+
const result = hasCouponSupport({
|
|
85
|
+
cart: {
|
|
86
|
+
data: {
|
|
87
|
+
flags: {}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
expect(result).toEqual(true);
|
|
92
|
+
});
|
|
93
|
+
it('should return true if the flag is true', () => {
|
|
94
|
+
const result = hasCouponSupport({
|
|
95
|
+
cart: {
|
|
96
|
+
data: {
|
|
97
|
+
flags: {
|
|
98
|
+
coupons: true
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
expect(result).toEqual(true);
|
|
104
|
+
});
|
|
105
|
+
it('should return false if the flag is false', () => {
|
|
106
|
+
const result = hasCouponSupport({
|
|
107
|
+
cart: {
|
|
108
|
+
data: {
|
|
109
|
+
flags: {
|
|
110
|
+
coupons: false
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
expect(result).toEqual(false);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe('isFetching()', () => {
|
|
119
|
+
it('should return true if cart is fetching', () => {
|
|
120
|
+
const result = getIsFetching({
|
|
121
|
+
cart: {
|
|
122
|
+
data: {
|
|
123
|
+
isFetching: true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
expect(result).toEqual(true);
|
|
128
|
+
});
|
|
129
|
+
it('should return false when no store information is given', () => {
|
|
130
|
+
const result = getIsFetching({
|
|
131
|
+
cart: {
|
|
132
|
+
data: {}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
expect(result).toEqual(false);
|
|
136
|
+
});
|
|
137
|
+
it('should return false if cart is not fetching', () => {
|
|
138
|
+
const result = getIsFetching({
|
|
139
|
+
cart: {
|
|
140
|
+
data: {
|
|
141
|
+
isFetching: false
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
expect(result).toEqual(false);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
describe('getTotals', () => {
|
|
149
|
+
const mockedState = {
|
|
150
|
+
cart: {
|
|
151
|
+
data: {
|
|
152
|
+
totals: [{
|
|
153
|
+
type: CART_TOTALS_TYPE_SUB,
|
|
154
|
+
amount: 100
|
|
155
|
+
}, {
|
|
156
|
+
type: CART_TOTALS_TYPE_DISCOUNT,
|
|
157
|
+
amount: 5
|
|
158
|
+
}, {
|
|
159
|
+
type: CART_TOTALS_TYPE_DISCOUNT,
|
|
160
|
+
amount: 2
|
|
161
|
+
}, {
|
|
162
|
+
type: CART_TOTALS_TYPE_TAX,
|
|
163
|
+
label: 'inkl. 26% MwSt.',
|
|
164
|
+
amount: 5
|
|
165
|
+
}, {
|
|
166
|
+
type: CART_TOTALS_TYPE_GRAND,
|
|
167
|
+
amount: 105
|
|
168
|
+
}]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
it('should return subtotal', () => {
|
|
173
|
+
expect(getSubTotal(mockedState)).toEqual(100);
|
|
174
|
+
});
|
|
175
|
+
it('should return discount', () => {
|
|
176
|
+
expect(getDiscounts(mockedState)).toEqual([mockedState.cart.data.totals[1], mockedState.cart.data.totals[2]]);
|
|
177
|
+
});
|
|
178
|
+
it('should return discount amount', () => {
|
|
179
|
+
expect(getDiscountsAmount(mockedState)).toEqual(7);
|
|
180
|
+
});
|
|
181
|
+
it('should return tax', () => {
|
|
182
|
+
expect(getTax(mockedState)).toEqual(mockedState.cart.data.totals[3]);
|
|
183
|
+
});
|
|
184
|
+
it('should return grand total', () => {
|
|
185
|
+
expect(getGrandTotal(mockedState)).toEqual(105);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
/* eslint-enable extra-rules/no-single-line-objects */
|
package/cart/streams/index.js
CHANGED
|
@@ -1,56 +1,203 @@
|
|
|
1
|
-
|
|
1
|
+
import queryString from 'query-string';
|
|
2
|
+
import { ACTION_PUSH, ACTION_REPLACE } from '@virtuous/conductor';
|
|
3
|
+
import { main$ } from '@shopgate/pwa-common/streams/main';
|
|
4
|
+
import { routeWillEnter$, routeDidEnter$, routeWillLeave$, routeDidLeave$, navigate$ } from '@shopgate/pwa-common/streams/router';
|
|
5
|
+
import { getCurrentPathname } from '@shopgate/pwa-common/selectors/router';
|
|
6
|
+
import { pushNotificationOpened$ } from '@shopgate/pwa-common/streams/app';
|
|
7
|
+
import { INDEX_PATH_DEEPLINK, INDEX_PATH } from '@shopgate/pwa-common/constants/RoutePaths';
|
|
8
|
+
import { getIsFetching } from "../selectors";
|
|
9
|
+
import { CART_PATH, REQUEST_CART, RECEIVE_CART, ERROR_CART, ADD_PRODUCTS_TO_CART, SUCCESS_ADD_PRODUCTS_TO_CART, ERROR_ADD_PRODUCTS_TO_CART, UPDATE_PRODUCTS_IN_CART, SUCCESS_UPDATE_PRODUCTS_IN_CART, ERROR_UPDATE_PRODUCTS_IN_CART, DELETE_PRODUCTS_FROM_CART, SUCCESS_DELETE_PRODUCTS_FROM_CART, ERROR_DELETE_PRODUCTS_FROM_CART, ADD_COUPONS_TO_CART, SUCCESS_ADD_COUPONS_TO_CART, ERROR_ADD_COUPONS_TO_CART, DELETE_COUPONS_FROM_CART, ERROR_DELETE_COUPONS_FROM_CART, SUCCESS_DELETE_COUPONS_FROM_CART, DEEPLINK_CART_ADD_PRODUCT_PATTERN, SET_FULFILLMENT_SLOT } from "../constants";
|
|
10
|
+
|
|
11
|
+
/**
|
|
2
12
|
* Specialized stream to handle push notifications that redirect to index screen with a coupon code.
|
|
3
13
|
* Default logic would dispatch a historyReset in that case without link in the action payload,
|
|
4
14
|
* so we need to hook onto the pushNotificationOpen stream to inspect the link.
|
|
5
15
|
* @type {Observable}
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
*/
|
|
17
|
+
const pushNotificationWithIndexCouponOpened$ = pushNotificationOpened$.filter(({
|
|
18
|
+
action
|
|
19
|
+
}) => {
|
|
20
|
+
if (!action.link) {
|
|
21
|
+
// stop execution when push contains no link
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const [pathname] = action.link.split('?');
|
|
25
|
+
if (pathname !== INDEX_PATH && pathname !== INDEX_PATH_DEEPLINK) {
|
|
26
|
+
// stop execution when link doesn't reference index path
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const parsed = queryString.parseUrl(action.link);
|
|
30
|
+
if (!parsed || !parsed.query || !parsed.query.coupon) {
|
|
31
|
+
// stop execution when link doesn't contain a coupon
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}).map(input => ({
|
|
36
|
+
// mock payload of navigation action to keep further handling simple
|
|
37
|
+
...input,
|
|
38
|
+
action: {
|
|
39
|
+
historyAction: ACTION_PUSH,
|
|
40
|
+
route: {
|
|
41
|
+
query: {
|
|
42
|
+
coupon: queryString.parseUrl(input.action.link).query.coupon
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @type {Observable}
|
|
50
|
+
*/
|
|
51
|
+
export const routeWithCouponWillEnter$ = routeWillEnter$.merge(pushNotificationWithIndexCouponOpened$).filter(({
|
|
52
|
+
action
|
|
53
|
+
}) => [ACTION_PUSH, ACTION_REPLACE].includes(action.historyAction) && action.route.query.coupon);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @type {Observable}
|
|
57
|
+
*/
|
|
58
|
+
export const cartWillEnter$ = routeWillEnter$.filter(({
|
|
59
|
+
action
|
|
60
|
+
}) => action.route.pattern === CART_PATH);
|
|
61
|
+
|
|
62
|
+
/**
|
|
14
63
|
* @type {Observable}
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
64
|
+
*/
|
|
65
|
+
export const cartDidEnter$ = routeDidEnter$.filter(({
|
|
66
|
+
action
|
|
67
|
+
}) => action.route.pattern === CART_PATH);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @type {Observable}
|
|
71
|
+
*/
|
|
72
|
+
export const cartWillLeave$ = routeWillLeave$.filter(({
|
|
73
|
+
action
|
|
74
|
+
}) => action.route.pattern === CART_PATH);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @type {Observable}
|
|
78
|
+
*/
|
|
79
|
+
export const cartDidLeave$ = routeDidLeave$.filter(({
|
|
80
|
+
action
|
|
81
|
+
}) => action.route.pattern === CART_PATH);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @type {Observable}
|
|
85
|
+
*/
|
|
86
|
+
export const cartRequesting$ = main$.filter(({
|
|
87
|
+
action
|
|
88
|
+
}) => action.type === REQUEST_CART);
|
|
89
|
+
export const cartWillEnterIdle$ = cartWillEnter$.filter(({
|
|
90
|
+
getState
|
|
91
|
+
}) => !getIsFetching(getState()));
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @type {Observable}
|
|
95
|
+
*/
|
|
96
|
+
export const cartReceived$ = main$.filter(({
|
|
97
|
+
action
|
|
98
|
+
}) => action.type === RECEIVE_CART || action.type === ERROR_CART);
|
|
99
|
+
|
|
100
|
+
/**
|
|
24
101
|
* Gets triggered when the user tried to add a coupon to the cart.
|
|
25
102
|
* @type {Observable}
|
|
26
|
-
*/
|
|
103
|
+
*/
|
|
104
|
+
export const couponsAdded$ = main$.filter(({
|
|
105
|
+
action
|
|
106
|
+
}) => action.type === ADD_COUPONS_TO_CART);
|
|
107
|
+
|
|
108
|
+
/**
|
|
27
109
|
* Gets triggered when the user tried to add a coupon to the cart.
|
|
28
110
|
* @type {Observable}
|
|
29
|
-
*/
|
|
111
|
+
*/
|
|
112
|
+
export const couponsDeleted$ = main$.filter(({
|
|
113
|
+
action
|
|
114
|
+
}) => action.type === DELETE_COUPONS_FROM_CART);
|
|
115
|
+
|
|
116
|
+
/**
|
|
30
117
|
* Gets triggered when the user tried to add a coupon to the cart.
|
|
31
118
|
* @type {Observable}
|
|
32
|
-
*/
|
|
119
|
+
*/
|
|
120
|
+
export const couponsUpdated$ = main$.filter(({
|
|
121
|
+
action
|
|
122
|
+
}) => action.type === SUCCESS_ADD_COUPONS_TO_CART || action.type === ERROR_ADD_COUPONS_TO_CART || action.type === SUCCESS_DELETE_COUPONS_FROM_CART || action.type === ERROR_DELETE_COUPONS_FROM_CART);
|
|
123
|
+
|
|
124
|
+
/**
|
|
33
125
|
* Gets triggered when the user tried to add a product to the cart.
|
|
34
126
|
* @type {Observable}
|
|
35
|
-
*/
|
|
127
|
+
*/
|
|
128
|
+
export const productsAdded$ = main$.filter(({
|
|
129
|
+
action
|
|
130
|
+
}) => action.type === ADD_PRODUCTS_TO_CART);
|
|
131
|
+
|
|
132
|
+
/**
|
|
36
133
|
* Gets triggered when the user tried to add a product to the cart.
|
|
37
134
|
* @type {Observable}
|
|
38
|
-
*/
|
|
135
|
+
*/
|
|
136
|
+
export const productsModified$ = main$.filter(({
|
|
137
|
+
action
|
|
138
|
+
}) => action.type === UPDATE_PRODUCTS_IN_CART);
|
|
139
|
+
|
|
140
|
+
/**
|
|
39
141
|
* Gets triggered when the user tried to add a product to the cart.
|
|
40
142
|
* @type {Observable}
|
|
41
|
-
*/
|
|
143
|
+
*/
|
|
144
|
+
export const productsDeleted$ = main$.filter(({
|
|
145
|
+
action
|
|
146
|
+
}) => action.type === DELETE_PRODUCTS_FROM_CART);
|
|
147
|
+
|
|
148
|
+
/**
|
|
42
149
|
* Gets triggered when the cart has been updated while the cart route was visible.
|
|
43
150
|
* @type {Observable}
|
|
44
|
-
*/
|
|
151
|
+
*/
|
|
152
|
+
export const cartUpdatedWhileVisible$ = cartReceived$.filter(({
|
|
153
|
+
getState
|
|
154
|
+
}) => getCurrentPathname(getState()) === CART_PATH);
|
|
155
|
+
|
|
156
|
+
/**
|
|
45
157
|
* Gets triggered when the user tried to add a coupon to the cart.
|
|
46
158
|
* @type {Observable}
|
|
47
|
-
*/
|
|
159
|
+
*/
|
|
160
|
+
export const productsUpdated$ = main$.filter(({
|
|
161
|
+
action
|
|
162
|
+
}) => action.type === SUCCESS_ADD_PRODUCTS_TO_CART || action.type === ERROR_ADD_PRODUCTS_TO_CART || action.type === SUCCESS_UPDATE_PRODUCTS_IN_CART || action.type === ERROR_UPDATE_PRODUCTS_IN_CART || action.type === SUCCESS_DELETE_PRODUCTS_FROM_CART || action.type === ERROR_DELETE_PRODUCTS_FROM_CART);
|
|
163
|
+
|
|
164
|
+
/**
|
|
48
165
|
* Gets triggered when the remote cart was updated.
|
|
49
166
|
* @type {Observable}
|
|
50
|
-
*/
|
|
167
|
+
*/
|
|
168
|
+
export const remoteCartDidUpdate$ = main$.filter(({
|
|
169
|
+
action
|
|
170
|
+
}) => action.type === SUCCESS_ADD_PRODUCTS_TO_CART || action.type === ERROR_ADD_PRODUCTS_TO_CART || action.type === SUCCESS_UPDATE_PRODUCTS_IN_CART || action.type === ERROR_UPDATE_PRODUCTS_IN_CART || action.type === SUCCESS_DELETE_PRODUCTS_FROM_CART || action.type === ERROR_DELETE_PRODUCTS_FROM_CART || action.type === SUCCESS_ADD_COUPONS_TO_CART || action.type === ERROR_ADD_COUPONS_TO_CART || action.type === SUCCESS_DELETE_COUPONS_FROM_CART || action.type === ERROR_DELETE_COUPONS_FROM_CART);
|
|
171
|
+
|
|
172
|
+
/**
|
|
51
173
|
* Gets triggered whenever any cart update request fails.
|
|
52
174
|
* @type {Observable}
|
|
53
|
-
*/
|
|
175
|
+
*/
|
|
176
|
+
export const cartUpdateFailed$ = main$.filter(({
|
|
177
|
+
action
|
|
178
|
+
}) => action.type === ERROR_ADD_PRODUCTS_TO_CART || action.type === ERROR_UPDATE_PRODUCTS_IN_CART || action.type === ERROR_DELETE_PRODUCTS_FROM_CART || action.type === ERROR_ADD_COUPONS_TO_CART || action.type === ERROR_DELETE_COUPONS_FROM_CART);
|
|
179
|
+
|
|
180
|
+
/**
|
|
54
181
|
* Gets triggered when /cart_add_product/123/COUPON route is navigated
|
|
55
182
|
* @type {Observable}
|
|
56
|
-
*/
|
|
183
|
+
*/
|
|
184
|
+
export const routeAddProductNavigate$ = navigate$.filter(({
|
|
185
|
+
action: {
|
|
186
|
+
params: {
|
|
187
|
+
pathname = ''
|
|
188
|
+
} = {}
|
|
189
|
+
}
|
|
190
|
+
}) => pathname.includes(DEEPLINK_CART_ADD_PRODUCT_PATTERN.split('/')[1])).map(params => {
|
|
191
|
+
const [,, productId, couponCode] = params.action.params.pathname.split('/');
|
|
192
|
+
return {
|
|
193
|
+
...params,
|
|
194
|
+
action: {
|
|
195
|
+
...params.action,
|
|
196
|
+
productId: decodeURIComponent(productId),
|
|
197
|
+
couponCode: couponCode ? decodeURIComponent(couponCode) : undefined
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
export const setFulfillmentSlot$ = main$.filter(({
|
|
202
|
+
action
|
|
203
|
+
}) => action.type === SET_FULFILLMENT_SLOT);
|