@ordergroove/offers 2.34.8-alpha-PR-784-7.8 → 2.34.9
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/CHANGELOG.md +19 -0
- package/dist/bundle-report.html +16 -16
- package/dist/examples.js.map +2 -2
- package/dist/offers.js +28 -28
- package/dist/offers.js.map +3 -3
- package/examples/index.js +1 -0
- package/package.json +2 -2
- package/src/components/PrepaidData.js +9 -6
- package/src/components/__tests__/PrepaidData.spec.js +23 -4
- package/src/shopify/__tests__/productPlan.spec.js +13 -13
- package/src/shopify/__tests__/shopifyReducer.spec.js +350 -417
- package/src/shopify/__tests__/utils.spec.js +3 -7
- package/src/shopify/reducers/productPlans.ts +19 -22
- package/src/shopify/shopifyBootstrap.ts +1 -9
- package/src/shopify/shopifyMiddleware.ts +3 -13
- package/src/shopify/shopifyReducer.js +3 -3
- package/src/shopify/types/shopify.ts +3 -3
- package/src/shopify/utils.ts +1 -7
package/examples/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.34.
|
|
3
|
+
"version": "2.34.9",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"@ordergroove/offers-templates": "^0.9.2",
|
|
49
49
|
"@types/lodash.memoize": "^4.1.9"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "a191165538ff5f2855d0a10a218eca99669602b5"
|
|
52
52
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { css, html } from 'lit-element';
|
|
2
2
|
import { connect } from '../core/connect';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
makeProductPrepaidShipmentOptionsSelector,
|
|
6
|
+
makeProductPrepaidShipmentsOptedInSelector,
|
|
7
|
+
makePrepaidShipmentsSelectedSelector
|
|
8
|
+
} from '../core/selectors';
|
|
7
9
|
import { safeProductId } from '../core/utils';
|
|
10
|
+
import { PrepaidStatus } from './PrepaidStatus';
|
|
8
11
|
|
|
9
|
-
export class PrepaidData extends
|
|
12
|
+
export class PrepaidData extends PrepaidStatus {
|
|
10
13
|
static get properties() {
|
|
11
14
|
return {
|
|
12
15
|
...super.properties,
|
|
13
|
-
shipmentsOptedIn: { type: Number },
|
|
14
16
|
productPlans: { type: Object },
|
|
15
17
|
prepaidShipmentsSelected: { type: Number },
|
|
16
18
|
totalPrice: { type: Boolean, reflect: true, attribute: 'total-price' },
|
|
@@ -36,7 +38,7 @@ export class PrepaidData extends withProduct(TemplateElement) {
|
|
|
36
38
|
const realProductId = safeProductId(this.product);
|
|
37
39
|
const plans = this.productPlans[realProductId] || [];
|
|
38
40
|
|
|
39
|
-
const targetShipments = this.
|
|
41
|
+
const targetShipments = this.selectedNumberOfShipments;
|
|
40
42
|
let currentPlan = plans.find(plan => plan.prepaidShipments > 1 && plan.prepaidShipments === targetShipments);
|
|
41
43
|
|
|
42
44
|
if (!currentPlan) {
|
|
@@ -100,6 +102,7 @@ export class PrepaidData extends withProduct(TemplateElement) {
|
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
const mapStateToProps = (state, ownProps) => ({
|
|
105
|
+
options: makeProductPrepaidShipmentOptionsSelector(ownProps.product.id)(state),
|
|
103
106
|
shipmentsOptedIn: makeProductPrepaidShipmentsOptedInSelector(ownProps.product)(state),
|
|
104
107
|
prepaidShipmentsSelected: makePrepaidShipmentsSelectedSelector(ownProps.product)(state),
|
|
105
108
|
productPlans: state.productPlans
|
|
@@ -18,7 +18,7 @@ const productPlanPayload = {
|
|
|
18
18
|
frequency: 'prepaid-selling-plan-id-1',
|
|
19
19
|
regularPrice: '$5.00',
|
|
20
20
|
subscriptionPrice: '$4.00',
|
|
21
|
-
discountRate: '
|
|
21
|
+
discountRate: '15%',
|
|
22
22
|
prepaidShipments: 3,
|
|
23
23
|
regularPrepaidPrice: '$12.00',
|
|
24
24
|
prepaidSavingsPerShipment: '$1.00',
|
|
@@ -60,6 +60,7 @@ async function renderPrepaidDataTemplate({
|
|
|
60
60
|
expect(document.body.querySelector(TAG_NAME_UNDER_TEST)).toBeFalsy();
|
|
61
61
|
render(template, document.getElementById(TEST_CONTAINER_ID));
|
|
62
62
|
const element = document.querySelector(TAG_NAME_UNDER_TEST);
|
|
63
|
+
element.options = [3, 6, 12];
|
|
63
64
|
element.shipmentsOptedIn = shipmentsOptedIn;
|
|
64
65
|
element.prepaidShipmentsSelected = prepaidShipmentsSelected;
|
|
65
66
|
element.productPlans = productPlans;
|
|
@@ -87,7 +88,7 @@ describe('PrepaidData', () => {
|
|
|
87
88
|
`;
|
|
88
89
|
const prepaidDataDiv = await renderPrepaidDataTemplate({ template });
|
|
89
90
|
const insideText = prepaidDataDiv.shadowRoot.textContent.trim();
|
|
90
|
-
expect(insideText).toBe('$
|
|
91
|
+
expect(insideText).toBe('$24.00');
|
|
91
92
|
});
|
|
92
93
|
|
|
93
94
|
it('should render total prepaid price for 6 shipments', async () => {
|
|
@@ -123,7 +124,7 @@ describe('PrepaidData', () => {
|
|
|
123
124
|
`;
|
|
124
125
|
const prepaidDataDiv = await renderPrepaidDataTemplate({ template });
|
|
125
126
|
const insideText = prepaidDataDiv.shadowRoot.textContent.trim();
|
|
126
|
-
expect(insideText).toBe('$
|
|
127
|
+
expect(insideText).toBe('$6.00');
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
it('should render per delivery savings price', async () => {
|
|
@@ -144,6 +145,15 @@ describe('PrepaidData', () => {
|
|
|
144
145
|
expect(insideText).toBe('20%');
|
|
145
146
|
});
|
|
146
147
|
|
|
148
|
+
it('should render percentage savings of default shipments', async () => {
|
|
149
|
+
const template = html`
|
|
150
|
+
<og-some-prepaid-data percentage-savings default-prepaid-shipments="12" product="yum id"></og-some-prepaid-data>
|
|
151
|
+
`;
|
|
152
|
+
const prepaidDataDiv = await renderPrepaidDataTemplate({ template });
|
|
153
|
+
const insideText = prepaidDataDiv.shadowRoot.textContent.trim();
|
|
154
|
+
expect(insideText).toBe('25%');
|
|
155
|
+
});
|
|
156
|
+
|
|
147
157
|
it('should render extraPercentageSavings savings', async () => {
|
|
148
158
|
const template = html`
|
|
149
159
|
<og-some-prepaid-data extra-percentage-savings product="yum id"></og-some-prepaid-data>
|
|
@@ -159,7 +169,16 @@ describe('PrepaidData', () => {
|
|
|
159
169
|
`;
|
|
160
170
|
const prepaidDataDiv = await renderPrepaidDataTemplate({ template });
|
|
161
171
|
const insideText = prepaidDataDiv.shadowRoot.textContent.trim();
|
|
162
|
-
expect(insideText).toBe('
|
|
172
|
+
expect(insideText).toBe('6');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('should render numberOfShipments of default shipments', async () => {
|
|
176
|
+
const template = html`
|
|
177
|
+
<og-some-prepaid-data number-of-shipments default-prepaid-shipments="12" product="yum id"></og-some-prepaid-data>
|
|
178
|
+
`;
|
|
179
|
+
const prepaidDataDiv = await renderPrepaidDataTemplate({ template });
|
|
180
|
+
const insideText = prepaidDataDiv.shadowRoot.textContent.trim();
|
|
181
|
+
expect(insideText).toBe('12');
|
|
163
182
|
});
|
|
164
183
|
|
|
165
184
|
it('should render nothing when no property is provided', async () => {
|
|
@@ -98,7 +98,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
98
98
|
const allocation = {
|
|
99
99
|
price: 1350
|
|
100
100
|
};
|
|
101
|
-
expect(getAllocationSubscriptionPrice(allocation
|
|
101
|
+
expect(getAllocationSubscriptionPrice(allocation)).toBe('$13.50');
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
it('should return per delivery money price for prepaid subscription', () => {
|
|
@@ -119,7 +119,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
119
119
|
]
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
expect(getAllocationSubscriptionPrice(allocation
|
|
122
|
+
expect(getAllocationSubscriptionPrice(allocation)).toBe('$10.00');
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
125
|
|
|
@@ -128,14 +128,14 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
128
128
|
const allocation = {
|
|
129
129
|
price_adjustments: [{ position: 1, value: 10, value_type: 'percentage' }]
|
|
130
130
|
};
|
|
131
|
-
expect(getAllocationDiscountRate(allocation
|
|
131
|
+
expect(getAllocationDiscountRate(allocation)).toBe('10%');
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
it('should return discount for pay-as-you-go subscription from price adjustment', () => {
|
|
135
135
|
const allocation = {
|
|
136
136
|
price_adjustments: [{ position: 1, value: 1050 }]
|
|
137
137
|
};
|
|
138
|
-
expect(getAllocationDiscountRate(allocation
|
|
138
|
+
expect(getAllocationDiscountRate(allocation)).toBe('$10.50');
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
it('should return discount for pay-as-you-go subscription from compare_at_price', () => {
|
|
@@ -144,7 +144,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
144
144
|
price: 1200,
|
|
145
145
|
price_adjustments: []
|
|
146
146
|
};
|
|
147
|
-
expect(getAllocationDiscountRate(allocation
|
|
147
|
+
expect(getAllocationDiscountRate(allocation)).toBe('$1.50');
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
it('should return prepaid percentage discount when prepaid options are present - 3 shipments', () => {
|
|
@@ -166,7 +166,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
166
166
|
]
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
|
-
expect(getAllocationDiscountRate(allocation
|
|
169
|
+
expect(getAllocationDiscountRate(allocation)).toBe('20%');
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
it('should return prepaid percentage discount when prepaid options are present - 12 shipments', () => {
|
|
@@ -232,7 +232,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
232
232
|
prepaidSavingsTotal: '$6.00'
|
|
233
233
|
};
|
|
234
234
|
|
|
235
|
-
const newProductPlan = addPrepaidPriceAndSavings(allocation, productPlan
|
|
235
|
+
const newProductPlan = addPrepaidPriceAndSavings(allocation, productPlan);
|
|
236
236
|
|
|
237
237
|
expect(newProductPlan).toEqual(expectedProductPlan);
|
|
238
238
|
});
|
|
@@ -276,7 +276,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
276
276
|
prepaidSavingsTotal: '$11.99'
|
|
277
277
|
};
|
|
278
278
|
|
|
279
|
-
const newProductPlan = addPrepaidPriceAndSavings(allocation, productPlan
|
|
279
|
+
const newProductPlan = addPrepaidPriceAndSavings(allocation, productPlan);
|
|
280
280
|
|
|
281
281
|
expect(newProductPlan).toEqual(expectedProductPlan);
|
|
282
282
|
});
|
|
@@ -302,11 +302,11 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
302
302
|
frequency: '688412655892',
|
|
303
303
|
regularPrice: '$5.00',
|
|
304
304
|
subscriptionPrice: '$4.50',
|
|
305
|
-
discountRate: '
|
|
305
|
+
discountRate: '$.50',
|
|
306
306
|
prepaidShipments: null
|
|
307
307
|
};
|
|
308
308
|
|
|
309
|
-
const productPlanCreated = mapSellingPlanToDiscount(allocation
|
|
309
|
+
const productPlanCreated = mapSellingPlanToDiscount(allocation);
|
|
310
310
|
|
|
311
311
|
expect(productPlanCreated).toEqual(expectedProductPlan);
|
|
312
312
|
});
|
|
@@ -366,7 +366,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
366
366
|
prepaidSavingsTotal: '$12.00'
|
|
367
367
|
};
|
|
368
368
|
|
|
369
|
-
const productPlanCreated = mapSellingPlanToDiscount(allocation, sellingPlans
|
|
369
|
+
const productPlanCreated = mapSellingPlanToDiscount(allocation, sellingPlans);
|
|
370
370
|
|
|
371
371
|
expect(productPlanCreated).toEqual(expectedProductPlan);
|
|
372
372
|
});
|
|
@@ -416,7 +416,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
416
416
|
|
|
417
417
|
const expectedsubscriptionPrice = '$15.99';
|
|
418
418
|
|
|
419
|
-
const productPlanCreated = mapSellingPlanToDiscount(allocation, sellingPlans
|
|
419
|
+
const productPlanCreated = mapSellingPlanToDiscount(allocation, sellingPlans);
|
|
420
420
|
|
|
421
421
|
expect(productPlanCreated.subscriptionPrice).toEqual(expectedsubscriptionPrice);
|
|
422
422
|
});
|
|
@@ -500,7 +500,7 @@ describe('Shopify productPlan Reducer', () => {
|
|
|
500
500
|
prepaidExtraSavingsPercentage: '10%'
|
|
501
501
|
};
|
|
502
502
|
|
|
503
|
-
const productPlanCreated = mapSellingPlanToDiscount(allocation, sellingPlans
|
|
503
|
+
const productPlanCreated = mapSellingPlanToDiscount(allocation, sellingPlans);
|
|
504
504
|
|
|
505
505
|
expect(productPlanCreated).toEqual(expectedProductPlan);
|
|
506
506
|
});
|