Skip to content

Introduced PurchasesDiagnostics to help diagnose SDK configuration errors#1977

Merged
NachoSoto merged 9 commits into
mainfrom
sdk-tester
Oct 27, 2022
Merged

Introduced PurchasesDiagnostics to help diagnose SDK configuration errors#1977
NachoSoto merged 9 commits into
mainfrom
sdk-tester

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Oct 10, 2022

Copy link
Copy Markdown
Contributor

Finishes CSDK-451.
This new small public API allows users to quickly figure out if everything in the SDK is correctly configured in a simple way:

let diagnostics = PurchasesDiagnostics.default
do {
    try await diagnostics.testSDKHealth()
} catch {
    print(error)
}

The specific underlying errors will provide information about what failed.

We can continue growing this to check for more specific things, but for now it does 4 things:

  • Verify API connectivity: networking issues, firewalling, etc.
  • Verify API key is correct
  • Verify Offerings are configured correctly
  • Verify that all products in Offerings are configured correctly and found in StoreKit

This new API is covered by:

  • API testers
  • Unit tests
  • Integration tests (both on SK1 and SK2)

I've taken the "shortcut" of making this async only (while still compatible with Objective-C), which means it's not compatible with iOS 12.x. But that made the implementation a lot simpler, which I think is a useful tradeoff.


This is a new API so I made sure it's documented with an example:

Screenshot 2022-10-10 at 14 38 28

Depends on:

@NachoSoto NachoSoto added the pr:feat A new feature label Oct 10, 2022
@NachoSoto NachoSoto requested a review from a team October 10, 2022 23:38
Comment thread Sources/Support/SDKTester.swift Outdated
Comment thread Sources/Purchasing/Purchases/PurchasesType.swift
Comment thread Sources/Purchasing/Purchases/Purchases.swift
Comment thread Tests/UnitTests/Misc/SDKTesterTests.swift
Comment thread Tests/UnitTests/Misc/SDKTesterTests.swift Outdated
@NachoSoto NachoSoto changed the base branch from main to internal-api October 14, 2022 18:44
@NachoSoto NachoSoto requested review from a team and vegaro October 14, 2022 18:47
@NachoSoto NachoSoto force-pushed the sdk-tester branch 2 times, most recently from e8e7f4c to 18fe0a2 Compare October 14, 2022 20:09
Comment thread Sources/Support/SDKTester.swift
@aboedo

aboedo commented Oct 17, 2022

Copy link
Copy Markdown
Member

We should be very, very explicit with our docs for this one. Perhaps @codykerns and / or the Support team can help us figure out a nice copy?
Similar thinking regarding the API: maybe we can call it something like testRevenueCatIntegration or something? Like, if it just says "test" it might IMO feel like something that's internal to the SDK, just meant for us to test it

@aboedo aboedo requested a review from codykerns October 17, 2022 20:09
Base automatically changed from internal-api to main October 20, 2022 18:03
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Similar thinking regarding the API: maybe we can call it something like testRevenueCatIntegration or something?

Oh yeah much better 👍🏻
I started with test as I was exploring and prototyping this and never went back to change the name 🤦🏻‍♂️

@codykerns any thoughts on the rest of the documentation in here?

Comment thread Sources/Support/SDKTester.swift 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 kind of think that naming this class more like a support or diagnostics tool, like RevenueCatDiagnostics or PurchasesDiagnostics as it more indicates symptoms of a potentially broken implementation. I think it would make it less ambiguous too, as the test terminology might be confusing/ pointing toward it being an internal thing rather than publicly accessible

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 like PurchasesDiagnostics 👍🏻

Comment thread Sources/Support/SDKTester.swift Outdated

@codykerns codykerns Oct 26, 2022

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.

