Skip to content

Commit

Permalink
SD-3241: Wrong shipping value for Shipping World Wide rewards (#2135)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkariang authored Sep 24, 2024
1 parent 6bb04b6 commit 37f062f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 37f062f

Please sign in to comment.