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

New TestStoreProduct for creating mock StoreProducts and Offerings #2711

Conversation

NachoSoto
Copy link
Contributor

Fixes #1563 and #2193.

This introduces DEBUG and Swift only types that allow creating a whole Offering for tests and SwiftUI previews.

Example:
Screenshot 2023-06-26 at 12 36 40

By making it available in only DEBUG builds we ensure that apps can't accidentally try to purchase these products, which would be impossible. If this is attempted in DEBUG builds, we return ErrorCode.

When trying to compile this API in release builds, you get an error with a suggestion:
image

@NachoSoto NachoSoto added the pr:feat A new feature label Jun 26, 2023
@NachoSoto NachoSoto force-pushed the nacho/sdk-3198-proposal-ability-to-mock-storeproduct-and-offerings branch from be432d1 to 63ef66e Compare June 26, 2023 19:45
NachoSoto added a commit that referenced this pull request Jun 26, 2023
@NachoSoto NachoSoto force-pushed the nacho/sdk-3198-proposal-ability-to-mock-storeproduct-and-offerings branch from 092c19d to 3c606bf Compare June 26, 2023 19:48
@NachoSoto NachoSoto force-pushed the nacho/sdk-3198-proposal-ability-to-mock-storeproduct-and-offerings branch 2 times, most recently from 734d723 to 781c5bf Compare June 26, 2023 20:22
@NachoSoto NachoSoto force-pushed the nacho/sdk-3198-proposal-ability-to-mock-storeproduct-and-offerings branch from 781c5bf to d7e50c2 Compare June 26, 2023 20:24
@NachoSoto NachoSoto force-pushed the nacho/sdk-3198-proposal-ability-to-mock-storeproduct-and-offerings branch from d7e50c2 to 750aaaa Compare June 26, 2023 23:46
@codecov
Copy link

codecov bot commented Jun 27, 2023

Codecov Report

Merging #2711 (750aaaa) into main (4a154fc) will increase coverage by 0.04%.
The diff coverage is 73.61%.

❗ Current head 750aaaa differs from pull request most recent head 9f51e8a. Consider uploading reports for the commit 9f51e8a to get more accurate results

@@            Coverage Diff             @@
##             main    #2711      +/-   ##
==========================================
+ Coverage   86.46%   86.51%   +0.04%     
==========================================
  Files         212      213       +1     
  Lines       15055    15101      +46     
==========================================
+ Hits        13018    13064      +46     
  Misses       2037     2037              
Impacted Files Coverage Δ
Sources/Misc/PriceFormatterProvider.swift 100.00% <ø> (ø)
.../Purchasing/StoreKitAbstractions/ProductType.swift 85.71% <ø> (ø)
...tractions/Test Data/TestStoreProductDiscount.swift 0.00% <0.00%> (ø)
Sources/Purchasing/Offering.swift 92.30% <100.00%> (ø)
Sources/Purchasing/Package.swift 40.90% <100.00%> (+2.81%) ⬆️
...s/Purchasing/Purchases/PurchasesOrchestrator.swift 87.48% <100.00%> (+1.24%) ⬆️
...Purchasing/StoreKitAbstractions/StoreProduct.swift 75.32% <100.00%> (+2.46%) ⬆️
...reKitAbstractions/Test Data/TestStoreProduct.swift 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

NachoSoto added a commit that referenced this pull request Jun 27, 2023
@NachoSoto NachoSoto force-pushed the nacho/sdk-3198-proposal-ability-to-mock-storeproduct-and-offerings branch from 750aaaa to 66fe37d Compare June 27, 2023 14:32
Copy link
Member

@aboedo aboedo left a comment

Choose a reason for hiding this comment

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

love it! Tagging @tonidero since it's related to some of the stuff we were talking about for android

