From 37f062fcb5119d01c9b091a1b84fdd17a9b8d10a Mon Sep 17 00:00:00 2001 From: Isabel Martin Date: Tue, 24 Sep 2024 09:11:46 -0700 Subject: [PATCH] SD-3241: Wrong shipping value for Shipping World Wide rewards (#2135) --- .../libs/utils/extensions/PledgeDataExt.kt | 9 ++++++--- .../libs/utils/extensions/PledgeDataExtTest.kt | 13 ++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/kickstarter/libs/utils/extensions/PledgeDataExt.kt b/app/src/main/java/com/kickstarter/libs/utils/extensions/PledgeDataExt.kt index aa96444f4a..26c39f67ef 100644 --- a/app/src/main/java/com/kickstarter/libs/utils/extensions/PledgeDataExt.kt +++ b/app/src/main/java/com/kickstarter/libs/utils/extensions/PledgeDataExt.kt @@ -18,9 +18,12 @@ fun PledgeData.locationId(): Long { * */ fun PledgeData.shippingCostIfShipping(): Double { - val rwShippingCost = if (RewardUtils.isShippable(this.reward())) - this.shippingRule()?.cost() ?: 0.0 - else 0.0 + val rwShippingCost = if (RewardUtils.isShippable(this.reward())) { + val matchingLocationIdRule = this.reward().shippingRules()?.find { it.location()?.id() == this.locationId() } + // - "Earth" shipping rule has location.id == 1 + matchingLocationIdRule?.cost() + ?: (this.reward().shippingRules()?.find { it.location()?.id() == 1L }?.cost() ?: 0.0) + } else 0.0 var addOnsShippingCost = 0.0 this.addOns()?.map { diff --git a/app/src/test/java/com/kickstarter/libs/utils/extensions/PledgeDataExtTest.kt b/app/src/test/java/com/kickstarter/libs/utils/extensions/PledgeDataExtTest.kt index d9050f643d..db5a673c96 100644 --- a/app/src/test/java/com/kickstarter/libs/utils/extensions/PledgeDataExtTest.kt +++ b/app/src/test/java/com/kickstarter/libs/utils/extensions/PledgeDataExtTest.kt @@ -14,7 +14,9 @@ class PledgeDataExtTest : TestCase() { fun `test checkoutTotalAmount for reward shipping with AddOns and bonus support on late pledges`() { val project = ProjectFactory.project() val shippingRule = ShippingRuleFactory.canadaShippingRule() - val rw = RewardFactory.rewardWithShipping().toBuilder().latePledgeAmount(8.0).pledgeAmount(2.0).build() + val rw = RewardFactory.rewardWithShipping().toBuilder() + .shippingRules(listOf(shippingRule)) + .latePledgeAmount(8.0).pledgeAmount(2.0).build() val addOn1 = RewardFactory.addOn().toBuilder() .id(1L) @@ -61,7 +63,9 @@ class PledgeDataExtTest : TestCase() { fun `test checkoutTotalAmount for reward shipping with AddOns and bonus support on crowdfund`() { val project = ProjectFactory.project() val shippingRule = ShippingRuleFactory.canadaShippingRule() - val rw = RewardFactory.rewardWithShipping().toBuilder().latePledgeAmount(8.0).pledgeAmount(2.0).build() + val rw = RewardFactory.rewardWithShipping().toBuilder() + .shippingRules(listOf(shippingRule)) + .latePledgeAmount(8.0).pledgeAmount(2.0).build() val addOn1 = RewardFactory.addOn().toBuilder().id(1L).quantity(3).latePledgeAmount(5.0).pledgeAmount(3.0).build() val addOn2 = RewardFactory.addOn().toBuilder().id(2L).quantity(2).latePledgeAmount(6.0).pledgeAmount(2.0).build() val addOns = listOf(addOn1, addOn2) @@ -75,9 +79,12 @@ class PledgeDataExtTest : TestCase() { } fun `test when the selected reward has shipping test shippingCostIfShipping`() { + val shippingRule = ShippingRuleFactory.canadaShippingRule() val rw = RewardFactory.rewardWithShipping() + .toBuilder() + .shippingRules(listOf(shippingRule)) + .build() val project = ProjectFactory.project() - val shippingRule = ShippingRuleFactory.canadaShippingRule() val pledgeData = with( PledgeFlowContext.NEW_PLEDGE,