Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

MBL-1550: Don't change selected card when unavailable card is added to payment methods #2081

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

amy-at-kickstarter
Copy link
Contributor

@amy-at-kickstarter amy-at-kickstarter commented Jun 18, 2024

📲 What

Don't change the selection on the Payments sheet if the newly added card is disabled.

🤔 Why

Now that we're saving cards immediately, it's possible to add a card that's not available for the current project. The previous logic would try and select the card, even if it was unavailable; this short-circuits that edge case. Fixing this prevents a bunch of unfortunate behavior as documented in the ticket.

@@ -1786,4 +1786,231 @@ final class PledgePaymentMethodsViewModelTests: TestCase {
XCTAssertTrue(allowedDelayedPaymentMethods)
}
}

// A test for MBL-1550
func testAddNewUnavailablePaymentMethod_userAlreadyHasCard_selectsValidPaymentMethod() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One line to fix the bug, 229 lines to test it.

XCTAssertEqual(self.reloadPaymentMethodsCards.lastValue?.count, 0)

// The discover is disabled and not selected.
let discoverCardData = self.reloadPaymentSheetPaymentMethodsCards.lastValue?.first(where: { (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can someone remind me if there's a more beautiful way to do this search? Maybe with a keypath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW I did this because the cards weren't ordered the way I expected, but I also realized it doesn't matter what order two disabled cards are in.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know a nicer way 😭 Tbh, if it's deterministic, I think I'd just go by the index (which would mean that the test would need to be changed if we change the order in the future, so I think I do like this search better).

@amy-at-kickstarter amy-at-kickstarter marked this pull request as ready for review June 18, 2024 15:59
@amy-at-kickstarter amy-at-kickstarter requested review from a team, scottkicks and ifosli and removed request for a team June 18, 2024 15:59

self.scheduler.run()

// There are now twos card, in the new section
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: "two cards" instead of "twos card"

XCTAssertEqual(self.reloadPaymentMethodsCards.lastValue?.count, 0)

// The discover is disabled and not selected.
let discoverCardData = self.reloadPaymentSheetPaymentMethodsCards.lastValue?.first(where: { (
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know a nicer way 😭 Tbh, if it's deterministic, I think I'd just go by the index (which would mean that the test would need to be changed if we change the order in the future, so I think I do like this search better).

let newCardData = self.reloadPaymentSheetPaymentMethodsCards.lastValue?.first
XCTAssertEqual(newCardData?.isEnabled, false)
XCTAssertEqual(newCardData?.isSelected, false)
XCTAssertNil(self.reloadPaymentMethodsSelectedCardId.lastValue ?? nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I haven't looked through all the tests again so this may be unnecessary, but should we also test that the pledge button doesn't get enabled in this test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh that's a great idea but this test doesn't have the pledge button! It's just the isolated payment sheet. The test for pledges don't have access to the payment sheet itself. So I'm not sure we actually can test the complete behavior of the bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The PledgeViewController watches the signal/delegate call for when a card is selected, so testing that behavior should hopefully be sufficient.

let newCardData = self.reloadPaymentSheetPaymentMethodsCards.lastValue?.first
XCTAssertEqual(newCardData?.isEnabled, false)
XCTAssertEqual(newCardData?.isSelected, false)
XCTAssertNil(self.reloadPaymentMethodsSelectedCardId.lastValue ?? nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

@amy-at-kickstarter amy-at-kickstarter merged commit 87add1a into main Jun 18, 2024
5 checks passed
@amy-at-kickstarter amy-at-kickstarter deleted the bug/adyer/MBL-1550 branch June 18, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants