@shopgate/pwa-common-commerce 7.31.5 → 7.31.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-common-commerce",
3
- "version": "7.31.5",
3
+ "version": "7.31.6",
4
4
  "description": "Commerce library for the Shopgate Connect PWA.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -20,8 +20,8 @@
20
20
  "reselect": "^4.1.8"
21
21
  },
22
22
  "devDependencies": {
23
- "@shopgate/pwa-common": "7.31.5",
24
- "@shopgate/pwa-core": "7.31.5",
23
+ "@shopgate/pwa-common": "7.31.6",
24
+ "@shopgate/pwa-core": "7.31.6",
25
25
  "@types/lodash": "^4.17.24",
26
26
  "lodash": "^4.17.23",
27
27
  "react": "^17.0.2",
@@ -1,189 +0,0 @@
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 */