@ordergroove/offers 2.27.22 → 2.27.23-alpha-PR-672-4.2
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/dist/bundle-report.html +7 -7
- package/dist/offers.js +24 -24
- package/dist/offers.js.map +2 -2
- package/package.json +2 -2
- package/src/shopify/__tests__/shopifyReducer.spec.js +271 -137
- package/src/shopify/shopifyMiddleware.ts +7 -15
- package/src/shopify/shopifyReducer.js +107 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.23-alpha-PR-672-4.2+09921357",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@ordergroove/offers-templates": "^0.4.15"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "09921357b675720d65a998f45f8badeb642554bb"
|
|
49
49
|
}
|
|
@@ -52,14 +52,16 @@ describe('autoshipEligible', () => {
|
|
|
52
52
|
{
|
|
53
53
|
type: constants.SETUP_PRODUCT,
|
|
54
54
|
payload: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
product: {
|
|
56
|
+
id: 'yum product id',
|
|
57
|
+
selling_plan_allocations: [{ 'yum key': 'yum value' }],
|
|
58
|
+
variants: [
|
|
59
|
+
{
|
|
60
|
+
id: 'yum variant id',
|
|
61
|
+
selling_plan_allocations: [{ 'yum key': 'yum value' }]
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
);
|
|
@@ -73,14 +75,16 @@ describe('autoshipEligible', () => {
|
|
|
73
75
|
{
|
|
74
76
|
type: constants.SETUP_PRODUCT,
|
|
75
77
|
payload: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
product: {
|
|
79
|
+
id: 'yum product id',
|
|
80
|
+
selling_plan_allocations: [],
|
|
81
|
+
variants: [
|
|
82
|
+
{
|
|
83
|
+
id: 'yum variant id',
|
|
84
|
+
selling_plan_allocations: []
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
);
|
|
@@ -120,55 +124,27 @@ describe('config', () => {
|
|
|
120
124
|
);
|
|
121
125
|
});
|
|
122
126
|
|
|
123
|
-
it('should return first selling plan id as default frequency given action SETUP_PRODUCT', () => {
|
|
124
|
-
const actual = config(
|
|
125
|
-
{},
|
|
126
|
-
{
|
|
127
|
-
type: constants.SETUP_PRODUCT,
|
|
128
|
-
payload: {
|
|
129
|
-
selling_plan_groups: [
|
|
130
|
-
{
|
|
131
|
-
name: 'Subscribe and Save',
|
|
132
|
-
selling_plans: [
|
|
133
|
-
{
|
|
134
|
-
id: 'yum selling plan id 1'
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
id: 'yum selling plan id 2'
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
expect(actual).toEqual(
|
|
147
|
-
jasmine.objectContaining({
|
|
148
|
-
defaultFrequency: 'yum selling plan id 1'
|
|
149
|
-
})
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
127
|
it('should return selling plan ids as frequencies given action SETUP_PRODUCT', () => {
|
|
154
128
|
const actual = config(
|
|
155
129
|
{},
|
|
156
130
|
{
|
|
157
131
|
type: constants.SETUP_PRODUCT,
|
|
158
132
|
payload: {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
133
|
+
product: {
|
|
134
|
+
selling_plan_groups: [
|
|
135
|
+
{
|
|
136
|
+
name: 'Subscribe and Save',
|
|
137
|
+
selling_plans: [
|
|
138
|
+
{
|
|
139
|
+
id: 'yum selling plan id 1'
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: 'yum selling plan id 2'
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
172
148
|
}
|
|
173
149
|
}
|
|
174
150
|
);
|
|
@@ -186,26 +162,28 @@ describe('config', () => {
|
|
|
186
162
|
{
|
|
187
163
|
type: constants.SETUP_PRODUCT,
|
|
188
164
|
payload: {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
165
|
+
product: {
|
|
166
|
+
selling_plan_groups: [
|
|
167
|
+
{
|
|
168
|
+
name: 'Old Selling Plan Group',
|
|
169
|
+
options: [{ values: 'old yum values' }],
|
|
170
|
+
selling_plans: [
|
|
171
|
+
{
|
|
172
|
+
id: 'old yum selling plan id'
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: 'Subscribe and Save',
|
|
178
|
+
options: [{ values: 'yum values' }],
|
|
179
|
+
selling_plans: [
|
|
180
|
+
{
|
|
181
|
+
id: 'yum selling plan id'
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
}
|
|
209
187
|
}
|
|
210
188
|
}
|
|
211
189
|
);
|
|
@@ -264,14 +242,16 @@ describe('inStock', () => {
|
|
|
264
242
|
{
|
|
265
243
|
type: constants.SETUP_PRODUCT,
|
|
266
244
|
payload: {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
245
|
+
product: {
|
|
246
|
+
id: 'yum product id',
|
|
247
|
+
available: true,
|
|
248
|
+
variants: [
|
|
249
|
+
{
|
|
250
|
+
id: 'yum variant id',
|
|
251
|
+
available: true
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
}
|
|
275
255
|
}
|
|
276
256
|
}
|
|
277
257
|
);
|
|
@@ -288,14 +268,16 @@ describe('inStock', () => {
|
|
|
288
268
|
{
|
|
289
269
|
type: constants.SETUP_PRODUCT,
|
|
290
270
|
payload: {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
271
|
+
product: {
|
|
272
|
+
id: 'yum product id',
|
|
273
|
+
available: false,
|
|
274
|
+
variants: [
|
|
275
|
+
{
|
|
276
|
+
id: 'yum variant id',
|
|
277
|
+
available: false
|
|
278
|
+
}
|
|
279
|
+
]
|
|
280
|
+
}
|
|
299
281
|
}
|
|
300
282
|
}
|
|
301
283
|
);
|
|
@@ -365,6 +347,156 @@ describe('optedin', () => {
|
|
|
365
347
|
]);
|
|
366
348
|
});
|
|
367
349
|
|
|
350
|
+
it('should return existing optin given action RECEIVE_OFFER and optin already exists in state, and new optin is ineligible for autoship by default', () => {
|
|
351
|
+
const actual = optedin(
|
|
352
|
+
[
|
|
353
|
+
{
|
|
354
|
+
id: 'yum product id 1',
|
|
355
|
+
frequency: 'yum existing frequency'
|
|
356
|
+
}
|
|
357
|
+
],
|
|
358
|
+
{
|
|
359
|
+
type: constants.RECEIVE_OFFER,
|
|
360
|
+
payload: {
|
|
361
|
+
autoship: {
|
|
362
|
+
'yum product id 1': false
|
|
363
|
+
},
|
|
364
|
+
autoship_by_default: {
|
|
365
|
+
'yum product id 1': false
|
|
366
|
+
},
|
|
367
|
+
in_stock: {
|
|
368
|
+
'yum product id 1': false
|
|
369
|
+
},
|
|
370
|
+
offer: {
|
|
371
|
+
defaultFrequency: 'yum offer default frequency'
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
expect(actual).toEqual([
|
|
378
|
+
{
|
|
379
|
+
id: 'yum product id 1',
|
|
380
|
+
frequency: 'yum existing frequency'
|
|
381
|
+
}
|
|
382
|
+
]);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('should return existing optin given action RECEIVE_OFFER, optin already exists in state, and new optin is eligible for autoship by default', () => {
|
|
386
|
+
const actual = optedin(
|
|
387
|
+
[
|
|
388
|
+
{
|
|
389
|
+
id: 'yum product id 1',
|
|
390
|
+
frequency: 'yum existing frequency'
|
|
391
|
+
}
|
|
392
|
+
],
|
|
393
|
+
{
|
|
394
|
+
type: constants.RECEIVE_OFFER,
|
|
395
|
+
payload: {
|
|
396
|
+
autoship: {
|
|
397
|
+
'yum product id 1': true
|
|
398
|
+
},
|
|
399
|
+
autoship_by_default: {
|
|
400
|
+
'yum product id 1': true
|
|
401
|
+
},
|
|
402
|
+
in_stock: {
|
|
403
|
+
'yum product id 1': true
|
|
404
|
+
},
|
|
405
|
+
offer: {
|
|
406
|
+
defaultFrequency: 'yum offer default frequency'
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
expect(actual).toEqual([
|
|
413
|
+
{
|
|
414
|
+
id: 'yum product id 1',
|
|
415
|
+
frequency: 'yum existing frequency'
|
|
416
|
+
}
|
|
417
|
+
]);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('should return existing optin given action RECEIVE_OFFER, optin already exists in state, and new optin is eligible for autoship by default', () => {
|
|
421
|
+
const actual = optedin(
|
|
422
|
+
[
|
|
423
|
+
{
|
|
424
|
+
id: 'yum product id 1',
|
|
425
|
+
frequency: 'yum existing frequency'
|
|
426
|
+
}
|
|
427
|
+
],
|
|
428
|
+
{
|
|
429
|
+
type: constants.RECEIVE_OFFER,
|
|
430
|
+
payload: {
|
|
431
|
+
autoship: {
|
|
432
|
+
'yum product id 1': true
|
|
433
|
+
},
|
|
434
|
+
autoship_by_default: {
|
|
435
|
+
'yum product id 1': true
|
|
436
|
+
},
|
|
437
|
+
in_stock: {
|
|
438
|
+
'yum product id 1': true
|
|
439
|
+
},
|
|
440
|
+
offer: {
|
|
441
|
+
defaultFrequency: 'yum offer default frequency'
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
expect(actual).toEqual([
|
|
448
|
+
{
|
|
449
|
+
id: 'yum product id 1',
|
|
450
|
+
frequency: 'yum existing frequency'
|
|
451
|
+
}
|
|
452
|
+
]);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('should return no optin given action RECEIVE_OFFER, optin does not exist in state, and product is not eligible for default to subscription', () => {
|
|
456
|
+
const actual = optedin([], {
|
|
457
|
+
type: constants.RECEIVE_OFFER,
|
|
458
|
+
payload: {
|
|
459
|
+
product: {},
|
|
460
|
+
offer: {
|
|
461
|
+
autoship: false,
|
|
462
|
+
autoship_by_default: false,
|
|
463
|
+
in_stock: false
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
expect(actual).toEqual([]);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it('should return optin given action RECEIVE_OFFER, optin does not exist in state, and product is eligible for default to subscription', () => {
|
|
472
|
+
const actual = optedin(
|
|
473
|
+
[
|
|
474
|
+
{
|
|
475
|
+
id: 'yum item id 1',
|
|
476
|
+
frequency: 'yum selling plan id 1'
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
{
|
|
480
|
+
type: constants.RECEIVE_OFFER,
|
|
481
|
+
payload: {
|
|
482
|
+
product: {},
|
|
483
|
+
offer: {
|
|
484
|
+
autoship: true,
|
|
485
|
+
autoship_by_default: true,
|
|
486
|
+
in_stock: true
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
expect(actual).toEqual([
|
|
493
|
+
{
|
|
494
|
+
id: 'yum item id 1',
|
|
495
|
+
frequency: 'yum selling plan id 1'
|
|
496
|
+
}
|
|
497
|
+
]);
|
|
498
|
+
});
|
|
499
|
+
|
|
368
500
|
it('should return unmodified state given unsupported action', () => {
|
|
369
501
|
const actual = optedin(
|
|
370
502
|
{ 'yum existing key': 'yum existing value' },
|
|
@@ -393,48 +525,50 @@ describe('productPlans', () => {
|
|
|
393
525
|
{
|
|
394
526
|
type: constants.SETUP_PRODUCT,
|
|
395
527
|
payload: {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
528
|
+
product: {
|
|
529
|
+
id: 'yum product id',
|
|
530
|
+
selling_plan_allocations: [
|
|
531
|
+
{
|
|
532
|
+
selling_plan_id: 'yum selling plan id 1',
|
|
533
|
+
compare_at_price: 100,
|
|
534
|
+
price: 50,
|
|
535
|
+
price_adjustments: [
|
|
536
|
+
{
|
|
537
|
+
value: 50,
|
|
538
|
+
value_type: 'percentage'
|
|
539
|
+
}
|
|
540
|
+
]
|
|
541
|
+
}
|
|
542
|
+
],
|
|
543
|
+
variants: [
|
|
544
|
+
{
|
|
545
|
+
id: 'yum variant id 1',
|
|
546
|
+
selling_plan_allocations: [
|
|
547
|
+
{
|
|
548
|
+
selling_plan_id: 'yum selling plan id 2',
|
|
549
|
+
compare_at_price: 50,
|
|
550
|
+
price: 25,
|
|
551
|
+
price_adjustments: [
|
|
552
|
+
{
|
|
553
|
+
value: 25
|
|
554
|
+
}
|
|
555
|
+
]
|
|
556
|
+
}
|
|
557
|
+
]
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
id: 'yum variant id 2',
|
|
561
|
+
selling_plan_allocations: [
|
|
562
|
+
{
|
|
563
|
+
selling_plan_id: 'yum selling plan id 3',
|
|
564
|
+
compare_at_price: 10,
|
|
565
|
+
price: 8,
|
|
566
|
+
price_adjustments: []
|
|
567
|
+
}
|
|
568
|
+
]
|
|
569
|
+
}
|
|
570
|
+
]
|
|
571
|
+
}
|
|
438
572
|
}
|
|
439
573
|
}
|
|
440
574
|
);
|
|
@@ -38,7 +38,8 @@ async function setupPdp(store, offer) {
|
|
|
38
38
|
const handle = guessProductHandle();
|
|
39
39
|
if (handle) {
|
|
40
40
|
try {
|
|
41
|
-
|
|
41
|
+
const product = await getProduct(handle);
|
|
42
|
+
store.dispatch({ type: SETUP_PRODUCT, payload: { product, offer } });
|
|
42
43
|
} catch (err) {
|
|
43
44
|
console.warn('OG: Unable to fetch product details for PDP', err);
|
|
44
45
|
}
|
|
@@ -126,7 +127,7 @@ async function setupCart(store, offer) {
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
const products = await Promise.all(Array.from(new Set(items.map(({ handle }) => handle))).map(getProduct));
|
|
129
|
-
products.forEach(product => store.dispatch({ type: SETUP_PRODUCT, payload: product }));
|
|
130
|
+
products.forEach(product => store.dispatch({ type: SETUP_PRODUCT, payload: { product, offer } }));
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
/**
|
|
@@ -358,30 +359,21 @@ export default function shopifyMiddleware(store) {
|
|
|
358
359
|
* This redux middleware will perform Shopify specific side-effects such as change
|
|
359
360
|
* the product selling plan when offer is cart
|
|
360
361
|
*/
|
|
362
|
+
|
|
363
|
+
next(action);
|
|
364
|
+
|
|
361
365
|
switch (action.type) {
|
|
362
|
-
case
|
|
363
|
-
case OPTOUT_PRODUCT:
|
|
364
|
-
case PRODUCT_CHANGE_FREQUENCY:
|
|
365
|
-
break;
|
|
366
|
-
case REQUEST_OFFER:
|
|
366
|
+
case RECEIVE_OFFER:
|
|
367
367
|
if (action.payload.offer?.isCart) {
|
|
368
368
|
setupCart(store, action.payload.offer);
|
|
369
369
|
} else {
|
|
370
370
|
setupPdp(store, action.payload.offer);
|
|
371
371
|
}
|
|
372
372
|
break;
|
|
373
|
-
default:
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
next(action);
|
|
377
|
-
|
|
378
|
-
switch (action.type) {
|
|
379
373
|
case OPTIN_PRODUCT:
|
|
380
374
|
case OPTOUT_PRODUCT:
|
|
381
375
|
case PRODUCT_CHANGE_FREQUENCY:
|
|
382
376
|
synchronizeCartOptin(action, store);
|
|
383
|
-
case REQUEST_OFFER:
|
|
384
|
-
case RECEIVE_OFFER:
|
|
385
377
|
case SETUP_PRODUCT:
|
|
386
378
|
synchronizeSellingPlan(store, action.payload.offer);
|
|
387
379
|
break;
|