Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[MBL-1687] Fix continue button on confirm details page not working #2147 #2148

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Library/ViewModels/ConfirmDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,14 @@ public class ConfirmDetailsViewModel: ConfirmDetailsViewModelType, ConfirmDetail
return [String](repeating: reward.graphID, count: count)
}

let locationId = selectedShippingRule == nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: You could do selectedShippingRule.flatMap { String($0.location.id) } to make this one line and remove the ! below (and do the same for NoShippingConfirmDetailsViewModel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that! Thanks!

? nil
: String(selectedShippingRule!.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
6 changes: 5 additions & 1 deletion Library/ViewModels/NoShippingConfirmDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,14 @@ public class NoShippingConfirmDetailsViewModel: NoShippingConfirmDetailsViewMode
return [String](repeating: reward.graphID, count: count)
}

let locationId = selectedShippingRule == nil
? nil
: String(selectedShippingRule!.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