Refactor offerings code out of Purchases#1027
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1027 +/- ##
==========================================
- Coverage 85.60% 85.52% -0.08%
==========================================
Files 170 172 +2
Lines 6042 6066 +24
Branches 842 845 +3
==========================================
+ Hits 5172 5188 +16
- Misses 540 545 +5
- Partials 330 333 +3
|
| @@ -1,7 +1,6 @@ | |||
| package com.revenuecat.purchases.google | |||
| package com.revenuecat.purchases.common | |||
There was a problem hiding this comment.
While this class is for Google and ideally it should live in the feature/google module, that made it significantly harder to keep the new classes in the common module. I could have moved them to purchases, but I kinda want to keep as much code as possible in common.
Without this, I would have had to mock the offerings parser in the common module tests, and it felt those test should use the real implementation (as they were doing until now)
|
|
||
| // region Private Methods | ||
|
|
||
| private fun fetchAndCacheOfferings( |
There was a problem hiding this comment.
It felt good removing all this from Purchases
| // region offerings | ||
|
|
||
| @Test | ||
| fun `fetch offerings on foregrounded if it's stale`() { |
There was a problem hiding this comment.
So much better removing code from here 👍🏻
This file is still 4100 lines. We could do the same I did in iOS:
- Split
PurchasesTestsstep 1: extractedBasePurchasesTestspurchases-ios#1609 - Split
PurchasesTestsstep 2: extractedPurchasesConfiguringTestsandPurchasesGetCustomerInfoTestspurchases-ios#1610 - Split
PurchasesTestsstep 3: extractedPurchasesPurchasingTestspurchases-ios#1611 - Split
PurchasesTestsstep 4: extractedPurchasesRestoreTestspurchases-ios#1612 - Split
PurchasesTestsstep 5: extractedPurchasesGetOfferingsTestspurchases-ios#1613 - Split
PurchasesTestsstep 6: extractedPurchasesSyncPurchasesTestspurchases-ios#1628 - Split
PurchasesTestsstep 7: extractedPurchasesDeferredPurchasesTestspurchases-ios#1629 - Split
PurchasesTestsstep 8: extractedPurchasesAttributionDataTestspurchases-ios#1630 - Split
PurchasesTestsstep 9: moved more tests purchases-ios#1632 - Split
PurchasesTestsstep 10: extractedPurchasesGetProductsTestspurchases-ios#1633 - Split
PurchasesTestsstep 11: extractedPurchasesTransactionHandlingTestspurchases-ios#1637 - Split
PurchasesTestsstep 12: moved more tests toPurchasesDeferredPurchasesTestspurchases-ios#1638 - Split
PurchasesTestsstep 13: extractedPurchasesDelegateTestspurchases-ios#1639
There was a problem hiding this comment.
A lot of that code in iOS is no longer in Purchases, but we have a lot of tests since this is the facade so it's useful to test from top to bottom.
There was a problem hiding this comment.
Yeah, we definitely need to improve these tests situation. We already have a first step with #1011 (Thanks @vegaro!).
As for keeping tests at the Purchases level, I think that makes sense to test the main flows and main things we should be careful of. I guess that would be pretty close to integration tests, since at that point we probably only want to mock shared preferences/backend... I think that would be a separate test suite since they might be slightly harder to write, but we can discuss it further.
Also, thanks for sharing those! It can definitely serve as inspiration
| // region offerings | ||
|
|
||
| @Test | ||
| fun `fetch offerings on foregrounded if it's stale`() { |
There was a problem hiding this comment.
A lot of that code in iOS is no longer in Purchases, but we have a lot of tests since this is the facade so it's useful to test from top to bottom.
| import org.json.JSONException | ||
| import org.json.JSONObject | ||
|
|
||
| class OfferingsFactory( |
There was a problem hiding this comment.
Nice 👍🏻 From 1 class to 3.
**This is an automatic release.** ### New Features * Offline entitlements support (#1030) via Toni Rico (@tonidero) ### Bugfixes * Fix billing connection error when querying purchases early in the process lifetime (#1032) via Toni Rico (@tonidero) ### Performance Improvements * Perform product entitlement mapping request after more critical requests (#1017) via Toni Rico (@tonidero) ### Dependency Updates * Bump fastlane from 2.212.2 to 2.213.0 (#1024) via dependabot[bot] (@dependabot[bot]) ### Other Changes * Get offerings response from disk cache if available (#1029) via Toni Rico (@tonidero) * Improve offline entitlements logs to mention limitations of this mode (#1039) via Toni Rico (@tonidero) * Improve error message when backend returns internal error code (#1038) via Toni Rico (@tonidero) * PurchaseTester: Add new UI to configure internal proxy behavior (#1016) via Toni Rico (@tonidero) * Updated readme to include links to migration guides (#1021) via Marcos Castany (@mcastany) * Store offerings response in SharedPreferences (#1028) via Toni Rico (@tonidero) * Refactor offerings code out of Purchases (#1027) via Toni Rico (@tonidero) --------- Co-authored-by: revenuecat-ops <ops@revenuecat.com> Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
Description
This is a first PR in preparation of persisting offerings in cache (SDK-3094). There are no behavior changes in this PR. This just extracts most of the code related to offerings from
Purchasesto the new classesOfferingsManagerandOfferingsFactory.Main changes
OfferingsManagerthat will be the entry point for all offerings-related logicOfferingsFactorythat allows to create theOfferingsobject from a JSON response. It will query the store to get the necessary products and create the final object.GoogleOfferingParserfrom thefeature/googlemodule to thecommonmodule. This is to be able to use the actual code in the unit tests more easily.