Suggested change
public func testRevenueCatIntegration() async throws {
public func testBasicSDKHealth() async throws {

If we rename the class, I think it's implied that it's for RevenueCat. Let's call it something like this to give room for other potential 'tests' in the future

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 like PurchasesDiagnostics.testSDKHealth 👍🏻

Finishes [CSDK-451].
This new small public API allows users to quickly figure out if everything in the SDK is correctly configured in a simple way:
```swift
let tester = SDKTester.default
do {
  try await tester.test()
} catch {
  print(error)
}
```

The specific underlying errors will provide information about what failed.

We can continue growing this to check for more specific things, but for now it does 4 things:
- Verify API connectivity: networking issues, firewalling, etc.
- Verify API key is correct
- Verify `Offerings` are configured correctly
- Verify that all products in `Offerings` are configured correctly and found in `StoreKit`

This new API is covered by:
- API testers
- Unit tests
- Integration tests (both on `SK1` and `SK2`)

- #1970
- #1971
- #1973
- #1974
- #1975
- #1976
@NachoSoto NachoSoto changed the title Introduced SDKTester to help diagnose SDK configuration errors Introduced PurchasesDiagnostics to help diagnose SDK configuration errors Oct 27, 2022
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Updated to PurchasesDiagnostics.testSDKHealth which is much better, thanks @codykerns!

@NachoSoto

Copy link
Copy Markdown
Contributor Author

Idea from @aboedo: we can expand the error descriptions with more details to help developers fix each one.
For example:

API key is not valid. You can obtain the API key for your app at https://whatever.com/. If you’re getting this message while using a key from https://whatever.com/, make sure that you’re using the key specific to this platform (i.e.: you can’t use the Android key on Apple platforms). A correct API key for this platform will look something like appl_ligarsgiajsgeasg or oiajwgeoieagoesgea if you’re using a legacy API key.

@codykerns

Copy link
Copy Markdown
Member

@NachoSoto do you want me to write up the potential errors messages, etc? I think that's a great idea

@NachoSoto

Copy link
Copy Markdown
Contributor Author

@codykerns that would be nice! You can see the main 4 errors (including unknown).
We can also expand the convert method to handle more ErrorCodes and provide more specific messages.

@NachoSoto

Copy link
Copy Markdown
Contributor Author

We can leave that for a future PR if everyone is okay with merging this for now?

@NachoSoto NachoSoto merged commit faf51e3 into main Oct 27, 2022
@NachoSoto NachoSoto deleted the sdk-tester branch October 27, 2022 19:00
@RCGitBot RCGitBot mentioned this pull request Nov 3, 2022
NachoSoto pushed a commit that referenced this pull request Nov 4, 2022
### New Features
* Introduced `PurchasesDiagnostics` to help diagnose SDK configuration
errors (#1977) via NachoSoto (@NachoSoto)
### Bugfixes
* Avoid posting empty receipts by making`TransactionsManager` always use
`SK1` implementation (#2015) via NachoSoto (@NachoSoto)
* `NetworkOperation`: workaround for iOS 12 crashes (#2008) via
NachoSoto (@NachoSoto)
### Other Changes
* Makes hold job wait for installation tests to pass (#2017) via Cesar
de la Vega (@vegaro)
* Update fastlane-plugin-revenuecat_internal (#2016) via Cesar de la
Vega (@vegaro)
* `bug_report.md`: changed SK2 wording (#2010) via NachoSoto
(@NachoSoto)
* Added `Set + Set` and `Set += Set` operators (#2013) via NachoSoto
(@NachoSoto)
* fix the link to StoreKit Config file from watchOS purchaseTester
(#2009) via Andy Boedo (@aboedo)
* `PurchaseTesterSwiftUI`: combined targets into one multi-platform and
fixed `macOS` (#1996) via NachoSoto (@NachoSoto)
* Less Array() (#2005) via SabinaHuseinova (@SabinaHuseinova)
* Docs: fixed `logIn` references (#2002) via NachoSoto (@NachoSoto)
* CI: use `Xcode 14.1` (#1992) via NachoSoto (@NachoSoto)
* `PurchaseTesterSwiftUI`: fixed warnings and simplified code using
`async` methods (#1985) via NachoSoto (@NachoSoto)
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.

4 participants