Comment on lines +292 to +293
} else if product.isTestProduct {
self.handleTestProduct(completion)
Copy link
Member

Choose a reason for hiding this comment

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

we really aren't making Liskov very happy with this, but it should be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I understand your point, that also applies to how we handle SK1 and SK2 products above, right?

Fixes #1563 and #2193.

This introduces **`DEBUG` and `Swift` only** types that allow creating a whole `Offering` for tests and SwiftUI previews.

Example:
![Screenshot 2023-06-26 at 12 36 40](https://github.com/RevenueCat/purchases-ios/assets/685609/03d83e65-b95b-40ba-80ad-f8be435c6d3e)

By making it available in only `DEBUG` builds we ensure that apps can't accidentally try to purchase these products, which would be impossible. If this is attempted in `DEBUG` builds, we return `ErrorCode`.

When trying to compile this API in release builds, you get an error with a suggestion:
![image](https://github.com/RevenueCat/purchases-ios/assets/685609/f83b8848-dab6-4ae6-a92d-5c07a30be217)
@NachoSoto NachoSoto force-pushed the nacho/sdk-3198-proposal-ability-to-mock-storeproduct-and-offerings branch from 66fe37d to 272f3ee Compare June 29, 2023 20:11
@NachoSoto NachoSoto enabled auto-merge (squash) June 29, 2023 20:11
@NachoSoto NachoSoto merged commit 761ca12 into main Jun 29, 2023
@NachoSoto NachoSoto deleted the nacho/sdk-3198-proposal-ability-to-mock-storeproduct-and-offerings branch June 29, 2023 21:06
NachoSoto added a commit that referenced this pull request Jun 30, 2023
**This is an automatic release.**

### New Features
* New `TestStoreProduct` for creating mock `StoreProduct`s and
`Offering`s (#2711) via NachoSoto (@NachoSoto)

✨ With this new API you can now create fake products for unit tests and
SwiftUI previews! 🎉
#### Example:
```swift
let product = TestStoreProduct(
    localizedTitle: "PRO monthly",
    price: 3.99,
    localizedPriceString: "$3.99",
    productIdentifier: "com.revenuecat.product",
    productType: .autoRenewableSubscription,
    localizedDescription: "Description",
    subscriptionGroupIdentifier: "group",
    subscriptionPeriod: .init(value: 1, unit: .month)
)
let offering = Offering(
    identifier: "offering",
    serverDescription: "Main offering",
    metadata: [:],
    availablePackages: [
        .init(
            identifier: "monthly",
            packageType: .monthly,
            storeProduct: product.toStoreProduct(),
            offeringIdentifier: offering
        )
    ]
)
```

### Dependency Updates
* Bump fastlane-plugin-revenuecat_internal from `13773d2` to `b2108fb`
(#2706) via dependabot[bot] (@dependabot[bot])
### Other Changes
* `VerificationResult: CustomDebugStringConvertible` (#2739) via
NachoSoto (@NachoSoto)
* Refactor: simplified `PurchasesOrchestrator.syncPurchases` (#2731) via
NachoSoto (@NachoSoto)
* `Trusted Entitlements`: add integration tests to verify `CustomerInfo`
cache invalidation (#2730) via NachoSoto (@NachoSoto)
* `SystemInfo.identifierForVendor`: add tests (#2732) via NachoSoto
(@NachoSoto)
* `Tests`: disabled `iOS 11.x` tests to fix `Xcode 15` tests (#2720) via
NachoSoto (@NachoSoto)
* `DebugViewSwiftUITests`: create separate snapshots for each OS version
(#2721) via NachoSoto (@NachoSoto)
* `Integration Tests`: fix clearing `UserDefaults` before each test
(#2719) via NachoSoto (@NachoSoto)
* Remove unused `Signing.loadPublicKey(with:)` (#2714) via NachoSoto
(@NachoSoto)
* Add `UInt32(littleEndian32Bits:)` and `UInt32.littleEndianData`
(#2713) via NachoSoto (@NachoSoto)
* `TimingUtil`: added synchronous API (#2716) via NachoSoto (@NachoSoto)
* `XCFramework`: sign archive for `Xcode 15` (#2709) via NachoSoto
(@NachoSoto)
* `CI`: removed `carthage_archive` from `release` lane (#2710) via
NachoSoto (@NachoSoto)
* `PriceFormatterProvider.priceFormatterForSK2`: enable on all versions
(#2712) via NachoSoto (@NachoSoto)
* `xrOS`: add support for `debugRevenueCatOverlay` (#2702) via NachoSoto
(@NachoSoto)
* Refactor method to get product ID including plan ID in android
purchases (#2708) via Toni Rico (@tonidero)
* `Purchases.restoreLogHandler` (#2699) via NachoSoto (@NachoSoto)
* Remove alpha from purchase tester icon to upload to testflight (#2705)
via Toni Rico (@tonidero)

---------

Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
NachoSoto added a commit that referenced this pull request Jul 23, 2023
See #2711. This is needed for #2855. In order to be able to create test products for the paywall loading screen, we need to be able to do this in release builds as well.
Another benefit of exposing `TestStoreProduct` in release builds is that it's also usable for pre-built versions of the SDK (like Carthage).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:feat A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Public init() for Package and Offerings
2 participants