Skip to content

OfferingsManager: added ability to fail if any product is not found#1976

Merged
NachoSoto merged 1 commit into
mainfrom
offerings-manager-policy-2
Oct 11, 2022
Merged

OfferingsManager: added ability to fail if any product is not found#1976
NachoSoto merged 1 commit into
mainfrom
offerings-manager-policy-2

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Oct 10, 2022

Copy link
Copy Markdown
Contributor

The default behavior is unchanged: if any products aren't found, those are logged, but an Offerings value is returned with the found products.

This introduces a new OfferingsManager.FetchPolicy that allows receiving an error if any product is not found. For the time being, this is internal only, and will be used for CSDK-451, since we don't want to ignore those errors when using this new SDK tester.

@NachoSoto NachoSoto requested a review from a team October 10, 2022 20:45

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.

⚠️ This is improved, no longer referencing SKProduct 😅

@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.

Looks good! Just a couple of comments

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.

Do we need to return after this?

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.

No, not in this case. This is the existing behavior, which was to simply log and keep going with the products that are found.

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.

Hmm do we have plans to add other policies here? Just wondering whether it would be better to just make this a boolean instead of an enum.

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.

Even if we don't, this allows us to document the behavior in the name. As for performance, this has essentially the same representation as a boolean.
The advantage over a Bool is that we don't have to wonder in every place what true or false means, and that's much more error prone.

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.

Looks like we are not testing these new methods directly. This is called by the existing getOfferings method, so it's tested with a default fetch policy but since it's a public method, even if it's internal, I think we should add a quick test for this just in case.

Base automatically changed from offerings-manager-policy to main October 11, 2022 19:57
NachoSoto added a commit that referenced this pull request Oct 11, 2022
…1975)

We had no test coverage for [`OfferingsManager`'s ability to ignore
products that aren't
found](https://github.com/RevenueCat/purchases-ios/blob/4.13.1/Sources/Purchasing/OfferingsManager.swift#L134-L140).

Added this before expanding this behavior in #1976.
The default behavior is unchanged: if any products aren't found, those are logged, but an `Offerings` value is returned with the found products.

This introduces a new `OfferingsManager.FetchPolicy` that allows receiving an error if any product is not found. For the time being, this is `internal` only, and will be used for [CSDK-451], since we don't want to ignore those errors when using this new SDK tester.
@NachoSoto NachoSoto force-pushed the offerings-manager-policy-2 branch from bdfcec9 to b717efd Compare October 11, 2022 19:57
@NachoSoto NachoSoto merged commit 36dff60 into main Oct 11, 2022
@NachoSoto NachoSoto deleted the offerings-manager-policy-2 branch October 11, 2022 20:07
NachoSoto added a commit that referenced this pull request Oct 11, 2022
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 added a commit that referenced this pull request Oct 14, 2022
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 added a commit that referenced this pull request Oct 27, 2022
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 added a commit that referenced this pull request Oct 27, 2022
…errors (#1977)

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 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._

### Depends on:
- #1970
- #1971
- #1973
- #1974
- #1975
- #1976

[CSDK-451]:
https://revenuecats.atlassian.net/browse/CSDK-451?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants