Skip to content

Paywalls: PaywallViewModel tests#1357

Merged
NachoSoto merged 3 commits into
paywallsfrom
paywalls-view-model-tests
Oct 19, 2023
Merged

Paywalls: PaywallViewModel tests#1357
NachoSoto merged 3 commits into
paywallsfrom
paywalls-view-model-tests

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Oct 16, 2023

Copy link
Copy Markdown
Contributor

There's more things we could test, but this is a start.

@NachoSoto NachoSoto added the test label Oct 16, 2023
@NachoSoto NachoSoto requested a review from a team October 16, 2023 21:59

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❤️

@NachoSoto NachoSoto force-pushed the paywalls-view-model-tests branch 4 times, most recently from 5253072 to c88bdb7 Compare October 18, 2023 00:52
@NachoSoto NachoSoto marked this pull request as ready for review October 18, 2023 00:53
Comment thread gradle/libs.versions.toml Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Required for InstantTaskExecutorRule

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved this to build so that it doesn't have to run during the new tests. Instead, we mock the call to purchase with the builder. That way we can still test the rest without it failing to build purchase params with a test product.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suppresses the warning for as T.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I hate that warning haha

@NachoSoto NachoSoto requested a review from tonidero October 18, 2023 00:55
@NachoSoto

Copy link
Copy Markdown
Contributor Author

@tonidero this should be ready now :)

@NachoSoto NachoSoto force-pushed the paywalls-view-model-tests branch 2 times, most recently from bf7fd6a to 0b01c0e Compare October 18, 2023 00:57
@codecov

codecov Bot commented Oct 18, 2023

Copy link
Copy Markdown

Codecov Report

All modified lines are covered by tests ✅

❗ No coverage uploaded for pull request base (paywalls@19ab46b). Click here to learn what that means.

❗ Current head af14fc4 differs from pull request most recent head c24bd01. Consider uploading reports for the commit c24bd01 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             paywalls    #1357   +/-   ##
===========================================
  Coverage            ?   84.55%           
===========================================
  Files               ?      194           
  Lines               ?     6545           
  Branches            ?      953           
===========================================
  Hits                ?     5534           
  Misses              ?      643           
  Partials            ?      368           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I hate that warning haha

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's this extension function for? Why not accessing activeSubscriptions directly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is unused now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why this change?

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/PurchaseParams.kt Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am a bit confused about the need of this class, why not making Purchases a dependency of PaywallViewModelImpl and mocking the extension functions directly?

Also, I find the name a bit confusing. PurchasesImpl implies it's implementing Purchases but it's not, and it's actually composed by Purchases and implementing PurchasesType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean, this is cleaner than mocking extensions, but I guess I am confused by the names

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We talked about this in Slack. We need this to simplify how we mock coroutines from Purchases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should have an @After that clears mocks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Like this?

