@ordergroove/offers 2.27.23 → 2.28.1
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 +29 -0
- package/README.md +24 -1
- package/dist/bundle-report.html +40 -37
- package/dist/offers.js +54 -54
- package/dist/offers.js.map +3 -3
- package/karma-shopify.conf.js +79 -0
- package/karma.conf.js +1 -1
- package/package.json +6 -4
- package/src/components/Offer.js +1 -0
- package/src/components/OptinButton.js +25 -5
- package/src/components/OptinSelect.js +2 -4
- package/src/components/OptinStatus.js +5 -1
- package/src/components/OptinToggle.js +9 -2
- package/src/components/__tests__/OG.fspec.js +84 -2
- package/src/core/__tests__/utils.spec.js +26 -0
- package/src/core/selectors.js +18 -1
- package/src/core/store.js +3 -2
- package/src/core/utils.ts +45 -6
- package/src/core/waitUntilOffersReady.js +66 -0
- package/src/index.js +6 -2
- package/src/init-shopify-tests.js +7 -0
- package/src/make-api.js +5 -15
- package/src/shopify/__tests__/shopifyReducer.spec.js +915 -122
- package/src/shopify/shopifyMiddleware.ts +4 -3
- package/src/shopify/shopifyReducer.js +169 -34
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as constants from '../../core/constants';
|
|
2
|
-
import * as coreReducers from '../../core/reducer';
|
|
3
2
|
import {
|
|
4
3
|
autoshipEligible,
|
|
5
4
|
config,
|
|
@@ -52,14 +51,16 @@ describe('autoshipEligible', () => {
|
|
|
52
51
|
{
|
|
53
52
|
type: constants.SETUP_PRODUCT,
|
|
54
53
|
payload: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
product: {
|
|
55
|
+
id: 'yum product id',
|
|
56
|
+
selling_plan_allocations: [{ 'yum key': 'yum value' }],
|
|
57
|
+
variants: [
|
|
58
|
+
{
|
|
59
|
+
id: 'yum variant id',
|
|
60
|
+
selling_plan_allocations: [{ 'yum key': 'yum value' }]
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
);
|
|
@@ -73,14 +74,16 @@ describe('autoshipEligible', () => {
|
|
|
73
74
|
{
|
|
74
75
|
type: constants.SETUP_PRODUCT,
|
|
75
76
|
payload: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
product: {
|
|
78
|
+
id: 'yum product id',
|
|
79
|
+
selling_plan_allocations: [],
|
|
80
|
+
variants: [
|
|
81
|
+
{
|
|
82
|
+
id: 'yum variant id',
|
|
83
|
+
selling_plan_allocations: []
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
);
|
|
@@ -120,25 +123,95 @@ describe('config', () => {
|
|
|
120
123
|
);
|
|
121
124
|
});
|
|
122
125
|
|
|
123
|
-
it('should
|
|
126
|
+
it('should set defaultFrequency to selling plan given selling plan exists for frequency given action SETUP_PRODUCT', () => {
|
|
124
127
|
const actual = config(
|
|
125
|
-
{
|
|
128
|
+
{
|
|
129
|
+
defaultFrequency: '1_2'
|
|
130
|
+
},
|
|
126
131
|
{
|
|
127
132
|
type: constants.SETUP_PRODUCT,
|
|
128
133
|
payload: {
|
|
129
|
-
|
|
130
|
-
{
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
id: 'yum selling plan id 1'
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
id: 'yum selling plan id 2'
|
|
138
|
-
}
|
|
139
|
-
]
|
|
134
|
+
offer: {
|
|
135
|
+
config: {
|
|
136
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
137
|
+
frequenciesEveryPeriod: ['1_1', '1_2']
|
|
140
138
|
}
|
|
141
|
-
|
|
139
|
+
},
|
|
140
|
+
product: {
|
|
141
|
+
selling_plan_groups: [
|
|
142
|
+
{
|
|
143
|
+
name: 'Subscribe and Save',
|
|
144
|
+
selling_plans: [
|
|
145
|
+
{
|
|
146
|
+
id: 'yum selling plan id 1',
|
|
147
|
+
options: [
|
|
148
|
+
{
|
|
149
|
+
value: '1 day'
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: 'yum selling plan id 2',
|
|
155
|
+
options: [
|
|
156
|
+
{
|
|
157
|
+
value: '1 week'
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
expect(actual).toEqual(
|
|
170
|
+
jasmine.objectContaining({
|
|
171
|
+
defaultFrequency: 'yum selling plan id 2'
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should set defaultFrequency to first selling plan given selling plan does not exist for frequency given action SETUP_PRODUCT', () => {
|
|
177
|
+
const actual = config(
|
|
178
|
+
{
|
|
179
|
+
defaultFrequency: '1_3'
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
type: constants.SETUP_PRODUCT,
|
|
183
|
+
payload: {
|
|
184
|
+
offer: {
|
|
185
|
+
config: {
|
|
186
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
187
|
+
frequenciesEveryPeriod: ['1_1', '1_2']
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
product: {
|
|
191
|
+
selling_plan_groups: [
|
|
192
|
+
{
|
|
193
|
+
name: 'Subscribe and Save',
|
|
194
|
+
selling_plans: [
|
|
195
|
+
{
|
|
196
|
+
id: 'yum selling plan id 1',
|
|
197
|
+
options: [
|
|
198
|
+
{
|
|
199
|
+
value: '1 day'
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
id: 'yum selling plan id 2',
|
|
205
|
+
options: [
|
|
206
|
+
{
|
|
207
|
+
value: '1 week'
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
]
|
|
214
|
+
}
|
|
142
215
|
}
|
|
143
216
|
}
|
|
144
217
|
);
|
|
@@ -150,25 +223,77 @@ describe('config', () => {
|
|
|
150
223
|
);
|
|
151
224
|
});
|
|
152
225
|
|
|
226
|
+
it('should not change default frequency if is already a selling plan given action SETUP_PRODUCT', () => {
|
|
227
|
+
const actual = config(
|
|
228
|
+
{
|
|
229
|
+
defaultFrequency: 'yum selling plan id 5'
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
type: constants.SETUP_PRODUCT,
|
|
233
|
+
payload: {
|
|
234
|
+
offer: {
|
|
235
|
+
config: {
|
|
236
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
237
|
+
frequenciesEveryPeriod: ['1_1', '1_2']
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
product: {
|
|
241
|
+
selling_plan_groups: [
|
|
242
|
+
{
|
|
243
|
+
name: 'Subscribe and Save',
|
|
244
|
+
selling_plans: [
|
|
245
|
+
{
|
|
246
|
+
id: 'yum selling plan id 1',
|
|
247
|
+
options: [
|
|
248
|
+
{
|
|
249
|
+
value: '1 day'
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: 'yum selling plan id 2',
|
|
255
|
+
options: [
|
|
256
|
+
{
|
|
257
|
+
value: '1 week'
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
expect(actual).toEqual(
|
|
270
|
+
jasmine.objectContaining({
|
|
271
|
+
defaultFrequency: 'yum selling plan id 5'
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
|
|
153
276
|
it('should return selling plan ids as frequencies given action SETUP_PRODUCT', () => {
|
|
154
277
|
const actual = config(
|
|
155
278
|
{},
|
|
156
279
|
{
|
|
157
280
|
type: constants.SETUP_PRODUCT,
|
|
158
281
|
payload: {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
282
|
+
product: {
|
|
283
|
+
selling_plan_groups: [
|
|
284
|
+
{
|
|
285
|
+
name: 'Subscribe and Save',
|
|
286
|
+
selling_plans: [
|
|
287
|
+
{
|
|
288
|
+
id: 'yum selling plan id 1'
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
id: 'yum selling plan id 2'
|
|
292
|
+
}
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
]
|
|
296
|
+
}
|
|
172
297
|
}
|
|
173
298
|
}
|
|
174
299
|
);
|
|
@@ -186,26 +311,28 @@ describe('config', () => {
|
|
|
186
311
|
{
|
|
187
312
|
type: constants.SETUP_PRODUCT,
|
|
188
313
|
payload: {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
314
|
+
product: {
|
|
315
|
+
selling_plan_groups: [
|
|
316
|
+
{
|
|
317
|
+
name: 'Old Selling Plan Group',
|
|
318
|
+
options: [{ values: 'old yum values' }],
|
|
319
|
+
selling_plans: [
|
|
320
|
+
{
|
|
321
|
+
id: 'old yum selling plan id'
|
|
322
|
+
}
|
|
323
|
+
]
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: 'Subscribe and Save',
|
|
327
|
+
options: [{ values: 'yum values' }],
|
|
328
|
+
selling_plans: [
|
|
329
|
+
{
|
|
330
|
+
id: 'yum selling plan id'
|
|
331
|
+
}
|
|
332
|
+
]
|
|
333
|
+
}
|
|
334
|
+
]
|
|
335
|
+
}
|
|
209
336
|
}
|
|
210
337
|
}
|
|
211
338
|
);
|
|
@@ -264,14 +391,16 @@ describe('inStock', () => {
|
|
|
264
391
|
{
|
|
265
392
|
type: constants.SETUP_PRODUCT,
|
|
266
393
|
payload: {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
394
|
+
product: {
|
|
395
|
+
id: 'yum product id',
|
|
396
|
+
available: true,
|
|
397
|
+
variants: [
|
|
398
|
+
{
|
|
399
|
+
id: 'yum variant id',
|
|
400
|
+
available: true
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
}
|
|
275
404
|
}
|
|
276
405
|
}
|
|
277
406
|
);
|
|
@@ -288,14 +417,16 @@ describe('inStock', () => {
|
|
|
288
417
|
{
|
|
289
418
|
type: constants.SETUP_PRODUCT,
|
|
290
419
|
payload: {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
420
|
+
product: {
|
|
421
|
+
id: 'yum product id',
|
|
422
|
+
available: false,
|
|
423
|
+
variants: [
|
|
424
|
+
{
|
|
425
|
+
id: 'yum variant id',
|
|
426
|
+
available: false
|
|
427
|
+
}
|
|
428
|
+
]
|
|
429
|
+
}
|
|
299
430
|
}
|
|
300
431
|
}
|
|
301
432
|
);
|
|
@@ -365,6 +496,666 @@ describe('optedin', () => {
|
|
|
365
496
|
]);
|
|
366
497
|
});
|
|
367
498
|
|
|
499
|
+
describe('given action RECEIVE_OFFER', () => {
|
|
500
|
+
describe('given optin already in state', () => {
|
|
501
|
+
describe('given optin does not have selling plan', () => {
|
|
502
|
+
it('should set frequency to the selling plan given there is a matching selling plan', () => {
|
|
503
|
+
const actual = optedin(
|
|
504
|
+
[
|
|
505
|
+
{
|
|
506
|
+
id: 'yum product id 1',
|
|
507
|
+
frequency: '1_2'
|
|
508
|
+
}
|
|
509
|
+
],
|
|
510
|
+
{
|
|
511
|
+
type: constants.RECEIVE_OFFER,
|
|
512
|
+
payload: {
|
|
513
|
+
offer: {
|
|
514
|
+
config: {
|
|
515
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
516
|
+
frequenciesEveryPeriod: ['1_1', '1_2']
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
expect(actual).toEqual([
|
|
524
|
+
{
|
|
525
|
+
id: 'yum product id 1',
|
|
526
|
+
frequency: 'yum selling plan id 2'
|
|
527
|
+
}
|
|
528
|
+
]);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('should set frequency to default selling plan given there is not a matching selling plan but there is a matching default sellin gplan', () => {
|
|
532
|
+
const actual = optedin(
|
|
533
|
+
[
|
|
534
|
+
{
|
|
535
|
+
id: 'yum product id 1',
|
|
536
|
+
frequency: '1_2'
|
|
537
|
+
}
|
|
538
|
+
],
|
|
539
|
+
{
|
|
540
|
+
type: constants.RECEIVE_OFFER,
|
|
541
|
+
payload: {
|
|
542
|
+
offer: {
|
|
543
|
+
config: {
|
|
544
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
545
|
+
frequenciesEveryPeriod: ['3_1', '3_2']
|
|
546
|
+
},
|
|
547
|
+
defaultFrequency: '3_2'
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
expect(actual).toEqual([
|
|
554
|
+
{
|
|
555
|
+
id: 'yum product id 1',
|
|
556
|
+
frequency: 'yum selling plan id 2'
|
|
557
|
+
}
|
|
558
|
+
]);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
it('should set frequency to first selling plan given there is not a matching selling plan or default selling plan', () => {
|
|
562
|
+
const actual = optedin(
|
|
563
|
+
[
|
|
564
|
+
{
|
|
565
|
+
id: 'yum product id 1',
|
|
566
|
+
frequency: '1_2'
|
|
567
|
+
}
|
|
568
|
+
],
|
|
569
|
+
{
|
|
570
|
+
type: constants.RECEIVE_OFFER,
|
|
571
|
+
payload: {
|
|
572
|
+
offer: {
|
|
573
|
+
config: {
|
|
574
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
575
|
+
frequenciesEveryPeriod: ['3_1', '3_2']
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
expect(actual).toEqual([
|
|
583
|
+
{
|
|
584
|
+
id: 'yum product id 1',
|
|
585
|
+
frequency: 'yum selling plan id 1'
|
|
586
|
+
}
|
|
587
|
+
]);
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('should not change frequency given optin already has a selling plan', () => {
|
|
592
|
+
const actual = optedin(
|
|
593
|
+
[
|
|
594
|
+
{
|
|
595
|
+
id: 'yum product id 1',
|
|
596
|
+
frequency: 'yum selling plan id 1'
|
|
597
|
+
}
|
|
598
|
+
],
|
|
599
|
+
{
|
|
600
|
+
type: constants.RECEIVE_OFFER,
|
|
601
|
+
payload: {
|
|
602
|
+
offer: {
|
|
603
|
+
config: {
|
|
604
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
605
|
+
frequenciesEveryPeriod: ['1_1', '1_2']
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
);
|
|
611
|
+
|
|
612
|
+
expect(actual).toEqual([
|
|
613
|
+
{
|
|
614
|
+
id: 'yum product id 1',
|
|
615
|
+
frequency: 'yum selling plan id 1'
|
|
616
|
+
}
|
|
617
|
+
]);
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
describe('given optin not already in state', () => {
|
|
622
|
+
describe('given offer is eligible for autoship by default', () => {
|
|
623
|
+
describe('given offer has PSDF', () => {
|
|
624
|
+
describe('given selling plans are set', () => {
|
|
625
|
+
it('should set frequency to the selling plan given there is a matching selling plan', () => {
|
|
626
|
+
const actual = optedin([], {
|
|
627
|
+
type: constants.RECEIVE_OFFER,
|
|
628
|
+
payload: {
|
|
629
|
+
autoship: {
|
|
630
|
+
'yum product id 1': true
|
|
631
|
+
},
|
|
632
|
+
autoship_by_default: {
|
|
633
|
+
'yum product id 1': true
|
|
634
|
+
},
|
|
635
|
+
default_frequencies: {
|
|
636
|
+
'yum product id 1': {
|
|
637
|
+
every: 1,
|
|
638
|
+
every_period: 2
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
in_stock: {
|
|
642
|
+
'yum product id 1': true
|
|
643
|
+
},
|
|
644
|
+
offer: {
|
|
645
|
+
config: {
|
|
646
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
647
|
+
frequenciesEveryPeriod: ['1_1', '1_2']
|
|
648
|
+
},
|
|
649
|
+
defaultFrequency: 'yum offer default frequency'
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
expect(actual).toEqual([
|
|
654
|
+
{
|
|
655
|
+
id: 'yum product id 1',
|
|
656
|
+
frequency: 'yum selling plan id 2'
|
|
657
|
+
}
|
|
658
|
+
]);
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
describe('given there is no matching selling plan for PSDF', () => {
|
|
662
|
+
it('should set frequency to offer element default frequency given offer element default frequency is a selling plan', () => {
|
|
663
|
+
const actual = optedin([], {
|
|
664
|
+
type: constants.RECEIVE_OFFER,
|
|
665
|
+
payload: {
|
|
666
|
+
autoship: {
|
|
667
|
+
'yum product id 1': true
|
|
668
|
+
},
|
|
669
|
+
autoship_by_default: {
|
|
670
|
+
'yum product id 1': true
|
|
671
|
+
},
|
|
672
|
+
default_frequencies: {
|
|
673
|
+
'yum product id 1': {
|
|
674
|
+
every: 1,
|
|
675
|
+
every_period: 2
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
in_stock: {
|
|
679
|
+
'yum product id 1': true
|
|
680
|
+
},
|
|
681
|
+
offer: {
|
|
682
|
+
config: {
|
|
683
|
+
frequencies: ['yum selling plan id 1'],
|
|
684
|
+
frequenciesEveryPeriod: ['1_1']
|
|
685
|
+
},
|
|
686
|
+
defaultFrequency: 'yum offer default selling plan'
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
expect(actual).toEqual([
|
|
691
|
+
{
|
|
692
|
+
id: 'yum product id 1',
|
|
693
|
+
frequency: 'yum offer default selling plan'
|
|
694
|
+
}
|
|
695
|
+
]);
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
it('should set frequency to the selling plan of the offer element default frequency given the offer element default frequency has a matching selling plan', () => {
|
|
699
|
+
const actual = optedin([], {
|
|
700
|
+
type: constants.RECEIVE_OFFER,
|
|
701
|
+
payload: {
|
|
702
|
+
autoship: {
|
|
703
|
+
'yum product id 1': true
|
|
704
|
+
},
|
|
705
|
+
autoship_by_default: {
|
|
706
|
+
'yum product id 1': true
|
|
707
|
+
},
|
|
708
|
+
default_frequencies: {
|
|
709
|
+
'yum product id 1': {
|
|
710
|
+
every: 1,
|
|
711
|
+
every_period: 2
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
in_stock: {
|
|
715
|
+
'yum product id 1': true
|
|
716
|
+
},
|
|
717
|
+
offer: {
|
|
718
|
+
config: {
|
|
719
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 3'],
|
|
720
|
+
frequenciesEveryPeriod: ['1_1', '1_3']
|
|
721
|
+
},
|
|
722
|
+
defaultFrequency: '1_3'
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
expect(actual).toEqual([
|
|
727
|
+
{
|
|
728
|
+
id: 'yum product id 1',
|
|
729
|
+
frequency: 'yum selling plan id 3'
|
|
730
|
+
}
|
|
731
|
+
]);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
it('should set frequency to the first selling plan given the offer element default frequency is not a selling plan and does not have a matching selling plan', () => {
|
|
735
|
+
const actual = optedin([], {
|
|
736
|
+
type: constants.RECEIVE_OFFER,
|
|
737
|
+
payload: {
|
|
738
|
+
autoship: {
|
|
739
|
+
'yum product id 1': true
|
|
740
|
+
},
|
|
741
|
+
autoship_by_default: {
|
|
742
|
+
'yum product id 1': true
|
|
743
|
+
},
|
|
744
|
+
default_frequencies: {
|
|
745
|
+
'yum product id 1': {
|
|
746
|
+
every: 1,
|
|
747
|
+
every_period: 2
|
|
748
|
+
}
|
|
749
|
+
},
|
|
750
|
+
in_stock: {
|
|
751
|
+
'yum product id 1': true
|
|
752
|
+
},
|
|
753
|
+
offer: {
|
|
754
|
+
config: {
|
|
755
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 4'],
|
|
756
|
+
frequenciesEveryPeriod: ['1_1', '1_4']
|
|
757
|
+
},
|
|
758
|
+
defaultFrequency: '1_3'
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
expect(actual).toEqual([
|
|
763
|
+
{
|
|
764
|
+
id: 'yum product id 1',
|
|
765
|
+
frequency: 'yum selling plan id 1'
|
|
766
|
+
}
|
|
767
|
+
]);
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
it('should set frequency to every_everyPeriod psdf given selling plans are not set', () => {
|
|
773
|
+
const actual = optedin([], {
|
|
774
|
+
type: constants.RECEIVE_OFFER,
|
|
775
|
+
payload: {
|
|
776
|
+
autoship: {
|
|
777
|
+
'yum product id 1': true
|
|
778
|
+
},
|
|
779
|
+
autoship_by_default: {
|
|
780
|
+
'yum product id 1': true
|
|
781
|
+
},
|
|
782
|
+
default_frequencies: {
|
|
783
|
+
'yum product id 1': {
|
|
784
|
+
every: 1,
|
|
785
|
+
every_period: 2
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
in_stock: {
|
|
789
|
+
'yum product id 1': true
|
|
790
|
+
},
|
|
791
|
+
offer: {
|
|
792
|
+
defaultFrequency: 'yum offer default frequency'
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
expect(actual).toEqual([
|
|
797
|
+
{
|
|
798
|
+
id: 'yum product id 1',
|
|
799
|
+
frequency: '1_2'
|
|
800
|
+
}
|
|
801
|
+
]);
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
describe('given offer does not have PSDF', () => {
|
|
806
|
+
it('should set frequency to offer element default frequency given offer element default frequency is selling plan', () => {
|
|
807
|
+
const actual = optedin([], {
|
|
808
|
+
type: constants.RECEIVE_OFFER,
|
|
809
|
+
payload: {
|
|
810
|
+
autoship: {
|
|
811
|
+
'yum product id 1': true
|
|
812
|
+
},
|
|
813
|
+
autoship_by_default: {
|
|
814
|
+
'yum product id 1': true
|
|
815
|
+
},
|
|
816
|
+
in_stock: {
|
|
817
|
+
'yum product id 1': true
|
|
818
|
+
},
|
|
819
|
+
offer: {
|
|
820
|
+
config: {
|
|
821
|
+
frequencies: ['yum selling plan id 1'],
|
|
822
|
+
frequenciesEveryPeriod: ['1_1']
|
|
823
|
+
},
|
|
824
|
+
defaultFrequency: 'yum offer default selling plan'
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
expect(actual).toEqual([
|
|
829
|
+
{
|
|
830
|
+
id: 'yum product id 1',
|
|
831
|
+
frequency: 'yum offer default selling plan'
|
|
832
|
+
}
|
|
833
|
+
]);
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
describe('given selling plans are set', () => {
|
|
837
|
+
it('should set frequency to the selling plan of offer element default frequency given there is a matching selling plan for offer element default frequency', () => {
|
|
838
|
+
const actual = optedin([], {
|
|
839
|
+
type: constants.RECEIVE_OFFER,
|
|
840
|
+
payload: {
|
|
841
|
+
autoship: {
|
|
842
|
+
'yum product id 1': true
|
|
843
|
+
},
|
|
844
|
+
autoship_by_default: {
|
|
845
|
+
'yum product id 1': true
|
|
846
|
+
},
|
|
847
|
+
in_stock: {
|
|
848
|
+
'yum product id 1': true
|
|
849
|
+
},
|
|
850
|
+
offer: {
|
|
851
|
+
config: {
|
|
852
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
853
|
+
frequenciesEveryPeriod: ['1_1', '1_2']
|
|
854
|
+
},
|
|
855
|
+
defaultFrequency: '1_2'
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
expect(actual).toEqual([
|
|
860
|
+
{
|
|
861
|
+
id: 'yum product id 1',
|
|
862
|
+
frequency: 'yum selling plan id 2'
|
|
863
|
+
}
|
|
864
|
+
]);
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
describe('given there is no matching selling plan for every_everyPeriod default frequency of offer element', () => {
|
|
868
|
+
it('should set frequency to offer element default frequency given offer element default frequency is a selling plan', () => {
|
|
869
|
+
const actual = optedin([], {
|
|
870
|
+
type: constants.RECEIVE_OFFER,
|
|
871
|
+
payload: {
|
|
872
|
+
autoship: {
|
|
873
|
+
'yum product id 1': true
|
|
874
|
+
},
|
|
875
|
+
autoship_by_default: {
|
|
876
|
+
'yum product id 1': true
|
|
877
|
+
},
|
|
878
|
+
in_stock: {
|
|
879
|
+
'yum product id 1': true
|
|
880
|
+
},
|
|
881
|
+
offer: {
|
|
882
|
+
config: {
|
|
883
|
+
frequencies: ['yum selling plan id 1'],
|
|
884
|
+
frequenciesEveryPeriod: ['1_1']
|
|
885
|
+
},
|
|
886
|
+
defaultFrequency: 'yum offer default selling plan'
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
expect(actual).toEqual([
|
|
891
|
+
{
|
|
892
|
+
id: 'yum product id 1',
|
|
893
|
+
frequency: 'yum offer default selling plan'
|
|
894
|
+
}
|
|
895
|
+
]);
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
it('should set frequency to the selling plan of the offer element default frequency given the offer element default frequency has a matching selling plan', () => {
|
|
899
|
+
const actual = optedin([], {
|
|
900
|
+
type: constants.RECEIVE_OFFER,
|
|
901
|
+
payload: {
|
|
902
|
+
autoship: {
|
|
903
|
+
'yum product id 1': true
|
|
904
|
+
},
|
|
905
|
+
autoship_by_default: {
|
|
906
|
+
'yum product id 1': true
|
|
907
|
+
},
|
|
908
|
+
in_stock: {
|
|
909
|
+
'yum product id 1': true
|
|
910
|
+
},
|
|
911
|
+
offer: {
|
|
912
|
+
config: {
|
|
913
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 3'],
|
|
914
|
+
frequenciesEveryPeriod: ['1_1', '1_3']
|
|
915
|
+
},
|
|
916
|
+
defaultFrequency: '1_3'
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
expect(actual).toEqual([
|
|
921
|
+
{
|
|
922
|
+
id: 'yum product id 1',
|
|
923
|
+
frequency: 'yum selling plan id 3'
|
|
924
|
+
}
|
|
925
|
+
]);
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
it('should set frequency to the first selling plan given the offer element default frequency is not a selling plan and does not have a matching selling plan', () => {
|
|
929
|
+
const actual = optedin([], {
|
|
930
|
+
type: constants.RECEIVE_OFFER,
|
|
931
|
+
payload: {
|
|
932
|
+
autoship: {
|
|
933
|
+
'yum product id 1': true
|
|
934
|
+
},
|
|
935
|
+
autoship_by_default: {
|
|
936
|
+
'yum product id 1': true
|
|
937
|
+
},
|
|
938
|
+
in_stock: {
|
|
939
|
+
'yum product id 1': true
|
|
940
|
+
},
|
|
941
|
+
offer: {
|
|
942
|
+
config: {
|
|
943
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 4'],
|
|
944
|
+
frequenciesEveryPeriod: ['1_1', '1_4']
|
|
945
|
+
},
|
|
946
|
+
defaultFrequency: '1_3'
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
expect(actual).toEqual([
|
|
951
|
+
{
|
|
952
|
+
id: 'yum product id 1',
|
|
953
|
+
frequency: 'yum selling plan id 1'
|
|
954
|
+
}
|
|
955
|
+
]);
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
it('should map frequency to selling plan given selling plan exists', () => {
|
|
962
|
+
const actual = optedin(
|
|
963
|
+
[
|
|
964
|
+
{
|
|
965
|
+
id: 'yum product id 1',
|
|
966
|
+
frequency: '1_2'
|
|
967
|
+
}
|
|
968
|
+
],
|
|
969
|
+
{
|
|
970
|
+
type: constants.RECEIVE_OFFER,
|
|
971
|
+
payload: {
|
|
972
|
+
offer: {
|
|
973
|
+
config: {
|
|
974
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
975
|
+
frequenciesEveryPeriod: ['1_1', '1_2']
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
);
|
|
981
|
+
expect(actual).toEqual([
|
|
982
|
+
{
|
|
983
|
+
id: 'yum product id 1',
|
|
984
|
+
frequency: 'yum selling plan id 2'
|
|
985
|
+
}
|
|
986
|
+
]);
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
it('should return unmodified state given state already contains optin with a selling plan', () => {
|
|
990
|
+
const actual = optedin(
|
|
991
|
+
[
|
|
992
|
+
{
|
|
993
|
+
id: 'yum product id 1',
|
|
994
|
+
frequency: 'yum existing frequency'
|
|
995
|
+
}
|
|
996
|
+
],
|
|
997
|
+
{
|
|
998
|
+
type: constants.RECEIVE_OFFER,
|
|
999
|
+
payload: {}
|
|
1000
|
+
}
|
|
1001
|
+
);
|
|
1002
|
+
expect(actual).toEqual([
|
|
1003
|
+
{
|
|
1004
|
+
id: 'yum product id 1',
|
|
1005
|
+
frequency: 'yum existing frequency'
|
|
1006
|
+
}
|
|
1007
|
+
]);
|
|
1008
|
+
});
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
describe('given action is SETUP_PRODUCT', () => {
|
|
1014
|
+
it('should return unmodified state given frequeny is already a selling plan', () => {
|
|
1015
|
+
const actual = optedin(
|
|
1016
|
+
[
|
|
1017
|
+
{
|
|
1018
|
+
id: 'yum product id 1',
|
|
1019
|
+
frequency: 'yum selling plan id 1'
|
|
1020
|
+
}
|
|
1021
|
+
],
|
|
1022
|
+
{
|
|
1023
|
+
type: constants.SETUP_PRODUCT,
|
|
1024
|
+
payload: {
|
|
1025
|
+
product: {
|
|
1026
|
+
selling_plan_groups: [
|
|
1027
|
+
{
|
|
1028
|
+
name: 'Subscribe and Save',
|
|
1029
|
+
selling_plans: [
|
|
1030
|
+
{
|
|
1031
|
+
id: 'yum selling plan id 1',
|
|
1032
|
+
options: [
|
|
1033
|
+
{
|
|
1034
|
+
value: '1 day'
|
|
1035
|
+
}
|
|
1036
|
+
]
|
|
1037
|
+
},
|
|
1038
|
+
{
|
|
1039
|
+
id: 'yum selling plan id 2',
|
|
1040
|
+
options: [
|
|
1041
|
+
{
|
|
1042
|
+
value: '1 week1'
|
|
1043
|
+
}
|
|
1044
|
+
]
|
|
1045
|
+
}
|
|
1046
|
+
]
|
|
1047
|
+
}
|
|
1048
|
+
]
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
);
|
|
1053
|
+
|
|
1054
|
+
expect(actual).toEqual([
|
|
1055
|
+
{
|
|
1056
|
+
id: 'yum product id 1',
|
|
1057
|
+
frequency: 'yum selling plan id 1'
|
|
1058
|
+
}
|
|
1059
|
+
]);
|
|
1060
|
+
});
|
|
1061
|
+
|
|
1062
|
+
it('should set frequency to selling plan given matching selling plan', () => {
|
|
1063
|
+
const actual = optedin(
|
|
1064
|
+
[
|
|
1065
|
+
{
|
|
1066
|
+
id: 'yum product id 1',
|
|
1067
|
+
frequency: '1_2'
|
|
1068
|
+
}
|
|
1069
|
+
],
|
|
1070
|
+
{
|
|
1071
|
+
type: constants.SETUP_PRODUCT,
|
|
1072
|
+
payload: {
|
|
1073
|
+
product: {
|
|
1074
|
+
selling_plan_groups: [
|
|
1075
|
+
{
|
|
1076
|
+
name: 'Subscribe and Save',
|
|
1077
|
+
selling_plans: [
|
|
1078
|
+
{
|
|
1079
|
+
id: 'yum selling plan id 1',
|
|
1080
|
+
options: [
|
|
1081
|
+
{
|
|
1082
|
+
value: '1 day'
|
|
1083
|
+
}
|
|
1084
|
+
]
|
|
1085
|
+
},
|
|
1086
|
+
{
|
|
1087
|
+
id: 'yum selling plan id 2',
|
|
1088
|
+
options: [
|
|
1089
|
+
{
|
|
1090
|
+
value: '1 week'
|
|
1091
|
+
}
|
|
1092
|
+
]
|
|
1093
|
+
}
|
|
1094
|
+
]
|
|
1095
|
+
}
|
|
1096
|
+
]
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
);
|
|
1101
|
+
|
|
1102
|
+
expect(actual).toEqual([
|
|
1103
|
+
{
|
|
1104
|
+
id: 'yum product id 1',
|
|
1105
|
+
frequency: 'yum selling plan id 2'
|
|
1106
|
+
}
|
|
1107
|
+
]);
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
it('should set frequency to first selling plan given no matching selling plan', () => {
|
|
1111
|
+
const actual = optedin(
|
|
1112
|
+
[
|
|
1113
|
+
{
|
|
1114
|
+
id: 'yum product id 1',
|
|
1115
|
+
frequency: '1_3'
|
|
1116
|
+
}
|
|
1117
|
+
],
|
|
1118
|
+
{
|
|
1119
|
+
type: constants.SETUP_PRODUCT,
|
|
1120
|
+
payload: {
|
|
1121
|
+
product: {
|
|
1122
|
+
selling_plan_groups: [
|
|
1123
|
+
{
|
|
1124
|
+
name: 'Subscribe and Save',
|
|
1125
|
+
selling_plans: [
|
|
1126
|
+
{
|
|
1127
|
+
id: 'yum selling plan id 1',
|
|
1128
|
+
options: [
|
|
1129
|
+
{
|
|
1130
|
+
value: '1 day'
|
|
1131
|
+
}
|
|
1132
|
+
]
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
id: 'yum selling plan id 2',
|
|
1136
|
+
options: [
|
|
1137
|
+
{
|
|
1138
|
+
value: '1 week'
|
|
1139
|
+
}
|
|
1140
|
+
]
|
|
1141
|
+
}
|
|
1142
|
+
]
|
|
1143
|
+
}
|
|
1144
|
+
]
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
);
|
|
1149
|
+
|
|
1150
|
+
expect(actual).toEqual([
|
|
1151
|
+
{
|
|
1152
|
+
id: 'yum product id 1',
|
|
1153
|
+
frequency: 'yum selling plan id 1'
|
|
1154
|
+
}
|
|
1155
|
+
]);
|
|
1156
|
+
});
|
|
1157
|
+
});
|
|
1158
|
+
|
|
368
1159
|
it('should return unmodified state given unsupported action', () => {
|
|
369
1160
|
const actual = optedin(
|
|
370
1161
|
{ 'yum existing key': 'yum existing value' },
|
|
@@ -393,48 +1184,50 @@ describe('productPlans', () => {
|
|
|
393
1184
|
{
|
|
394
1185
|
type: constants.SETUP_PRODUCT,
|
|
395
1186
|
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
|
-
|
|
1187
|
+
product: {
|
|
1188
|
+
id: 'yum product id',
|
|
1189
|
+
selling_plan_allocations: [
|
|
1190
|
+
{
|
|
1191
|
+
selling_plan_id: 'yum selling plan id 1',
|
|
1192
|
+
compare_at_price: 100,
|
|
1193
|
+
price: 50,
|
|
1194
|
+
price_adjustments: [
|
|
1195
|
+
{
|
|
1196
|
+
value: 50,
|
|
1197
|
+
value_type: 'percentage'
|
|
1198
|
+
}
|
|
1199
|
+
]
|
|
1200
|
+
}
|
|
1201
|
+
],
|
|
1202
|
+
variants: [
|
|
1203
|
+
{
|
|
1204
|
+
id: 'yum variant id 1',
|
|
1205
|
+
selling_plan_allocations: [
|
|
1206
|
+
{
|
|
1207
|
+
selling_plan_id: 'yum selling plan id 2',
|
|
1208
|
+
compare_at_price: 50,
|
|
1209
|
+
price: 25,
|
|
1210
|
+
price_adjustments: [
|
|
1211
|
+
{
|
|
1212
|
+
value: 25
|
|
1213
|
+
}
|
|
1214
|
+
]
|
|
1215
|
+
}
|
|
1216
|
+
]
|
|
1217
|
+
},
|
|
1218
|
+
{
|
|
1219
|
+
id: 'yum variant id 2',
|
|
1220
|
+
selling_plan_allocations: [
|
|
1221
|
+
{
|
|
1222
|
+
selling_plan_id: 'yum selling plan id 3',
|
|
1223
|
+
compare_at_price: 10,
|
|
1224
|
+
price: 8,
|
|
1225
|
+
price_adjustments: []
|
|
1226
|
+
}
|
|
1227
|
+
]
|
|
1228
|
+
}
|
|
1229
|
+
]
|
|
1230
|
+
}
|
|
438
1231
|
}
|
|
439
1232
|
}
|
|
440
1233
|
);
|