@ordergroove/offers 2.29.0 → 2.29.1-alpha-PR-707-2.113
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/README.md +22 -1
- package/dist/bundle-report.html +72 -59
- package/dist/examples.js +262 -105
- package/dist/examples.js.map +2 -2
- package/dist/offers.js +82 -32
- package/dist/offers.js.map +3 -3
- package/examples/index.js +230 -218
- package/package.json +2 -2
- package/src/components/PrepaidData.js +110 -0
- package/src/components/PrepaidToggle.js +108 -0
- package/src/components/Price.js +6 -6
- package/src/components/Select.js +6 -1
- package/src/components/__tests__/PrepaidData.spec.js +173 -0
- package/src/components/__tests__/PrepaidToggle.spec.js +115 -0
- package/src/components/__tests__/Price.spec.js +96 -0
- package/src/core/__tests__/adapters.spec.js +232 -1
- package/src/core/__tests__/descriptors.spec.js +56 -0
- package/src/core/__tests__/reducer.spec.js +153 -1
- package/src/core/__tests__/selectors.spec.js +34 -1
- package/src/core/actions.js +5 -0
- package/src/core/adapters.js +48 -2
- package/src/core/constants.js +1 -0
- package/src/core/descriptors.js +7 -1
- package/src/core/reducer.js +35 -14
- package/src/core/selectors.js +32 -0
- package/src/core/utils.ts +16 -0
- package/src/make-api.js +4 -0
- package/src/shopify/__tests__/productPlan.spec.js +513 -0
- package/src/shopify/__tests__/shopifyReducer.spec.js +630 -19
- package/src/shopify/__tests__/utils.spec.js +25 -0
- package/src/shopify/reducers/productPlans.ts +134 -0
- package/src/shopify/shopifyMiddleware.ts +3 -0
- package/src/shopify/shopifyReducer.js +96 -47
- package/src/shopify/shopifyTrackingMiddleware.ts +1 -1
- package/src/shopify/types/productPlan.ts +11 -0
- package/src/shopify/types/shopify.ts +98 -0
- package/src/shopify/utils.ts +3 -0
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
productPlans,
|
|
10
10
|
textToFreq
|
|
11
11
|
} from '../shopifyReducer';
|
|
12
|
+
import { getObjectStructuredProductPlans } from '../../core/adapters';
|
|
13
|
+
import { DEFAULT_PAY_AS_YOU_GO_GROUP_NAME } from '../reducers/productPlans';
|
|
12
14
|
|
|
13
15
|
describe('autoshipEligible', () => {
|
|
14
16
|
it('should return true for each id given action RECEIVE_PRODUCT_PLANS', () => {
|
|
@@ -140,7 +142,7 @@ describe('config', () => {
|
|
|
140
142
|
product: {
|
|
141
143
|
selling_plan_groups: [
|
|
142
144
|
{
|
|
143
|
-
name:
|
|
145
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
144
146
|
selling_plans: [
|
|
145
147
|
{
|
|
146
148
|
id: 'yum selling plan id 1',
|
|
@@ -190,7 +192,7 @@ describe('config', () => {
|
|
|
190
192
|
product: {
|
|
191
193
|
selling_plan_groups: [
|
|
192
194
|
{
|
|
193
|
-
name:
|
|
195
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
194
196
|
selling_plans: [
|
|
195
197
|
{
|
|
196
198
|
id: 'yum selling plan id 1',
|
|
@@ -240,7 +242,7 @@ describe('config', () => {
|
|
|
240
242
|
product: {
|
|
241
243
|
selling_plan_groups: [
|
|
242
244
|
{
|
|
243
|
-
name:
|
|
245
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
244
246
|
selling_plans: [
|
|
245
247
|
{
|
|
246
248
|
id: 'yum selling plan id 1',
|
|
@@ -282,7 +284,7 @@ describe('config', () => {
|
|
|
282
284
|
product: {
|
|
283
285
|
selling_plan_groups: [
|
|
284
286
|
{
|
|
285
|
-
name:
|
|
287
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
286
288
|
selling_plans: [
|
|
287
289
|
{
|
|
288
290
|
id: 'yum selling plan id 1'
|
|
@@ -323,7 +325,7 @@ describe('config', () => {
|
|
|
323
325
|
]
|
|
324
326
|
},
|
|
325
327
|
{
|
|
326
|
-
name:
|
|
328
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
327
329
|
options: [{ values: 'yum values' }],
|
|
328
330
|
selling_plans: [
|
|
329
331
|
{
|
|
@@ -344,6 +346,45 @@ describe('config', () => {
|
|
|
344
346
|
);
|
|
345
347
|
});
|
|
346
348
|
|
|
349
|
+
it('should set prepaidSellingPlans', () => {
|
|
350
|
+
const sellingPlanGroups = [
|
|
351
|
+
{
|
|
352
|
+
name: 'Prepaid-43017264201944',
|
|
353
|
+
selling_plans: [
|
|
354
|
+
{
|
|
355
|
+
id: 2146042072,
|
|
356
|
+
name: 'Delivered every 2 months, prepaid for 4 shipments',
|
|
357
|
+
options: [
|
|
358
|
+
{ name: 'Delivery every', position: 1, value: 'PREPAID-2 months' },
|
|
359
|
+
{ name: 'Shipment amount', position: 2, value: '4 shipments' }
|
|
360
|
+
]
|
|
361
|
+
}
|
|
362
|
+
]
|
|
363
|
+
}
|
|
364
|
+
];
|
|
365
|
+
const actual = config(
|
|
366
|
+
{},
|
|
367
|
+
{
|
|
368
|
+
type: constants.SETUP_PRODUCT,
|
|
369
|
+
payload: {
|
|
370
|
+
product: {
|
|
371
|
+
selling_plan_groups: sellingPlanGroups
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
expect(actual).toEqual({
|
|
377
|
+
prepaidSellingPlans: {
|
|
378
|
+
'43017264201944': [
|
|
379
|
+
{
|
|
380
|
+
numberShipments: 4,
|
|
381
|
+
sellingPlan: '2146042072'
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
347
388
|
it('should return unmodified state given unsupported action', () => {
|
|
348
389
|
const actual = config(
|
|
349
390
|
{ 'yum existing key': 'yum existing value' },
|
|
@@ -468,7 +509,13 @@ describe('optedin', () => {
|
|
|
468
509
|
key: 'yum item key 1',
|
|
469
510
|
selling_plan_allocation: {
|
|
470
511
|
selling_plan: {
|
|
471
|
-
id: 'yum selling plan id 1'
|
|
512
|
+
id: 'yum selling plan id 1',
|
|
513
|
+
options: [
|
|
514
|
+
{
|
|
515
|
+
name: 'Deliver every',
|
|
516
|
+
value: '2 months'
|
|
517
|
+
}
|
|
518
|
+
]
|
|
472
519
|
}
|
|
473
520
|
}
|
|
474
521
|
},
|
|
@@ -476,7 +523,31 @@ describe('optedin', () => {
|
|
|
476
523
|
key: 'yum item key 2',
|
|
477
524
|
selling_plan_allocation: {
|
|
478
525
|
selling_plan: {
|
|
479
|
-
id: 'yum selling plan id 2'
|
|
526
|
+
id: 'yum selling plan id 2',
|
|
527
|
+
options: [
|
|
528
|
+
{
|
|
529
|
+
name: 'Deliver every',
|
|
530
|
+
value: '2 months'
|
|
531
|
+
}
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
key: 'prepaid yum item',
|
|
538
|
+
selling_plan_allocation: {
|
|
539
|
+
selling_plan: {
|
|
540
|
+
id: 'prepaid yum selling plan id',
|
|
541
|
+
options: [
|
|
542
|
+
{
|
|
543
|
+
name: 'Deliver every',
|
|
544
|
+
value: '1 month'
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
name: 'Shipment amount',
|
|
548
|
+
value: '3 shipments'
|
|
549
|
+
}
|
|
550
|
+
]
|
|
480
551
|
}
|
|
481
552
|
}
|
|
482
553
|
}
|
|
@@ -492,6 +563,11 @@ describe('optedin', () => {
|
|
|
492
563
|
{
|
|
493
564
|
id: 'yum item key 2',
|
|
494
565
|
frequency: 'yum selling plan id 2'
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
id: 'prepaid yum item',
|
|
569
|
+
frequency: 'prepaid yum selling plan id',
|
|
570
|
+
prepaidShipments: 3
|
|
495
571
|
}
|
|
496
572
|
]);
|
|
497
573
|
});
|
|
@@ -1025,7 +1101,7 @@ describe('optedin', () => {
|
|
|
1025
1101
|
product: {
|
|
1026
1102
|
selling_plan_groups: [
|
|
1027
1103
|
{
|
|
1028
|
-
name:
|
|
1104
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
1029
1105
|
selling_plans: [
|
|
1030
1106
|
{
|
|
1031
1107
|
id: 'yum selling plan id 1',
|
|
@@ -1073,7 +1149,7 @@ describe('optedin', () => {
|
|
|
1073
1149
|
product: {
|
|
1074
1150
|
selling_plan_groups: [
|
|
1075
1151
|
{
|
|
1076
|
-
name:
|
|
1152
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
1077
1153
|
selling_plans: [
|
|
1078
1154
|
{
|
|
1079
1155
|
id: 'yum selling plan id 1',
|
|
@@ -1121,7 +1197,7 @@ describe('optedin', () => {
|
|
|
1121
1197
|
product: {
|
|
1122
1198
|
selling_plan_groups: [
|
|
1123
1199
|
{
|
|
1124
|
-
name:
|
|
1200
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
1125
1201
|
selling_plans: [
|
|
1126
1202
|
{
|
|
1127
1203
|
id: 'yum selling plan id 1',
|
|
@@ -1156,6 +1232,80 @@ describe('optedin', () => {
|
|
|
1156
1232
|
});
|
|
1157
1233
|
});
|
|
1158
1234
|
|
|
1235
|
+
describe('given action is PRODUCT_CHANGE_PREPAID_SHIPMENTS', () => {
|
|
1236
|
+
function getPayload(prepaidShipments) {
|
|
1237
|
+
return {
|
|
1238
|
+
product: {
|
|
1239
|
+
id: 'yum prepaid id'
|
|
1240
|
+
},
|
|
1241
|
+
prepaidShipments: prepaidShipments,
|
|
1242
|
+
offer: {
|
|
1243
|
+
config: {
|
|
1244
|
+
prepaidSellingPlans: {
|
|
1245
|
+
'yum prepaid id': [
|
|
1246
|
+
{ numberShipments: 3, sellingPlan: 'yum prepaid selling plan id 1' },
|
|
1247
|
+
{
|
|
1248
|
+
numberShipments: 4,
|
|
1249
|
+
sellingPlan: 'yum prepaid selling plan id 2'
|
|
1250
|
+
}
|
|
1251
|
+
]
|
|
1252
|
+
},
|
|
1253
|
+
frequencies: ['yum selling plan id 1']
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
it('sets frequency to the corresponding selling plan', () => {
|
|
1260
|
+
const actual = optedin([], {
|
|
1261
|
+
type: constants.PRODUCT_CHANGE_PREPAID_SHIPMENTS,
|
|
1262
|
+
payload: getPayload(4)
|
|
1263
|
+
});
|
|
1264
|
+
expect(actual).toEqual([
|
|
1265
|
+
{
|
|
1266
|
+
id: 'yum prepaid id',
|
|
1267
|
+
frequency: 'yum prepaid selling plan id 2',
|
|
1268
|
+
prepaidShipments: 4
|
|
1269
|
+
}
|
|
1270
|
+
]);
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
it('sets frequency to the first frequency when prepaidShipments is null', () => {
|
|
1274
|
+
const actual = optedin([], {
|
|
1275
|
+
type: constants.PRODUCT_CHANGE_PREPAID_SHIPMENTS,
|
|
1276
|
+
payload: getPayload(null)
|
|
1277
|
+
});
|
|
1278
|
+
expect(actual).toEqual([
|
|
1279
|
+
{
|
|
1280
|
+
id: 'yum prepaid id',
|
|
1281
|
+
frequency: 'yum selling plan id 1'
|
|
1282
|
+
}
|
|
1283
|
+
]);
|
|
1284
|
+
});
|
|
1285
|
+
|
|
1286
|
+
it('updates existing opted in state', () => {
|
|
1287
|
+
const actual = optedin(
|
|
1288
|
+
[
|
|
1289
|
+
{
|
|
1290
|
+
id: 'yum prepaid id',
|
|
1291
|
+
frequency: 'yum selling plan id 1'
|
|
1292
|
+
}
|
|
1293
|
+
],
|
|
1294
|
+
{
|
|
1295
|
+
type: constants.PRODUCT_CHANGE_PREPAID_SHIPMENTS,
|
|
1296
|
+
payload: getPayload(4)
|
|
1297
|
+
}
|
|
1298
|
+
);
|
|
1299
|
+
expect(actual).toEqual([
|
|
1300
|
+
{
|
|
1301
|
+
id: 'yum prepaid id',
|
|
1302
|
+
frequency: 'yum prepaid selling plan id 2',
|
|
1303
|
+
prepaidShipments: 4
|
|
1304
|
+
}
|
|
1305
|
+
]);
|
|
1306
|
+
});
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1159
1309
|
it('should return unmodified state given unsupported action', () => {
|
|
1160
1310
|
const actual = optedin(
|
|
1161
1311
|
{ 'yum existing key': 'yum existing value' },
|
|
@@ -1226,6 +1376,36 @@ describe('productPlans', () => {
|
|
|
1226
1376
|
}
|
|
1227
1377
|
]
|
|
1228
1378
|
}
|
|
1379
|
+
],
|
|
1380
|
+
selling_plan_groups: [
|
|
1381
|
+
{
|
|
1382
|
+
selling_plans: [
|
|
1383
|
+
{
|
|
1384
|
+
id: 'yum selling plan id 1',
|
|
1385
|
+
options: [
|
|
1386
|
+
{
|
|
1387
|
+
value: '1 day'
|
|
1388
|
+
}
|
|
1389
|
+
]
|
|
1390
|
+
},
|
|
1391
|
+
{
|
|
1392
|
+
id: 'yum selling plan id 2',
|
|
1393
|
+
options: [
|
|
1394
|
+
{
|
|
1395
|
+
value: '1 week'
|
|
1396
|
+
}
|
|
1397
|
+
]
|
|
1398
|
+
},
|
|
1399
|
+
{
|
|
1400
|
+
id: 'yum selling plan id 3',
|
|
1401
|
+
options: [
|
|
1402
|
+
{
|
|
1403
|
+
value: '1 month'
|
|
1404
|
+
}
|
|
1405
|
+
]
|
|
1406
|
+
}
|
|
1407
|
+
]
|
|
1408
|
+
}
|
|
1229
1409
|
]
|
|
1230
1410
|
}
|
|
1231
1411
|
}
|
|
@@ -1233,30 +1413,461 @@ describe('productPlans', () => {
|
|
|
1233
1413
|
);
|
|
1234
1414
|
|
|
1235
1415
|
expect(actual).toEqual({
|
|
1236
|
-
'yum product id':
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1416
|
+
'yum product id': [
|
|
1417
|
+
{
|
|
1418
|
+
frequency: 'yum selling plan id 1',
|
|
1419
|
+
prepaidShipments: null,
|
|
1420
|
+
regularPrice: '$1.00',
|
|
1421
|
+
subscriptionPrice: '$.50',
|
|
1422
|
+
discountRate: '50%'
|
|
1423
|
+
}
|
|
1424
|
+
],
|
|
1425
|
+
'yum variant id 1': [
|
|
1426
|
+
{
|
|
1427
|
+
frequency: 'yum selling plan id 2',
|
|
1428
|
+
prepaidShipments: null,
|
|
1429
|
+
regularPrice: '$.50',
|
|
1430
|
+
subscriptionPrice: '$.25',
|
|
1431
|
+
discountRate: '$.25'
|
|
1432
|
+
}
|
|
1433
|
+
],
|
|
1434
|
+
'yum variant id 2': [
|
|
1435
|
+
{
|
|
1436
|
+
frequency: 'yum selling plan id 3',
|
|
1437
|
+
prepaidShipments: null,
|
|
1438
|
+
regularPrice: '$.10',
|
|
1439
|
+
subscriptionPrice: '$8',
|
|
1440
|
+
discountRate: '$2'
|
|
1441
|
+
}
|
|
1442
|
+
]
|
|
1241
1443
|
});
|
|
1242
1444
|
});
|
|
1243
1445
|
|
|
1244
|
-
it('should return
|
|
1446
|
+
it('should return product plans with formatted discounts and prepaid info given action SETUP_PRODUCT with prepaid selling plans', () => {
|
|
1245
1447
|
const actual = productPlans(
|
|
1246
1448
|
{},
|
|
1247
1449
|
{
|
|
1248
|
-
type: constants.
|
|
1450
|
+
type: constants.SETUP_PRODUCT,
|
|
1451
|
+
payload: {
|
|
1452
|
+
product: {
|
|
1453
|
+
id: 'yum product id',
|
|
1454
|
+
selling_plan_allocations: [
|
|
1455
|
+
{
|
|
1456
|
+
selling_plan_id: 'yum selling plan id 1',
|
|
1457
|
+
compare_at_price: 2000,
|
|
1458
|
+
price: 4800,
|
|
1459
|
+
price_adjustments: [
|
|
1460
|
+
{
|
|
1461
|
+
value: 4800
|
|
1462
|
+
}
|
|
1463
|
+
]
|
|
1464
|
+
}
|
|
1465
|
+
],
|
|
1466
|
+
variants: [
|
|
1467
|
+
{
|
|
1468
|
+
id: 'yum variant id 1',
|
|
1469
|
+
selling_plan_allocations: [
|
|
1470
|
+
{
|
|
1471
|
+
selling_plan_id: 'yum selling plan id 2',
|
|
1472
|
+
compare_at_price: 50,
|
|
1473
|
+
price: 25,
|
|
1474
|
+
price_adjustments: [
|
|
1475
|
+
{
|
|
1476
|
+
value: 25
|
|
1477
|
+
}
|
|
1478
|
+
]
|
|
1479
|
+
},
|
|
1480
|
+
{
|
|
1481
|
+
selling_plan_id: 'yum selling plan id prepaid 3 shipments',
|
|
1482
|
+
compare_at_price: 50,
|
|
1483
|
+
price: 120
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
selling_plan_id: 'yum selling plan id prepaid 6 shipments',
|
|
1487
|
+
compare_at_price: 50,
|
|
1488
|
+
price: 240
|
|
1489
|
+
},
|
|
1490
|
+
{
|
|
1491
|
+
selling_plan_id: 'yum selling plan id prepaid 12 shipments',
|
|
1492
|
+
compare_at_price: 50,
|
|
1493
|
+
price: 480
|
|
1494
|
+
}
|
|
1495
|
+
]
|
|
1496
|
+
},
|
|
1497
|
+
{
|
|
1498
|
+
id: 'yum variant id 2',
|
|
1499
|
+
selling_plan_allocations: [
|
|
1500
|
+
{
|
|
1501
|
+
selling_plan_id: 'yum selling plan id 3',
|
|
1502
|
+
compare_at_price: 10,
|
|
1503
|
+
price: 8,
|
|
1504
|
+
price_adjustments: []
|
|
1505
|
+
}
|
|
1506
|
+
]
|
|
1507
|
+
}
|
|
1508
|
+
],
|
|
1509
|
+
selling_plan_groups: [
|
|
1510
|
+
{
|
|
1511
|
+
selling_plans: [
|
|
1512
|
+
{
|
|
1513
|
+
id: 'yum selling plan id 1',
|
|
1514
|
+
options: [
|
|
1515
|
+
{
|
|
1516
|
+
name: 'Delivery every',
|
|
1517
|
+
position: 1,
|
|
1518
|
+
value: 'PREPAID-1 month'
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
name: 'Shipment amount',
|
|
1522
|
+
position: 2,
|
|
1523
|
+
value: '3 shipments'
|
|
1524
|
+
}
|
|
1525
|
+
]
|
|
1526
|
+
},
|
|
1527
|
+
{
|
|
1528
|
+
id: 'yum selling plan id 2',
|
|
1529
|
+
options: [
|
|
1530
|
+
{
|
|
1531
|
+
value: '1 week'
|
|
1532
|
+
}
|
|
1533
|
+
]
|
|
1534
|
+
},
|
|
1535
|
+
{
|
|
1536
|
+
id: 'yum selling plan id 3',
|
|
1537
|
+
options: [
|
|
1538
|
+
{
|
|
1539
|
+
value: '1 month'
|
|
1540
|
+
}
|
|
1541
|
+
]
|
|
1542
|
+
}
|
|
1543
|
+
]
|
|
1544
|
+
},
|
|
1545
|
+
{
|
|
1546
|
+
selling_plans: [
|
|
1547
|
+
{
|
|
1548
|
+
id: 'yum selling plan id prepaid 3 shipments',
|
|
1549
|
+
options: [
|
|
1550
|
+
{
|
|
1551
|
+
name: 'Delivery every',
|
|
1552
|
+
position: 1,
|
|
1553
|
+
value: 'PREPAID-1 month'
|
|
1554
|
+
},
|
|
1555
|
+
{
|
|
1556
|
+
name: 'Shipment amount',
|
|
1557
|
+
position: 2,
|
|
1558
|
+
value: '3 shipments'
|
|
1559
|
+
}
|
|
1560
|
+
]
|
|
1561
|
+
},
|
|
1562
|
+
{
|
|
1563
|
+
id: 'yum selling plan id prepaid 6 shipments',
|
|
1564
|
+
options: [
|
|
1565
|
+
{
|
|
1566
|
+
name: 'Delivery every',
|
|
1567
|
+
position: 1,
|
|
1568
|
+
value: 'PREPAID-1 month'
|
|
1569
|
+
},
|
|
1570
|
+
{
|
|
1571
|
+
name: 'Shipment amount',
|
|
1572
|
+
position: 2,
|
|
1573
|
+
value: '6 shipments'
|
|
1574
|
+
}
|
|
1575
|
+
]
|
|
1576
|
+
},
|
|
1577
|
+
{
|
|
1578
|
+
id: 'yum selling plan id prepaid 12 shipments',
|
|
1579
|
+
options: [
|
|
1580
|
+
{
|
|
1581
|
+
name: 'Delivery every',
|
|
1582
|
+
position: 1,
|
|
1583
|
+
value: 'PREPAID-1 month'
|
|
1584
|
+
},
|
|
1585
|
+
{
|
|
1586
|
+
name: 'Shipment amount',
|
|
1587
|
+
position: 2,
|
|
1588
|
+
value: '12 shipments'
|
|
1589
|
+
}
|
|
1590
|
+
]
|
|
1591
|
+
}
|
|
1592
|
+
]
|
|
1593
|
+
}
|
|
1594
|
+
]
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
);
|
|
1599
|
+
|
|
1600
|
+
expect(actual).toEqual({
|
|
1601
|
+
'yum product id': [
|
|
1602
|
+
{
|
|
1603
|
+
frequency: 'yum selling plan id 1',
|
|
1604
|
+
regularPrice: '$20.00',
|
|
1605
|
+
subscriptionPrice: '$16.00',
|
|
1606
|
+
discountRate: '20%',
|
|
1607
|
+
prepaidShipments: 3,
|
|
1608
|
+
regularPrepaidPrice: '$48.00',
|
|
1609
|
+
prepaidSavingsPerShipment: '$4.00',
|
|
1610
|
+
prepaidSavingsTotal: '$12.00'
|
|
1611
|
+
}
|
|
1612
|
+
],
|
|
1613
|
+
'yum variant id 1': [
|
|
1614
|
+
{
|
|
1615
|
+
frequency: 'yum selling plan id 2',
|
|
1616
|
+
regularPrice: '$.50',
|
|
1617
|
+
subscriptionPrice: '$.25',
|
|
1618
|
+
discountRate: '$.25',
|
|
1619
|
+
prepaidShipments: null
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
frequency: 'yum selling plan id prepaid 3 shipments',
|
|
1623
|
+
regularPrice: '$.50',
|
|
1624
|
+
subscriptionPrice: '$.40',
|
|
1625
|
+
discountRate: '20%',
|
|
1626
|
+
prepaidShipments: 3,
|
|
1627
|
+
regularPrepaidPrice: '$1.20',
|
|
1628
|
+
prepaidSavingsPerShipment: '$.10',
|
|
1629
|
+
prepaidSavingsTotal: '$.30'
|
|
1630
|
+
},
|
|
1631
|
+
{
|
|
1632
|
+
frequency: 'yum selling plan id prepaid 6 shipments',
|
|
1633
|
+
regularPrice: '$.50',
|
|
1634
|
+
subscriptionPrice: '$.40',
|
|
1635
|
+
discountRate: '20%',
|
|
1636
|
+
prepaidShipments: 6,
|
|
1637
|
+
regularPrepaidPrice: '$2.40',
|
|
1638
|
+
prepaidSavingsPerShipment: '$.10',
|
|
1639
|
+
prepaidSavingsTotal: '$.60'
|
|
1640
|
+
},
|
|
1641
|
+
{
|
|
1642
|
+
frequency: 'yum selling plan id prepaid 12 shipments',
|
|
1643
|
+
regularPrice: '$.50',
|
|
1644
|
+
subscriptionPrice: '$.40',
|
|
1645
|
+
discountRate: '20%',
|
|
1646
|
+
prepaidShipments: 12,
|
|
1647
|
+
regularPrepaidPrice: '$4.80',
|
|
1648
|
+
prepaidSavingsPerShipment: '$.10',
|
|
1649
|
+
prepaidSavingsTotal: '$1.20'
|
|
1650
|
+
}
|
|
1651
|
+
],
|
|
1652
|
+
'yum variant id 2': [
|
|
1653
|
+
{
|
|
1654
|
+
frequency: 'yum selling plan id 3',
|
|
1655
|
+
regularPrice: '$.10',
|
|
1656
|
+
subscriptionPrice: '$8',
|
|
1657
|
+
discountRate: '$2',
|
|
1658
|
+
prepaidShipments: null
|
|
1659
|
+
}
|
|
1660
|
+
]
|
|
1661
|
+
});
|
|
1662
|
+
});
|
|
1663
|
+
|
|
1664
|
+
it('should product plans with formatted discounts given action SETUP_CART', () => {
|
|
1665
|
+
const actual = productPlans(
|
|
1666
|
+
{},
|
|
1667
|
+
{
|
|
1668
|
+
type: constants.SETUP_CART,
|
|
1669
|
+
payload: {
|
|
1670
|
+
items: [
|
|
1671
|
+
{
|
|
1672
|
+
id: 'yum variant id 1',
|
|
1673
|
+
key: 'yum variant key 1',
|
|
1674
|
+
selling_plan_allocation: {
|
|
1675
|
+
selling_plan_id: 'yum selling plan id 2',
|
|
1676
|
+
compare_at_price: 50,
|
|
1677
|
+
price: 25,
|
|
1678
|
+
price_adjustments: [
|
|
1679
|
+
{
|
|
1680
|
+
value: 25
|
|
1681
|
+
}
|
|
1682
|
+
],
|
|
1683
|
+
selling_plan: {
|
|
1684
|
+
id: 'yum selling plan id 2',
|
|
1685
|
+
options: [
|
|
1686
|
+
{
|
|
1687
|
+
name: 'Delivery every',
|
|
1688
|
+
position: 1,
|
|
1689
|
+
value: '1 day'
|
|
1690
|
+
}
|
|
1691
|
+
]
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
},
|
|
1695
|
+
{
|
|
1696
|
+
id: 'yum variant id 2',
|
|
1697
|
+
key: 'yum variant key 2',
|
|
1698
|
+
selling_plan_allocation: {
|
|
1699
|
+
selling_plan_id: 'yum selling plan id 3',
|
|
1700
|
+
compare_at_price: 10,
|
|
1701
|
+
price: 8,
|
|
1702
|
+
price_adjustments: [],
|
|
1703
|
+
selling_plan: {
|
|
1704
|
+
id: 'yum selling plan id 3',
|
|
1705
|
+
options: [
|
|
1706
|
+
{
|
|
1707
|
+
name: 'Delivery every',
|
|
1708
|
+
position: 1,
|
|
1709
|
+
value: '1 month'
|
|
1710
|
+
}
|
|
1711
|
+
]
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
]
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
);
|
|
1719
|
+
|
|
1720
|
+
expect(actual).toEqual({
|
|
1721
|
+
'yum variant key 1': [
|
|
1722
|
+
{
|
|
1723
|
+
frequency: 'yum selling plan id 2',
|
|
1724
|
+
prepaidShipments: null,
|
|
1725
|
+
regularPrice: '$.50',
|
|
1726
|
+
subscriptionPrice: '$.25',
|
|
1727
|
+
discountRate: '$.25'
|
|
1728
|
+
}
|
|
1729
|
+
],
|
|
1730
|
+
'yum variant key 2': [
|
|
1731
|
+
{
|
|
1732
|
+
frequency: 'yum selling plan id 3',
|
|
1733
|
+
prepaidShipments: null,
|
|
1734
|
+
regularPrice: '$.10',
|
|
1735
|
+
subscriptionPrice: '$8',
|
|
1736
|
+
discountRate: '$2'
|
|
1737
|
+
}
|
|
1738
|
+
]
|
|
1739
|
+
});
|
|
1740
|
+
});
|
|
1741
|
+
|
|
1742
|
+
it('should product plans with formatted discounts and prepaid info given action SETUP_CART with prepaid selling plans', () => {
|
|
1743
|
+
const actual = productPlans(
|
|
1744
|
+
{},
|
|
1745
|
+
{
|
|
1746
|
+
type: constants.SETUP_CART,
|
|
1249
1747
|
payload: {
|
|
1250
|
-
|
|
1748
|
+
items: [
|
|
1749
|
+
{
|
|
1750
|
+
id: 'yum variant id 1',
|
|
1751
|
+
key: 'yum variant key 1',
|
|
1752
|
+
selling_plan_allocation: {
|
|
1753
|
+
selling_plan_id: 'yum prepaid selling plan id',
|
|
1754
|
+
compare_at_price: 50,
|
|
1755
|
+
price: 480,
|
|
1756
|
+
price_adjustments: [
|
|
1757
|
+
{
|
|
1758
|
+
value: 480
|
|
1759
|
+
}
|
|
1760
|
+
],
|
|
1761
|
+
selling_plan: {
|
|
1762
|
+
id: 'yum prepaid selling plan id',
|
|
1763
|
+
options: [
|
|
1764
|
+
{
|
|
1765
|
+
name: 'Delivery every',
|
|
1766
|
+
position: 1,
|
|
1767
|
+
value: '1 day'
|
|
1768
|
+
},
|
|
1769
|
+
{
|
|
1770
|
+
name: 'Shipment amount',
|
|
1771
|
+
position: 2,
|
|
1772
|
+
value: '12 shipments'
|
|
1773
|
+
}
|
|
1774
|
+
]
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
},
|
|
1778
|
+
{
|
|
1779
|
+
id: 'yum variant id 2',
|
|
1780
|
+
key: 'yum variant key 2',
|
|
1781
|
+
selling_plan_allocation: {
|
|
1782
|
+
selling_plan_id: 'yum selling plan id 3',
|
|
1783
|
+
compare_at_price: 10,
|
|
1784
|
+
price: 8,
|
|
1785
|
+
price_adjustments: [],
|
|
1786
|
+
selling_plan: {
|
|
1787
|
+
id: 'yum selling plan id 3',
|
|
1788
|
+
options: [
|
|
1789
|
+
{
|
|
1790
|
+
name: 'Delivery every',
|
|
1791
|
+
position: 1,
|
|
1792
|
+
value: '1 month'
|
|
1793
|
+
}
|
|
1794
|
+
]
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
]
|
|
1251
1799
|
}
|
|
1252
1800
|
}
|
|
1253
1801
|
);
|
|
1254
1802
|
|
|
1255
1803
|
expect(actual).toEqual({
|
|
1256
|
-
'yum key':
|
|
1804
|
+
'yum variant key 1': [
|
|
1805
|
+
{
|
|
1806
|
+
frequency: 'yum prepaid selling plan id',
|
|
1807
|
+
regularPrice: '$.50',
|
|
1808
|
+
subscriptionPrice: '$.40',
|
|
1809
|
+
discountRate: '20%',
|
|
1810
|
+
prepaidShipments: 12,
|
|
1811
|
+
regularPrepaidPrice: '$4.80',
|
|
1812
|
+
prepaidSavingsPerShipment: '$.10',
|
|
1813
|
+
prepaidSavingsTotal: '$1.20'
|
|
1814
|
+
}
|
|
1815
|
+
],
|
|
1816
|
+
'yum variant key 2': [
|
|
1817
|
+
{
|
|
1818
|
+
frequency: 'yum selling plan id 3',
|
|
1819
|
+
prepaidShipments: null,
|
|
1820
|
+
regularPrice: '$.10',
|
|
1821
|
+
subscriptionPrice: '$8',
|
|
1822
|
+
discountRate: '$2'
|
|
1823
|
+
}
|
|
1824
|
+
]
|
|
1257
1825
|
});
|
|
1258
1826
|
});
|
|
1259
1827
|
|
|
1828
|
+
it('should return object structure payload given action RECEIVE_PRODUCT_PLANS', () => {
|
|
1829
|
+
const payload = {
|
|
1830
|
+
'variant-1': {
|
|
1831
|
+
'1_3': ['$15.00', '10%', '$13.50'],
|
|
1832
|
+
'2_3': ['$15.00', '10%', '$13.50'],
|
|
1833
|
+
'3_3': ['$15.00', '20%', '$12.00']
|
|
1834
|
+
},
|
|
1835
|
+
'variant-2': [
|
|
1836
|
+
{
|
|
1837
|
+
frequency: '1_3',
|
|
1838
|
+
prepaidShipments: null,
|
|
1839
|
+
regularPrice: '$30.00',
|
|
1840
|
+
subscriptionPrice: '$27.00',
|
|
1841
|
+
discountRate: '10%'
|
|
1842
|
+
},
|
|
1843
|
+
{
|
|
1844
|
+
frequency: '2_3',
|
|
1845
|
+
prepaidShipments: null,
|
|
1846
|
+
regularPrice: '$30.00',
|
|
1847
|
+
subscriptionPrice: '$27.00',
|
|
1848
|
+
discountRate: '10%'
|
|
1849
|
+
},
|
|
1850
|
+
{
|
|
1851
|
+
frequency: '3_3',
|
|
1852
|
+
prepaidShipments: 3,
|
|
1853
|
+
regularPrice: '$30.00',
|
|
1854
|
+
subscriptionPrice: '$24.00',
|
|
1855
|
+
discountRate: '20%'
|
|
1856
|
+
}
|
|
1857
|
+
]
|
|
1858
|
+
};
|
|
1859
|
+
|
|
1860
|
+
const actual = productPlans(
|
|
1861
|
+
{},
|
|
1862
|
+
{
|
|
1863
|
+
type: constants.RECEIVE_PRODUCT_PLANS,
|
|
1864
|
+
payload: payload
|
|
1865
|
+
}
|
|
1866
|
+
);
|
|
1867
|
+
|
|
1868
|
+
expect(actual).toEqual(getObjectStructuredProductPlans(payload));
|
|
1869
|
+
});
|
|
1870
|
+
|
|
1260
1871
|
it('should return unmodified state given unsupported action', () => {
|
|
1261
1872
|
const actual = productPlans(
|
|
1262
1873
|
{ 'yum existing key': 'yum existing value' },
|