-
Notifications
You must be signed in to change notification settings - Fork 53
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
in app messages support #1290
Merged
tonidero
merged 7 commits into
main
from
andy/sdk-3266-android-support-showing-inapp-messages
Sep 26, 2023
Merged
in app messages support #1290
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6d4fde5
draft for in app messages support
aboedo 76509bf
Use activity lifecycle callback to get activity and display billing c…
tonidero a4eca20
Improve docs
tonidero 151334a
Some fixes and tests
tonidero a8eb16f
Sync purchases if subscription status changed, to make sure we get la…
tonidero 31570b6
Display snackbar on app open by default
tonidero ed89ca6
standardize strings
tonidero 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
Some fixes and tests
- Loading branch information
commit 151334ae6b1cbafc94e3375ff58e382c5e7d7e40
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
137 changes: 137 additions & 0 deletions
137
purchases/src/test/java/com/revenuecat/purchases/PurchasesLifecycleTest.kt
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 |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package com.revenuecat.purchases | ||
|
||
import android.app.Activity | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.revenuecat.purchases.common.AppConfig | ||
import com.revenuecat.purchases.common.PlatformInfo | ||
import io.mockk.Runs | ||
import io.mockk.every | ||
import io.mockk.just | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.assertj.core.api.Assertions | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Config(manifest = Config.NONE) | ||
internal class PurchasesLifecycleTest: BasePurchasesTest() { | ||
|
||
// region app lifecycle | ||
|
||
@Test | ||
fun `state appInBackground is updated when app foregrounded`() { | ||
mockOfferingsManagerAppForeground() | ||
purchases.purchasesOrchestrator.state = purchases.purchasesOrchestrator.state.copy(appInBackground = true) | ||
Purchases.sharedInstance.purchasesOrchestrator.onAppForegrounded() | ||
Assertions.assertThat(purchases.purchasesOrchestrator.state.appInBackground).isFalse | ||
} | ||
|
||
@Test | ||
fun `state appInBackground is updated when app backgrounded`() { | ||
purchases.purchasesOrchestrator.state = purchases.purchasesOrchestrator.state.copy(appInBackground = false) | ||
Purchases.sharedInstance.purchasesOrchestrator.onAppBackgrounded() | ||
Assertions.assertThat(purchases.purchasesOrchestrator.state.appInBackground).isTrue | ||
} | ||
|
||
@Test | ||
fun `force update of caches when app foregrounded for the first time`() { | ||
mockOfferingsManagerAppForeground() | ||
purchases.purchasesOrchestrator.state = purchases.purchasesOrchestrator.state.copy(appInBackground = false, firstTimeInForeground = true) | ||
Purchases.sharedInstance.purchasesOrchestrator.onAppForegrounded() | ||
Assertions.assertThat(purchases.purchasesOrchestrator.state.firstTimeInForeground).isFalse | ||
verify(exactly = 1) { | ||
mockCustomerInfoHelper.retrieveCustomerInfo( | ||
appUserId, | ||
CacheFetchPolicy.FETCH_CURRENT, | ||
false, | ||
any() | ||
) | ||
} | ||
verify(exactly = 0) { | ||
mockCache.isCustomerInfoCacheStale(appInBackground = false, appUserID = appUserId) | ||
} | ||
} | ||
|
||
@Test | ||
fun `don't force update of caches when app foregrounded not for the first time`() { | ||
every { | ||
mockCache.isCustomerInfoCacheStale(appInBackground = false, appUserID = appUserId) | ||
} returns false | ||
mockOfferingsManagerAppForeground() | ||
purchases.purchasesOrchestrator.state = purchases.purchasesOrchestrator.state.copy(appInBackground = false, firstTimeInForeground = false) | ||
Purchases.sharedInstance.purchasesOrchestrator.onAppForegrounded() | ||
Assertions.assertThat(purchases.purchasesOrchestrator.state.firstTimeInForeground).isFalse | ||
verify(exactly = 0) { | ||
mockCustomerInfoHelper.retrieveCustomerInfo( | ||
appUserId, | ||
CacheFetchPolicy.FETCH_CURRENT, | ||
false, | ||
any() | ||
) | ||
} | ||
verify(exactly = 1) { | ||
mockCache.isCustomerInfoCacheStale(appInBackground = false, appUserID = appUserId) | ||
} | ||
} | ||
|
||
@Test | ||
fun `update of caches when app foregrounded not for the first time and caches stale`() { | ||
every { | ||
mockCache.isCustomerInfoCacheStale(appInBackground = false, appUserID = appUserId) | ||
} returns true | ||
mockOfferingsManagerAppForeground() | ||
purchases.purchasesOrchestrator.state = purchases.purchasesOrchestrator.state.copy(appInBackground = false, firstTimeInForeground = false) | ||
Purchases.sharedInstance.purchasesOrchestrator.onAppForegrounded() | ||
Assertions.assertThat(purchases.purchasesOrchestrator.state.firstTimeInForeground).isFalse | ||
verify(exactly = 1) { | ||
mockCustomerInfoHelper.retrieveCustomerInfo( | ||
appUserId, | ||
CacheFetchPolicy.FETCH_CURRENT, | ||
false, | ||
any() | ||
) | ||
} | ||
verify(exactly = 1) { | ||
mockCache.isCustomerInfoCacheStale(appInBackground = false, appUserID = appUserId) | ||
} | ||
} | ||
|
||
// endregion | ||
|
||
// region activity lifecycle | ||
|
||
@Test | ||
fun `activity on start does not show inapp messages if option disabled`() { | ||
resetShowDeclinedPaymentMessagesAutomatically(false) | ||
purchases.purchasesOrchestrator.onActivityStarted(mockk()) | ||
verify(exactly = 0) { mockBillingAbstract.showInAppMessagesIfNeeded(any()) } | ||
} | ||
|
||
@Test | ||
fun `activity on start shows inapp messages if option enabled`() { | ||
resetShowDeclinedPaymentMessagesAutomatically(true) | ||
val activity = mockk<Activity>() | ||
every { mockBillingAbstract.showInAppMessagesIfNeeded(activity) } just Runs | ||
purchases.purchasesOrchestrator.onActivityStarted(activity) | ||
verify(exactly = 1) { mockBillingAbstract.showInAppMessagesIfNeeded(activity) } | ||
} | ||
|
||
// endregion activity lifecycle | ||
|
||
// region Private | ||
|
||
private fun resetShowDeclinedPaymentMessagesAutomatically(showDeclinedPaymentMessagesAutomatically: Boolean) { | ||
purchases.purchasesOrchestrator.appConfig = AppConfig( | ||
mockContext, | ||
observerMode = false, | ||
showDeclinedPaymentMessagesAutomatically = showDeclinedPaymentMessagesAutomatically, | ||
PlatformInfo("", null), | ||
proxyURL = null, | ||
Store.AMAZON | ||
) | ||
} | ||
|
||
// endregion Private | ||
} |
Oops, something went wrong.
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.
I'm using a weak reference here since I want to avoid any chance of leaking the activity if there is a problem connecting to the billing client.