Skip to content

Commit

Permalink
[MBL-1687] Fix continue button on confirm details page not working #2147
Browse files Browse the repository at this point in the history
 (#2148)

* Fix broken late pledge by handling location id correctly

* Fix failing test

* simplify locationId
  • Loading branch information
ifosli authored Sep 5, 2024
1 parent f1cd7bd commit 0b0c46b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 3 additions & 1 deletion Library/ViewModels/ConfirmDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,12 @@ public class ConfirmDetailsViewModel: ConfirmDetailsViewModelType, ConfirmDetail
return [String](repeating: reward.graphID, count: count)
}

let locationId = selectedShippingRule.flatMap { String($0.location.id) }

return CreateCheckoutInput(
projectId: project.graphID,
amount: String(format: "%.2f", pledgeTotal),
locationId: "\(selectedShippingRule?.location.id)",
locationId: locationId,
rewardIds: rewardsIDs,
refParam: refTag?.stringTag
)
Expand Down
4 changes: 3 additions & 1 deletion Library/ViewModels/NoShippingConfirmDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,12 @@ public class NoShippingConfirmDetailsViewModel: NoShippingConfirmDetailsViewMode
return [String](repeating: reward.graphID, count: count)
}

let locationId = selectedShippingRule.flatMap { String($0.location.id) }

return CreateCheckoutInput(
projectId: project.graphID,
amount: String(format: "%.2f", pledgeTotal),
locationId: "\(selectedShippingRule?.location.id)",
locationId: locationId,
rewardIds: rewardsIDs,
refParam: refTag?.stringTag
)
Expand Down
35 changes: 17 additions & 18 deletions Library/ViewModels/NoShippingConfirmDetailsViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,7 @@ final class NoShippingConfirmDetailsViewModelTests: TestCase {
])
}

// TODO(MBL-1687): This test should be fixed when the corresponding flow works.
func testContinueButton_CallsCreateBackingMutation_Success() throws {
throw XCTSkip()
func testContinueButton_CallsCreateBackingMutation_Success() {
let expectedId = "Q2hlY2tvdXQtMTk4MzM2NjQ2"
let createCheckout = CreateCheckoutEnvelope.Checkout(
id: expectedId,
Expand All @@ -438,34 +436,35 @@ final class NoShippingConfirmDetailsViewModelTests: TestCase {

let expectedRewards = [reward, addOnReward1]
let selectedQuantities = [reward.id: 1, addOnReward1.id: 1]
let data = PledgeViewData(
project: project,
rewards: expectedRewards,
selectedShippingRule: nil,
selectedQuantities: selectedQuantities,
selectedLocationId: ShippingRule.template.id,
refTag: nil,
context: .pledge
)

self.vm.inputs.configure(with: data)
self.vm.inputs.viewDidLoad()

let expectedShipping = PledgeShippingSummaryViewData(
locationName: "Los Angeles, CA",
locationName: "United States",
omitUSCurrencyCode: true,
projectCountry: .us,
total: 3
)

let selectedShippingRule = ShippingRule(
cost: expectedShipping.total,
id: nil,
location: .losAngeles,
id: 47,
location: .usa,
estimatedMin: Money(amount: 1.0),
estimatedMax: Money(amount: 10.0)
)

let data = PledgeViewData(
project: project,
rewards: expectedRewards,
selectedShippingRule: selectedShippingRule,
selectedQuantities: selectedQuantities,
selectedLocationId: ShippingRule.template.id,
refTag: nil,
context: .pledge
)

self.vm.inputs.configure(with: data)
self.vm.inputs.viewDidLoad()

let expectedBonus = 5.0
self.vm.inputs.pledgeAmountViewControllerDidUpdate(
with: (amount: expectedBonus, min: 0, max: 100, isValid: true)
Expand Down

0 comments on commit 0b0c46b

Please sign in to comment.