From ea3e15f0c8459122e4b02b3212c01a4883d69b4d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 11 Mar 2022 11:06:28 +0100 Subject: [PATCH] Max|Current fulfilled value is the max|current divided by group_buy_unit_size + improve testing with representative values + Update bulk_order_management_spec.rb and revert previously changed values --- .../line_items_controller.js.coffee | 6 +++--- .../line_items_controller_spec.js.coffee | 20 +++++++++++-------- .../admin/bulk_order_management_spec.rb | 4 ++-- 3 files changed, 17 insertions(+), 13 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 aa575c1e7e..16376ed14a 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 @@ -182,9 +182,9 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout, 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.getScale($scope.selectedUnitsProduct, $scope.selectedUnitsVariant) - sumOfUnitValues = sumOfUnitValues / scale if scale == 28.35 || scale == 453.6 # divide by scale if smallest unit - $scope.roundToThreeDecimals(sumOfUnitValues / $scope.selectedUnitsProduct.group_buy_unit_size * $scope.selectedUnitsVariant.unit_value) + 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 a9114f1fef..e54b71995b 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 @@ -169,15 +169,19 @@ describe "LineItemsCtrl", -> scope.fulfilled() expect(Math.round).toHaveBeenCalled() - it "returns the quantity of fulfilled group buy units", -> - scope.selectedUnitsProduct = { variant_unit: "weight", group_buy_unit_size: 1000 } - scope.selectedUnitsVariant = { unit_value: 1 } - expect(scope.fulfilled(1500)).toEqual 1.5 - it "returns the quantity of fulfilled group buy units by volume", -> - scope.selectedUnitsProduct = { variant_unit: "volume", group_buy_unit_size: 5000 } - scope.selectedUnitsVariant = { unit_value: 1000 } - expect(scope.fulfilled(5)).toEqual 1 + describe "returns the quantity of fulfilled group buy units", -> + runs = [ + { selectedUnitsProduct: { variant_unit: "weight", group_buy_unit_size: 1000, variant_unit_scale: 1 }, arg: 1500, expected: 1.5 }, + { selectedUnitsProduct: { variant_unit: "weight", group_buy_unit_size: 60000, variant_unit_scale: 1000 }, arg: 9, expected: 0.15 }, + { selectedUnitsProduct: { variant_unit: "weight", group_buy_unit_size: 60000, variant_unit_scale: 1 }, arg: 9000, expected: 0.15 } + { selectedUnitsProduct: { variant_unit: "weight", group_buy_unit_size: 5, variant_unit_scale: 28.35 }, arg: 12, expected: 2.4}, + { selectedUnitsProduct: { variant_unit: "volume", group_buy_unit_size: 5000, variant_unit_scale: 1 }, arg: 5, expected: 0.001} + ]; + runs.forEach ({selectedUnitsProduct, arg, expected}) -> + it "returns the quantity of fulfilled group buy units, group_buy_unit_size: " + selectedUnitsProduct.group_buy_unit_size + ", arg: " + arg + ", scale: " + selectedUnitsProduct.variant_unit_scale , -> + scope.selectedUnitsProduct = selectedUnitsProduct + expect(scope.fulfilled(arg)).toEqual expected describe "allFinalWeightVolumesPresent()", -> it "returns false if the unit_value of any item in filteredLineItems does not exist", -> diff --git a/spec/system/admin/bulk_order_management_spec.rb b/spec/system/admin/bulk_order_management_spec.rb index d78619f454..d05949130e 100644 --- a/spec/system/admin/bulk_order_management_spec.rb +++ b/spec/system/admin/bulk_order_management_spec.rb @@ -823,9 +823,9 @@ describe ' expect(page).to have_text "Max Quantity Ordered" expect(page).to have_text "9000 g" expect(page).to have_text "Current Fulfilled Units" - expect(page).to have_text "800" + expect(page).to have_text "0.8" expect(page).to have_text "Max Fulfilled Units" - expect(page).to have_text "1800" + expect(page).to have_text "1.8" expect(page).to have_selector "div.shared_resource", visible: true within "div.shared_resource" do expect(page).to have_selector "span", text: "Shared Resource?"