@ordergroove/offers 2.30.4 → 2.30.6-alpha-PR-719-2.5

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": "@ordergroove/offers",
3
- "version": "2.30.4",
3
+ "version": "2.30.6-alpha-PR-719-2.5+da65ad5e",
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,7 +45,7 @@
45
45
  "throttle-debounce": "^2.1.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@ordergroove/offers-templates": "^0.5.2"
48
+ "@ordergroove/offers-templates": "^0.5.3"
49
49
  },
50
- "gitHead": "8f41940bb20d4eb376250add3aaa154e773a481b"
50
+ "gitHead": "da65ad5e152472bd2f558b35c68725272d08959a"
51
51
  }
@@ -371,6 +371,66 @@ describe('Shopify productPlan Reducer', () => {
371
371
  expect(productPlanCreated).toEqual(expectedProductPlan);
372
372
  });
373
373
 
374
+ it('should create prepaid product plan solving rounding issue', () => {
375
+ const allocation = {
376
+ price_adjustments: [
377
+ {
378
+ position: 1,
379
+ price: 4798
380
+ }
381
+ ],
382
+ price: 4798,
383
+ compare_at_price: 1999,
384
+ per_delivery_price: 4798,
385
+ selling_plan_id: 688412983572
386
+ };
387
+
388
+ const sellingPlans = [
389
+ {
390
+ id: 688412983572,
391
+ name: 'Delivered every 1 month, prepaid for 3 shipments',
392
+ description: null,
393
+ options: [
394
+ {
395
+ name: 'Delivery every',
396
+ position: 1,
397
+ value: 'PREPAID-1 month'
398
+ },
399
+ {
400
+ name: 'Shipment amount',
401
+ position: 2,
402
+ value: '3 shipments'
403
+ }
404
+ ],
405
+ recurring_deliveries: true,
406
+ price_adjustments: [
407
+ {
408
+ order_count: null,
409
+ position: 1,
410
+ value_type: 'price',
411
+ value: 4798
412
+ }
413
+ ]
414
+ }
415
+ ];
416
+
417
+ const expectedProductPlan = {
418
+ frequency: '688412983572',
419
+ regularPrice: '$19.99',
420
+ // There is to be an issue when not rounding where subscriptionPrice was calculated as $1599.3333333333333.35
421
+ subscriptionPrice: '$15.99',
422
+ discountRate: '20%',
423
+ prepaidShipments: 3,
424
+ regularPrepaidPrice: '$47.98',
425
+ prepaidSavingsPerShipment: '$4.00',
426
+ prepaidSavingsTotal: '$11.99'
427
+ };
428
+
429
+ const productPlanCreated = mapSellingPlanToDiscount(allocation, sellingPlans);
430
+
431
+ expect(productPlanCreated).toEqual(expectedProductPlan);
432
+ });
433
+
374
434
  it('should create prepaid product plan with extra discount percentage', () => {
375
435
  const allocation = {
376
436
  price_adjustments: [
@@ -27,7 +27,7 @@ export const getAllocationRegularPrice = (allocation: ShopifySellingPlanAllocati
27
27
  export const getAllocationSubscriptionPrice = (allocation: ShopifySellingPlanAllocationsEntity) => {
28
28
  if (isPrepaidAllocation(allocation)) {
29
29
  const prepaidShipmentsPerBilling = getPrepaidShipmentsNumberFromOptions(allocation.selling_plan?.options);
30
- const pricePerShipment = allocation.price / prepaidShipmentsPerBilling;
30
+ const pricePerShipment = Math.round(allocation.price / prepaidShipmentsPerBilling);
31
31
  return money(pricePerShipment);
32
32
  }
33
33