Follow up to #3599 and #3600.
These `@MainActor` annotations don't work anymore because of this:
> Main actor-isolated class '...' has different actor isolation from
nonisolated superclass 'TestCase'; this is an error in Swift 6
They were necessary with an older version of Xcode (likely 13.x), but
not anymore.
---------
Co-authored-by: Mark Villacampa <m@markvillacampa.com>
This is a follow up to #717.
In order to be able to reproduce #2338, which seems to be an issue only
on `watchOS`, it's important that we now run tests on `watchOS` as well.
We probably won't be able to fully replicate that issue since we don't
run tests on actual devices, so they'll still run on 64 bits. But this
way we might be able to prevent issues that are only reproducible on
`watchOS` in the future.
## Changes:
- Added CircleCI job
- Added lane
- Simplified `UnitTestsHostApp` definition using `SwiftUI`
- Increased _test only_ `watchOS` deployment target to 7.0 (this was
necessary to be able to have a common `@main` for the host app)
- Increased _test only_ `tvOS` deployment target to `14.0` (same as
above, plus we only run tvOS tests on the latest version anyway. We test
backwards compatibility through iOS already)
- Fixed test compilation on `watchOS`
- Disabled `HTTPClient` tests on `watchOS` (see
https://github.com/AliSoftware/OHHTTPStubs/issues/287)
- `StoreKitConfigTestCase` is only available from `watchOS 7.0` since
that's when `SKTestSession` was introduced
- Added `watchOS` support to `UnitTests` target
- Added `watchOS` support to `ReceiptParserTests` target
- Fixed `isFamilySharable` `watchOS` version checks for version 8.0
- Created new `CI-RevenueCat` Test Plan to only run unit tests and not
StoreKit tests on `watchOS`
The entire target had a deployment target of iOS 14.0 because
`SKTestSession` requires it. However, not all tests in that target use
`StoreKitConfigTestCase`, and those weren't running before iOS 14.0.
To fix this, I've removed the deployment target overrides from all
targets (expect for integration tests, those have a higher one for
simplicity), and instead defined them only once at the *project level*,
so all targets inherit that automatically.
`StoreKitConfigTestCase` will skip the test automatically if the iOS is
below 14.0, but the other tests will now run on iOS 12 and 13.
Simplifies the common pattern in tests:
```swift
expect(array).to(haveCount(1))
let element = try XCTUnwrap(array.first)
```
Into simply:
```swift
let element = try XCTUnwrap(array.onlyElement)
```
I often get failures when running all tests in parallel because this test takes more than 1 second to run.
Example:
> failed - expected to be close to <2022-05-24 10:59:18.3370> (within 1), got <2022-05-24 10:58:18.0000>
To allow the test to take a few more seconds, I think this is a reasonable compromise.
This adds a third case `disabled` that allows tests to explicitly disable StoreKit 2.
Some types, like `TrialOrIntroPriceEligibilityChecker` and `TransactionsManager` always used SK2 because the implementation was better. But this meant that tests couldn't explicitly disable it (other than calling the internal methods directly).
This allows #1464 to be a lot simpler but being able to use the public `Purchases` methods, but forcing the implementation to use SK1.
Note that this is purely an implementation detail. `StoreKit2Setting` is `internal`, and the public API still only exposes the same boolean.
This basically solves [CF-497] too, since those tests will now force `TrialOrIntroPriceEligibilityChecker` to run the SK1 implementation.
[CF-497]: https://revenuecats.atlassian.net/browse/CF-497?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
* made a few attributes that aren't present in SKTest receipts optional, added test with IAP
* added more tests for every field in the receipt
* fixed a few places where `asDict` wasn't correctly considering nullability in the IAP receipt fields
* added basic ugly test
* fixed local receipt parsing for sktest, broke regular receipt parsing temporarily
* updated length calculation so that it works for both storekit test and regular receipts
* updated test to allow for missing OriginalAppVersion in receipt
* fixed linting in imports
* fixed checks for non-storekitTest receipts
* added a longer comment to explain the length == 0 case
* cleaned up the still-ugly tests for the receipt parser