Commit Graph
30 Commits
Author SHA1 Message Date
Will Taylor 6a363db8df make PurchaseParams & Win-Back APIs public 2024-11-19 13:18:21 -06:00
Mark VillacampaandToni Rico 72b06f6943 Introduce PurchaseParams to allow passing extra configuration info when making a purchase (#4400)
* Introduce PurchaseParams to allow passing extra configuration info when making a purchase

* simplify naming

* fallback to old method when flag is not enabled

* Add $(inherited) to the test targets so they pick up compiler flags from Local.xcconfig

* Include product/package inside PurchaseParams

* fix tests

* add compiler flag check

* update purchase tester

* fix docs

* add tests

* Update Sources/Networking/Operations/PostReceiptDataOperation.swift

Co-authored-by: Toni Rico <toni.rico.diez@revenuecat.com>

---------

Co-authored-by: Toni Rico <toni.rico.diez@revenuecat.com>
2024-11-06 16:05:37 +07:00
Toni Rico c23d61651a Bring back offline integration tests on M1 (#3976)
### Description
This was introduced in #3961 and reverted temporarily in #3974. This
brings the changes back.
2024-06-21 08:58:48 +02:00
Toni Rico b63332be0e Revert "Run offline backend integration tests on M1 machines (#3961)" (#3974)
### Description
This reverts #3961. This was causing some problems in our iOS 12 tests,
so we're leaving them out from this release:
https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/19858/workflows/c470dc5c-03a8-4893-badd-5ea9a961f1a2/jobs/223279
2024-06-19 19:57:24 +02:00
d8f172e6a6 Run offline backend integration tests on M1 machines (#3961)
### Description
This moves the offline backend integration tests to run on M1 machines
in CircleCI.

Since this causes tests to be much more flaky, this includes a
cherry-pick of the changes in the 5.0 branch that improves those:
https://github.com/RevenueCat/purchases-ios/pull/3902

---------

Co-authored-by: Josh Holtz <me@joshholtz.com>
Co-authored-by: Will Taylor <wtaylor151@gmail.com>
Co-authored-by: Andy Boedo <andresboedo@gmail.com>
2024-06-19 17:26:29 +02:00
Josh Holtz a98d86e32e Revert "Xcode 15.3: fix warnings on Integration Tests" (#3744)
Reverts RevenueCat/purchases-ios#3603

I _think_ this is causing a bunch of failures in SK2 tests
2024-03-05 05:30:49 -06:00
NachoSotoandMark Villacampa 0bb44cc41e Xcode 15.3: fix warnings on Integration Tests (#3603)
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>
2024-03-04 10:47:06 +01:00
NachoSoto 0aa950a99c Integration Tests: new logs for troubleshooting flaky tests (#3328)
This modifies `BaseStoreKitIntegrationTests.printReceipt` to also log
`StoreKit 2` transactions which can be used to debug failures of
`OfflineStoreKitIntegrationTests`.
`PurchasedProductsFetcher` also logs how many `currentEntitlements` it
found since failures are coming from there.
2023-10-24 09:41:25 -07:00
NachoSoto 18ad735fce Integration Tests: prevent false positives when purchasing returns 5xx (#3209)
Good news: offline entitlements are amazing, and our SDK is very
resilient to the backend being down.
Bad news: this is kind of a false positive, this behavior is already
verified by `OfflineStoreKitIntegrationTests`.

I refactored `BaseStoreKitIntegrationTests` because it had grown a lot.
I put this verification in the `purchase` methods so all tests benefit
from this.

So that `OfflineStoreKitIntegrationTests` don't fail, I added a
parameter to ignore that verification in those tests.
2023-09-18 14:23:40 -07:00
NachoSoto cc307399c3 Paywalls: added Purchases.track(paywallEvent:) (#3160)
This uses `PaywallEventsManager` (#3159) to track events, and saves the
presented `PaywallEvent` to be send along with
`PostReceiptDataOperation`.
2023-09-14 18:28:11 -07:00
NachoSotoandWill Taylor 1072870a41 SDK-2859: add integration tests for ghost transfer behavior
This is now fixed on the backend. These new tests reflect the new
expected behavior.

---------

Co-authored-by: Will Taylor <wtaylor151@gmail.com>
2023-09-13 09:48:40 -05:00
NachoSoto 5d3263c8e6 TransactionPoster: don't finish transactions for non-subscriptions if they're not processed (#2841) 2023-08-15 07:05:00 -07:00
NachoSoto a31743aaea Integration Tests: added tests for non-renewing and non-consumable packages (#3008)
There were some questions about these in #2841, and realized we had no
test coverage for them.
This also improves the documentation of `CustomerInfo.nonSubscriptions`
and `NonSubscriptionTransaction`.
2023-08-14 15:09:32 -07:00
NachoSoto 216f1e13c3 PurchasesOrchestrator: disambiguate transactions from the queue (#2890)
This adds tests and a fix for a scenario discovered by @aboedo and
@mcastany.

### Timeline:
- Make a purchase of product_1
- Close app
- Renewals happen in the background
- Subscription expires
- Open app, renewals are in the queue but not processed yet
- Start a purchase of `product_1` (`SKPaymentQueue.add`)
- StoreKit queue shows renewal from step 3 as finished, it's expired
- SDK sees finished transaction in the queue for `product_1`
- SDK sees completion block for `product_1`, considers it a successful
`.purchase`
- SDK posts receipt, `initiation_source: .purchase` 💥
- Backend replies with 422 because StoreKit hasn't processed the
transaction from 6

### Fix:
The fix looks at the date when the completion block was added (the time
`.purchase()` is called).
If the transaction was created _before_ this, we know it didn't come
from the actual purchase, and therefore it should be identified as
`.queue`.
2023-08-07 15:57:10 -07:00
NachoSoto 8ac59d0478 Integration Tests: added more observer mode tests (#2905)
This extracts the purchasing code into a new `ExternalPurchasesManager`
and `ObserverModeManager`, which can be used to perform purchases
without using the SDK.

I've also bumped the deployment target of integration tests to 15.0 to
simplify the code.
2023-08-07 22:42:11 +00:00
NachoSoto e182a6ad53 IntegrationTests: replaced Purchases.shared with a throwing property (#2867)
This is a similar change to #2532.

I noticed yet another source of crashes in our integration tests.
This is what [the
result](https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/13247/workflows/52fd2014-7a19-442f-a572-64116393abec/jobs/94728)
was:
```
failed - Message 'Finishing transaction' should not have been logged
expected to not find object in collection that satisfies predicate
```

That came from this code:
```swift
self.logger.verifyMessageWasNotLogged("Finishing transaction")

let info1 = try await Purchases.shared.customerInfo()
```

After that assertion failure, `XCTest` continued execution, while it had
already tear down `Purchases`, which lead to this crash:
```
Thread 0 Crashed:
0   libswiftCore.dylib            	       0x103b84e81 _assertionFailure(_:_:file:line:flags:) + 353
1   RevenueCat                    	       0x1332516d0 static Purchases.shared.getter + 352 (Purchases.swift:65)
2   BackendIntegrationTests       	       0x130f7048a OfflineStoreKit1IntegrationTests.testPurchaseWhileServerIsDownPostsReceiptWhenForegroundingApp() + 362 (OfflineStoreKitIntegrationTests.swift:289)
3   BackendIntegrationTests       	       0x130f75ee1 @objc closure #1 in OfflineStoreKit1IntegrationTests.testPurchaseWhileServerIsDownPostsReceiptWhenForegroundingApp() + 1
4   BackendIntegrationTests       	       0x130f77d91 partial apply for @objc closure #1 in OfflineStoreKit1IntegrationTests.testPurchaseWhileServerIsDownPostsReceiptWhenForegroundingApp() + 1
```

To prevent this, instead of using `Purchases.shared` this replaces that
with a throwing `self.purchases`.
Just like we don't use force-unwraps in tests and instead use
`XCTUwnrap`, this now will fail the test instead of crashing it.
2023-07-24 13:20:00 +02:00
NachoSoto 557b25e281 TestLogHandler: changed all tests to explicitly deinitialize it (#2784) 2023-07-12 06:34:12 -07:00
NachoSoto 0cfec83e1f Integration Tests: refactored expiration detection (#2700)
This extracts a common `verifySubscriptionExpired`.
If we want to change the approach to detecting this, we can modify a
single method.
2023-07-05 17:15:14 -07:00
NachoSoto 8f48922ff7 Integration Tests: avoid crashes when stopping tests early (#2741)
If tests are skipped or failed early, before the `SKTestSession` is
initialized, this will crash instead of failing or being skipped.
2023-06-30 09:03:18 -07:00
NachoSoto 7f875ae212 Changed Logger to use os_log (#2608) 2023-06-15 15:13:48 -07:00
NachoSoto 7cfbfe04c9 StoreKitObserverModeIntegrationTests: added test for posting renewals (#2590)
Follow up to #2589.
Depends on #2612.
2023-06-14 13:18:23 -07:00
NachoSoto 2a95520b98 StoreKitConfigTestCase/BaseStoreKitIntegrationTests: also clear transactions after every test (#2616)
Trying to work around `FB11799675`, this was suggested by @joshdholtz
and it seems to be working really well. This now calls
`deleteAllTransactions` and `SKTestSession.clearTransactions` _after_
every test, not only before.

The problem is that `clearTransactions` only seems to delete stuff from
`SKTestSession.allTransactions`, but not from
`StoreKit.Transaction.unfinished`. Doing this at the end of every test
seems to do a much better job at ensuring that each test invocation has
no leftover transaction, hopefully leading to fewer flaky failures.
2023-06-12 08:52:09 -07:00
NachoSoto db17623197 Improved finishAllUnfinishedTransactions (#2615) 2023-06-12 07:07:13 -07:00
NachoSoto 2cf1851625 Custom Entitlements Computation: added Integration Tests (#2568)
Fixes SDK-3158.

### Changes:
- Added new `BackendCustomEntitlementsIntegrationTests` target that
depends on the `RevenueCat_CustomEntitlementComputation` SPM
- Updated `BaseBackendIntegrationTests` and
`BaseStoreKitIntegrationTests` to support
`RevenueCat_CustomEntitlementComputation`
- Added `CustomEntitlementsComputationIntegrationTests` with custom
`Purchases.configureInCustomEntitlementsComputationMode` initialization
- Added integration tests for basic operations
- Verify that none of those integration tests ever use
`GetCustomerInfoOperation`
- Added `testGetCustomerInfo` to `OtherIntegrationTests` (we didn't have
an explicit test for this)

### TODO:
- [x] Verify v3 integration tests
- [x] Verify SPM commit is updated when running tests
2023-06-02 11:25:06 -07:00
NachoSoto 242c4028c4 Integration Tests: avoid crashes when printing receipt (#2570)
Fixes
https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/11501/workflows/b978f26f-ce2d-4040-ac40-96e121c4407f/jobs/72997/steps

Same as #2532, this prevents test crashes when this function is called
after `Purchases` has been reset.
Test crashes are inconvenient because it makes the entire test run fail,
instead of allowing retries.
2023-06-01 07:52:18 -07:00
NachoSoto e43a8de771 Integration Tests: workaround for XCTest crash after a test failure (#2532)
See https://app.circleci.com/jobs/github/RevenueCat/purchases-ios/69881

Assertion failures in that method were leading to _crashes_ in
`Purchases.shared`, instead of a simple test failure that could be
retried:

![image](https://github.com/RevenueCat/purchases-ios/assets/685609/c86e17a8-a0f4-4b97-a4b8-ee1537d6378e)

For some reason, `XCTest` is continuing execution after an assertion
failure in an `async` method, despite having `self.continueAfterFailure
= false`.
This might even be a Swift mis-compilation. This PR is a workaround:
instead of relying on `XCTest` stopping execution of the test, we
instead throw an `Error` to force that at compile time.

Note that this still produces nice errors when an assertion fails inside
of `verifyEntitlementWentThrough`:
![Screenshot 2023-05-23 at 13 27
55](https://github.com/RevenueCat/purchases-ios/assets/685609/5a6aa599-235e-41c8-9d85-930e55ace1b1)
2023-05-24 09:51:23 -07:00
NachoSoto f4e79bb283 Integration Tests: removed @preconcurrency import (#2464) 2023-05-03 07:27:36 -07:00
NachoSoto 3085cce7a9 SubscriberAttributesManagerIntegrationTests: fixed flaky failures (#2381)
Turns out we had already solved this race condition in #1492 that lead
to flaky failures,
but it was only in `BaseStoreKitIntegrationTests`. This moves it up to
`BaseBackendIntegrationTests` so that
`SubscriberAttributesManagerIntegrationTests` can use it too.

Fixes
https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/10501/workflows/cb6dbf22-cda8-4c41-875b-04b489992631/jobs/61135
2023-03-27 18:29:18 -03:00
NachoSoto fdd7874deb IntroEligibilityCalculator: fixed logic for subscriptions in same group (#2174)
- Fixes  [TRIAGE-221] for `SK1`.
- Filed `FB11889732` for `SK2`.

### Changes:
- Added 2 `IntroEligibilityCalculatorTests` unit tests to cover this
scenario
- Added 1 `IntroEligibilityCalculatorTests` unit tests to cover the
equivalent of the `testIneligibleForIntroAfterPurchaseExpires`
integration test
- Added 2 `StoreKitIntegrationTests` to cover this scenario (one of them
disabled in SK2)
- Updated `IntroEligibilityCalculator` logic to fix the new tests.
- Refactored `IntroEligibilityCalculatorTests` to avoid duplication and
allow adding new cases more easily.
- Added a few more tests to ensure other cases are correct.

[TRIAGE-221]:
https://revenuecats.atlassian.net/browse/TRIAGE-221?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2023-01-25 08:40:35 -08:00
NachoSoto 662940100f Integration Tests: split up tests in smaller files (#2158)
With #2069 this file grew up a bit too much.

This splits up `BaseStoreKitIntegrationTests` and
`StoreKitObserverModeIntegrationTests` to make them more maintainable.
2022-12-21 07:35:38 -08:00