@After
internal fun tearDown() {
    clearAllMocks()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That should work. We are recreating most of the mocks on each test (in the setUp), but the mockkStatic wouldn't get reset without that or unmockkStatic

@NachoSoto NachoSoto force-pushed the paywalls-view-model-tests branch 2 times, most recently from c985df7 to af14fc4 Compare October 18, 2023 21:11
@NachoSoto

Copy link
Copy Markdown
Contributor Author

@vegaro I think I addressed the rest of your comments.

Comment thread examples/paywall-tester/src/main/java/com/revenuecat/paywallstester/Constants.kt Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is unused now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That should work. We are recreating most of the mocks on each test (in the setUp), but the mockkStatic wouldn't get reset without that or unmockkStatic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess we are not verifying the changes in this value, but I'm unsure on what's the best way to do this with coroutines... (with callbacks, I would hold a reference to the callback and call it at the appropriate time)... With coroutines, I can only think of delaying the response to verify this field, but not really a great option... Any ideas @vegaro? I don't think this is a blocker though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I tried different things but couldn't figure it out.
Definitely a useful addition to these tests though.

@NachoSoto NachoSoto force-pushed the paywalls-view-model-tests branch from af14fc4 to c105465 Compare October 19, 2023 15:07
@NachoSoto NachoSoto requested review from tonidero and vegaro October 19, 2023 15:07
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Addressed all comments I think

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think there is still an infinite loop there? Other than that, looks good!

@NachoSoto NachoSoto enabled auto-merge (squash) October 19, 2023 15:16
@NachoSoto NachoSoto merged commit c2f6627 into paywalls Oct 19, 2023
@NachoSoto NachoSoto deleted the paywalls-view-model-tests branch October 19, 2023 15:33
tonidero pushed a commit that referenced this pull request Oct 31, 2023
There's more things we could test, but this is a start.
NachoSoto added a commit that referenced this pull request Oct 31, 2023
### New Features
#### ✨📱 Introducing Android Paywalls 🐾🧱

RevenueCat's Paywalls allow you to remotely configure your entire
paywall view without any code changes or app updates.
Our paywall templates use native code to deliver smooth, intuitive
experiences to your customers when you’re ready to deliver them an
Offering; and you can use our Dashboard to pick the right template and
configuration to meet your needs.

To use RevenueCat Paywalls on Android, simply:

1. Create a Paywall on the Dashboard for the `Offering` you intend to
serve to your customers
2. Add the `RevenueCatUI` dependency to your project:
```groovy build.gradle
implementation 'com.revenuecat.purchases:purchases:7.1.0'
implementation 'com.revenuecat.purchases:purchases-ui:7.1.0'
```
3. Display a paywall:
```kotlin
@OptIn(ExperimentalPreviewRevenueCatUIPurchasesAPI::class)
@composable
private fun LockedScreen() {
    YourContent()

    PaywallDialog(
        PaywallDialogOptions.Builder()
            .setRequiredEntitlementIdentifier(Constants.ENTITLEMENT_ID)
            .build()
    )
}
```

> **Note**
> Android paywalls is currently behind an experimental flag:
`ExperimentalPreviewRevenueCatUIPurchasesAPI`.
> It is safe to release app updates with it. We guarantee that paywalls
will continue to work and any changes will always be backwards
compatible.
> They are stable, but migration steps may be required in the future.
We'll do our best to minimize any changes you have to make.

You can find more information in [our
documentation](https://rev.cat/paywalls).

<details>

<summary>List of changes</summary>

* `Paywalls`: Improve PaywallDialog look on tablets (#1419) via Toni
Rico (@tonidero)
* `Paywalls`: disallow Markdown links in PurchaseButton (#1421) via
NachoSoto (@NachoSoto)
* `Paywalls`: implemented template 5 (#1412) via NachoSoto (@NachoSoto)
* `Paywalls`: Fix wrong view model data after configuration changes
(#1417) via Toni Rico (@tonidero)
* `Paywalls`: update template 4 colors (#1410) via NachoSoto
(@NachoSoto)
* `Paywalls`: Add bundled font to paywall tester (#1415) via Toni Rico
(@tonidero)
* `Paywalls`: Fix purchase button text flashing when changing selected
package (#1416) via Toni Rico (@tonidero)
* `Paywalls`: support text3 and accent3 colors (#1409) via NachoSoto
(@NachoSoto)
* `Paywalls`: PaywallData errors shouldn't make Offerings fail to decode
(#1402) via NachoSoto (@NachoSoto)
* `Paywalls`: convert empty strings to null via NachoSoto (@NachoSoto)
* `Paywalls`: footer view should not render background image via
NachoSoto (@NachoSoto)
* `Paywalls`: improve template 4 A11y support via NachoSoto (@NachoSoto)
* `Paywalls`: Add close button option (#1390) via Toni Rico (@tonidero)
* `Paywalls`: fix MarkdownText stealing touches from package buttons
(#1411) via NachoSoto (@NachoSoto)
* Fix onDismiss getting called twice in PaywallDialogs (#1408) via Cesar
de la Vega (@vegaro)
* `Paywalls`: ignore URL deserialization errors (#1399) via NachoSoto
(@NachoSoto)
* Animate transition between loading and loaded paywall (#1404) via
Cesar de la Vega (@vegaro)
* Fix button padding in Loading paywall (#1405) via Cesar de la Vega
(@vegaro)
* Add test for `packageInfo.localizedDiscount` (#1407) via Cesar de la
Vega (@vegaro)
* `Paywalls`: RemoteImage always renders a placeholder on previews via
NachoSoto (@NachoSoto)
* `Paywalls`: decode empty images as null via NachoSoto (@NachoSoto)
* `Paywalls`: Allow trigger manual paywall tester release (#1406) via
Toni Rico (@tonidero)
* Fix navigation after closing paywall in Paywalls screen (#1403) via
Cesar de la Vega (@vegaro)
* `Paywalls`: Add experimental annotation to all public APIs in
RevenueCat UI (#1400) via Toni Rico (@tonidero)
* `Paywalls`: improve template 2 layout (#1396) via NachoSoto
(@NachoSoto)
* `Paywalls`: template 4 (#1349) via NachoSoto (@NachoSoto)
* `Paywalls`: fix template 3 offer details color (#1394) via NachoSoto
(@NachoSoto)
* `Paywalls`: PaywallDialogOptions no longer requires dismissRequest
(#1386) via NachoSoto (@NachoSoto)
* `Paywalls`: fixed accessibility across templates (#1392) via NachoSoto
(@NachoSoto)
* `Paywalls`: increase PaywallBackground blur radius to match iOS via
NachoSoto (@NachoSoto)
* `Paywalls`: use LocalUriHandler for opening links (#1388) via
NachoSoto (@NachoSoto)
* `Paywalls`: support for Markdown links (#1387) via NachoSoto
(@NachoSoto)
* `Paywalls`: display purchase/restore errors (#1384) via NachoSoto
(@NachoSoto)
* `Paywalls`: improve error handling (#1383) via NachoSoto (@NachoSoto)
* `Paywalls`: fixed incorrect background on footer (#1382) via NachoSoto
(@NachoSoto)
* `Paywalls`: fix backwards-compatible blurring of default paywall
background (#1380) via NachoSoto (@NachoSoto)
* `Paywalls`: polish template 2 spacing (#1381) via NachoSoto
(@NachoSoto)
* `Paywalls`: optimize backwards compatible blurring (#1379) via
NachoSoto (@NachoSoto)
* `Paywalls`: Predownload offering images if paywalls sdk exists (#1372)
via Toni Rico (@tonidero)
* `Paywalls`: PurchaseButton supports gradients (#1378) via NachoSoto
(@NachoSoto)
* `Paywalls`: optimize AdaptiveComposable (#1377) via NachoSoto
(@NachoSoto)
* `Paywalls`: improve FooterDialog corner radius (#1374) via NachoSoto
(@NachoSoto)
* `Paywalls`: optimize PurchaseButton (#1376) via NachoSoto (@NachoSoto)
* `Paywalls`: Enable footer modes in paywall tester paywalls tab (#1368)
via Toni Rico (@tonidero)
* `Paywalls`: Support footer in template 3 (#1367) via Toni Rico
(@tonidero)
* `Paywalls`: calculate discountRelativeToMostExpensivePerMonth (#1370)
via NachoSoto (@NachoSoto)
* `Paywalls`: Add offer details in template 2 when in condensed form
(#1371) via Toni Rico (@tonidero)
* `Paywalls`: improve handling of lifetime/custom packages (#1363) via
NachoSoto (@NachoSoto)
* `Paywalls`: Support footer in template 1 (#1366) via Toni Rico
(@tonidero)
* Add `StoreProduct.pricePerMonth` (#1369) via NachoSoto (@NachoSoto)
* `Paywalls`: Support condensed footer presentation in template 2
(#1365) via Toni Rico (@tonidero)
* `Paywalls`: finished localization support (#1362) via NachoSoto
(@NachoSoto)
* `Paywalls`: backwards compatible blurring (#1327) via Andy Boedo
(@AndyBoedo)
* `Paywalls`: PaywallViewModel tests (#1357) via NachoSoto (@NachoSoto)
* `Paywalls`: improve LoadingPaywall (#1364) via NachoSoto (@NachoSoto)
* `Paywalls`: Fix paywall compose previews (#1360) via Toni Rico
(@tonidero)
* `Paywalls`: Fix proguard rules kotlinx serialization (#1356) via Toni
Rico (@tonidero)
* `Paywalls`: Add custom font example to paywalls screen (#1358) via
Toni Rico (@tonidero)
* `Paywalls`: Support Google fonts and font families with multiple fonts
(#1338) via Toni Rico (@tonidero)
* `Paywalls`: Support custom fonts through FontProvider (#1328) via Toni
Rico (@tonidero)
* `Paywalls`: fixed Footer padding (#1354) via NachoSoto (@NachoSoto)
* `Paywalls`: Rename PaywallView to Paywall (#1351) via Toni Rico
(@tonidero)
* `Paywalls`: disable PurchaseButton during purchases (#1352) via
NachoSoto (@NachoSoto)
* `Paywalls`: enable library publishing (#1353) via NachoSoto
(@NachoSoto)
* `Paywalls`: handle "action in progress" state (#1346) via NachoSoto
(@NachoSoto)
* `Paywalls`: support {{ sub_duration_in_months }} (#1348) via NachoSoto
(@NachoSoto)
* `Paywalls`: disallow purchasing currently subscribed products (#1334)
via NachoSoto (@NachoSoto)
* `Paywalls`: new PaywallActivityLauncher.launchIfNeeded methods (#1335)
via NachoSoto (@NachoSoto)
* `Paywalls`: PaywallColor supports RGBA (#1332) via NachoSoto
(@NachoSoto)
* `Paywalls`: Make DialogScaffold private (#1329) via Toni Rico
(@tonidero)
* Add `revenuecatui` `gradle.properties` to specify name of dependency
(#1324) via Toni Rico (@tonidero)
* `Paywalls`: log error when failing to load images (#1321) via
NachoSoto (@NachoSoto)
* Log errors when displaying default paywall (#1318) via Cesar de la
Vega (@vegaro)
* Rename packages to packageIds in `PaywallData` (#1309) via Cesar de la
Vega (@vegaro)
* Add support for multiple intro offers in `IntroEligibilityStateView`
(#1319) via Cesar de la Vega (@vegaro)
* Fix material theme references to use Material3 versions (#1326) via
Toni Rico (@tonidero)
* `Paywalls`: Add support to launch paywall as activity (#1317) via Toni
Rico (@tonidero)
* Parse `{{ sub_offer_price_2 }}` and `{{ sub_offer_duration_2 }}`
variables (#1313) via Cesar de la Vega (@vegaro)
* `Paywalls`: changed PaywallsTester app icon (#1323) via NachoSoto
(@NachoSoto)
* `Paywalls`: fixed PaywallDialog.setRequiredEntitlementIdentifier
(#1322) via NachoSoto (@NachoSoto)
* `Paywalls`: Markdown support (#1312) via NachoSoto (@NachoSoto)
* `PaywallsTester`: added template name to offerings list (#1316) via
NachoSoto (@NachoSoto)
* `Paywalls`: Update paywall tester to be able to display paywall footer
(#1315) via Toni Rico (@tonidero)
* `Paywalls`: Add PaywallFooter composable to present a minified paywall
UI that allows for custom paywalls (#1314) via Toni Rico (@tonidero)
* `Paywalls`: use IntroEligibilityStateView (#1311) via NachoSoto
(@NachoSoto)
* `PaywallData` validation tests (#1310) via Cesar de la Vega (@vegaro)
* `Paywalls`: implemented LoadingPaywallView with placeholder (#1284)
via NachoSoto (@NachoSoto)
* `Paywalls`: created LoadingPaywallView (#1282) via NachoSoto
(@NachoSoto)
* Fix template test data (#1308) via Cesar de la Vega (@vegaro)
</details>

### Other Changes
Add `purchases.setOnesignalUserID` (#1304) via Raquel Diez
(@Raquel10-RevenueCat)

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
@vegaro vegaro added pr:other and removed pr:test labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants