-
Notifications
You must be signed in to change notification settings - Fork 991
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-1744: Refactor Fix Pledge Flow #2142
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6bdb58f
- Bring Fix-Pledge into the new `CrowdfundCheckoutFragment/ViewModel`
Arkariang 3586168
Merge branch 'master' of github.com:kickstarter/android-oss into imar…
Arkariang 9798ccf
- Feature flagging the fix-pledge refactor
Arkariang e9187aa
- Tests
Arkariang 28f1ddc
- Fixed Tests, added callback to ProjectActivity to update states on …
Arkariang d5e4c04
- Clean up comments
Arkariang 4636ec6
Merge branch 'master' into imartin/MBL-1744
Arkariang 40c97ee
Merge branch 'master' into imartin/MBL-1744
Arkariang acd096a
Merge branch 'master' into imartin/MBL-1744
leighdouglas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,10 +161,11 @@ class CrowdfundCheckoutViewModel(val environment: Environment, bundle: Bundle? = | |
when (flowContext) { | ||
PledgeFlowContext.NEW_PLEDGE, | ||
PledgeFlowContext.CHANGE_REWARD -> getPledgeInfoFrom(pData) | ||
PledgeFlowContext.MANAGE_REWARD -> { | ||
PledgeFlowContext.MANAGE_REWARD, | ||
PledgeFlowContext.FIX_ERRORED_PLEDGE | ||
-> { | ||
backing?.let { getPledgeInfoFrom(it) } | ||
} | ||
|
||
else -> { | ||
errorAction.invoke(null) | ||
} | ||
|
@@ -363,7 +364,8 @@ class CrowdfundCheckoutViewModel(val environment: Environment, bundle: Bundle? = | |
PledgeReason.PLEDGE -> createBacking() | ||
PledgeReason.UPDATE_PLEDGE, | ||
PledgeReason.UPDATE_REWARD, | ||
PledgeReason.UPDATE_PAYMENT -> updateBacking() | ||
PledgeReason.UPDATE_PAYMENT, | ||
PledgeReason.FIX_PLEDGE -> updateBacking() | ||
else -> { | ||
errorAction.invoke(null) | ||
} | ||
|
@@ -407,6 +409,7 @@ class CrowdfundCheckoutViewModel(val environment: Environment, bundle: Bundle? = | |
project.backing()?.let { backing -> | ||
val backingData = when (pledgeReason) { | ||
PledgeReason.UPDATE_PAYMENT -> { | ||
// - Update payment should NOT send amounts | ||
val locationId = backing.locationId() ?: 0 | ||
val rwl = mutableListOf<Reward>() | ||
backing.reward()?.let { | ||
|
@@ -424,7 +427,9 @@ class CrowdfundCheckoutViewModel(val environment: Environment, bundle: Bundle? = | |
selectedPaymentMethod | ||
) | ||
} | ||
PledgeReason.UPDATE_REWARD -> { | ||
PledgeReason.UPDATE_REWARD, | ||
PledgeReason.UPDATE_PLEDGE -> { | ||
// - Update Reward/Pledge should send ALL newly selected rewards/Locations | ||
val isShippable = pledgeData?.reward()?.let { RewardUtils.isShippable(it) } ?: false | ||
val locationIdOrNull = | ||
if (isShippable) pledgeData?.shippingRule()?.location()?.id().toString() | ||
|
@@ -441,9 +446,14 @@ class CrowdfundCheckoutViewModel(val environment: Environment, bundle: Bundle? = | |
selectedPaymentMethod | ||
) | ||
} | ||
PledgeReason.FIX_PLEDGE, // Managed on PledgeFragment/ViewModel | ||
PledgeReason.FIX_PLEDGE -> { | ||
// - Fix pledge should NOT send amounts/rewardId's/locationId ONLY selected paymentMethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
getUpdateBackingData( | ||
backing = backing, | ||
pMethod = selectedPaymentMethod | ||
) | ||
} | ||
PledgeReason.PLEDGE, // Error | ||
PledgeReason.UPDATE_PLEDGE, // Error | ||
PledgeReason.LATE_PLEDGE, // Error | ||
null -> { null } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -785,6 +785,106 @@ class CrowdfundCheckoutViewModelTest : KSRobolectricTestCase() { | |
segmentTrack.assertValue(EventName.PAGE_VIEWED.eventName) | ||
} | ||
|
||
@Test | ||
fun `test fix Pledge Flow`() = runTest { | ||
val shippingRules = ShippingRulesEnvelopeFactory.shippingRules().shippingRules() | ||
val rewardBacked = RewardFactory.rewardWithShipping().toBuilder() | ||
.shippingRules(shippingRules = shippingRules) | ||
.build() | ||
|
||
val addOns1Backed = RewardFactory.rewardWithShipping() | ||
.toBuilder() | ||
.isAddOn(true) | ||
.shippingRules(shippingRules) | ||
.build() | ||
|
||
val backing = BackingFactory.backing(rewardBacked) | ||
.toBuilder() | ||
.addOns(listOf(addOns1Backed)) | ||
.location(shippingRules.first().location()) | ||
.locationId(shippingRules.first().location()?.id()) | ||
.bonusAmount(5.0) | ||
.amount(44.0) | ||
.shippingAmount(33f) | ||
.paymentSource(PaymentSourceFactory.visa()) | ||
.build() | ||
|
||
val project = ProjectFactory.project().toBuilder() | ||
.backing(backing) | ||
.isBacking(true) | ||
.rewards(listOf(rewardBacked)) | ||
.build() | ||
|
||
val cards = listOf(StoredCardFactory.visa(), StoredCardFactory.discoverCard(), StoredCardFactory.fromPaymentSheetCard()) | ||
|
||
val user = UserFactory.user() | ||
val currentUserV2 = MockCurrentUserV2(initialUser = user) | ||
|
||
val projectData = ProjectDataFactory.project(project) | ||
|
||
val bundle = Bundle() | ||
|
||
val pledgeData = PledgeData.with( | ||
PledgeFlowContext.forPledgeReason(PledgeReason.FIX_PLEDGE), | ||
projectData, | ||
rewardBacked, | ||
bonusAmount = 7.0, | ||
addOns = listOf(addOns1Backed.toBuilder().quantity(5).build()) | ||
) | ||
|
||
bundle.putParcelable( | ||
ArgumentsKey.PLEDGE_PLEDGE_DATA, | ||
pledgeData | ||
) | ||
bundle.putSerializable(ArgumentsKey.PLEDGE_PLEDGE_REASON, PledgeReason.FIX_PLEDGE) | ||
|
||
lateinit var data: UpdateBackingData | ||
val environment = environment().toBuilder() | ||
.apolloClientV2(object : MockApolloClientV2() { | ||
override fun getStoredCards(): Observable<List<StoredCard>> { | ||
return Observable.just(cards) | ||
} | ||
|
||
override fun userPrivacy(): Observable<UserPrivacy> { | ||
return Observable.just( | ||
UserPrivacy("", "[email protected]", true, true, true, true, "USD") | ||
) | ||
} | ||
|
||
override fun updateBacking(updateBackingData: UpdateBackingData): Observable<Checkout> { | ||
data = updateBackingData | ||
val checkout = Checkout.builder().id(77L).backing(Checkout.Backing.builder().requiresAction(false).clientSecret("clientSecret").build()).build() | ||
return Observable.just(checkout) | ||
} | ||
}) | ||
.currentUserV2(currentUserV2) | ||
.build() | ||
|
||
setUpEnvironment(environment) | ||
|
||
val dispatcher = UnconfinedTestDispatcher(testScheduler) | ||
val checkout = mutableListOf<Pair<CheckoutData, PledgeData>>() | ||
|
||
backgroundScope.launch(dispatcher) { | ||
viewModel.provideScopeAndDispatcher(this, dispatcher) | ||
viewModel.provideBundle(bundle) | ||
viewModel.userChangedPaymentMethodSelected(cards.first()) | ||
viewModel.pledgeOrUpdatePledge() | ||
viewModel.checkoutResultState.toList(checkout) | ||
} | ||
advanceUntilIdle() | ||
|
||
assertEquals(data.rewardsIds?.size, null) | ||
assertEquals(data.rewardsIds?.first(), null) | ||
assertEquals(data.amount, null) | ||
|
||
// Fix pledge flow should only payment ID anything else | ||
assertEquals(data.rewardsIds?.size, null) | ||
assertEquals(data.rewardsIds?.first(), null) | ||
assertEquals(data.amount, null) | ||
assertEquals(data.paymentSourceId, cards.first().id()) | ||
} | ||
|
||
@Test | ||
fun `test adding new paymentMethod throw Stripe's paymentSheet`() = runTest { | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling
activate
when the activity is loaded will minimize the fist installation gap when the information requested to firebase remote config has not yet been applied.