From a4afeeaa3d062b6e1a99975833bbc050c05362e0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 25 Apr 2022 15:53:38 +0200 Subject: [PATCH] When BOM is 'item', do not update sumOfUnitValues with scale since scale is always `1`, but return a value + update tests as well --- .../controllers/line_items_controller.js.coffee | 10 +++++----- .../controllers/line_items_controller_spec.js.coffee | 11 ++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee index b05150522f..0d67d632a7 100644 --- a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee +++ b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee @@ -211,11 +211,11 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout, $scope.fulfilled = (sumOfUnitValues) -> # A Units Variant is an API object which holds unit properies of a variant - if $scope.selectedUnitsProduct.hasOwnProperty("group_buy_unit_size") && $scope.selectedUnitsProduct.group_buy_unit_size > 0 && - $scope.selectedUnitsProduct.hasOwnProperty("variant_unit") && - ( $scope.selectedUnitsProduct.variant_unit == "weight" || $scope.selectedUnitsProduct.variant_unit == "volume" ) - scale = $scope.selectedUnitsProduct.variant_unit_scale - sumOfUnitValues = sumOfUnitValues * scale unless scale == 28.35 || scale == 453.6 + if $scope.selectedUnitsProduct.hasOwnProperty("group_buy_unit_size")&& $scope.selectedUnitsProduct.group_buy_unit_size > 0 && + $scope.selectedUnitsProduct.hasOwnProperty("variant_unit") + if $scope.selectedUnitsProduct.variant_unit == "weight" || $scope.selectedUnitsProduct.variant_unit == "volume" + scale = $scope.selectedUnitsProduct.variant_unit_scale + sumOfUnitValues = sumOfUnitValues * scale unless scale == 28.35 || scale == 453.6 $scope.roundToThreeDecimals(sumOfUnitValues / $scope.selectedUnitsProduct.group_buy_unit_size) else '' diff --git a/spec/javascripts/unit/admin/line_items/controllers/line_items_controller_spec.js.coffee b/spec/javascripts/unit/admin/line_items/controllers/line_items_controller_spec.js.coffee index 60b0c6a77c..72798f3a8e 100644 --- a/spec/javascripts/unit/admin/line_items/controllers/line_items_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/line_items/controllers/line_items_controller_spec.js.coffee @@ -207,13 +207,7 @@ describe "LineItemsCtrl", -> scope.selectedUnitsProduct = { variant_unit: "weight" } expect(scope.fulfilled()).toEqual '' - it "returns '', and does not call Math.round if variant_unit is 'items'", -> - spyOn(Math,"round") - scope.selectedUnitsProduct = { variant_unit: "items", group_buy_unit_size: 10 } - expect(scope.fulfilled()).toEqual '' - expect(Math.round).not.toHaveBeenCalled() - - it "calls Math.round() if variant_unit is 'weight' or 'volume'", -> + it "calls Math.round() if variant_unit is 'weight', 'volume', or items", -> spyOn(Math,"round") scope.selectedUnitsProduct = { variant_unit: "weight", group_buy_unit_size: 10 } scope.fulfilled() @@ -221,6 +215,9 @@ describe "LineItemsCtrl", -> scope.selectedUnitsProduct = { variant_unit: "volume", group_buy_unit_size: 10 } scope.fulfilled() expect(Math.round).toHaveBeenCalled() + scope.selectedUnitsProduct = { variant_unit: "items", group_buy_unit_size: 10 } + scope.fulfilled() + expect(Math.round).toHaveBeenCalled() describe "returns the quantity of fulfilled group buy units", ->