Commit Graph
20 Commits
Author SHA1 Message Date
NachoSoto 2bcd0ce328 5.0.0 changes: support SK2 by default 2024-07-01 14:37:21 -05: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
32c63cdb46 [SK2] Add support for StoreKit Config files in SK2 (#3365)
When using StoreKit Config file, we do not have access to the
transaction history or subscription status server-side.

To work around this, we introduce a new `StoreKit2Receipt` type that
closely resembles the structure of an SK1 receipt and contains all the
transaction history and subscription status for the customer. It can be
sent in a single request to `/receipt`

---------

Co-authored-by: RevenueCat Git Bot <72824662+RCGitBot@users.noreply.github.com>
Co-authored-by: Distiller <distiller@static.38.39.183.137.cyberlynk.net>
Co-authored-by: Distiller <distiller@static.38.23.40.89.cyberlynk.net>
Co-authored-by: Distiller <distiller@static.38.39.185.65.cyberlynk.net>
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
2023-12-13 17:00:37 +01: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 1350189e90 StoreKit 2: only listen to StoreKit.Transaction.updates when SK2 is enabled (#3032) 2023-08-16 16:04:42 -07:00
NachoSoto 581a048308 CustomerInfoManager: post transactions in parallel to POST receipts only once (#2954)
The existing implementation was posting them in sequence, which meant
that it was always going to make N requests.
With this new implementation we can ensure that only one request is made
for all transactions.
2023-08-11 15:39:44 -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 9add1c9cb8 Tests: added missing super.setUp() (#2804) 2023-07-13 05:31:21 -07:00
NachoSoto 557b25e281 TestLogHandler: changed all tests to explicitly deinitialize it (#2784) 2023-07-12 06:34:12 -07:00
NachoSoto a1481e6ca5 PurchasesOrchestrator: update CustomerInfoManager cache after processing transactions (#2676)
This is the last piece needed after #2612. Transactions handled from
`StoreKit.Transaction.updates` were ignoring the result `CustomerInfo`.
On example where this was noticed is when redeeming promo codes: we
posted the transaction, but `PurchasesDelegate` was not notified of the
change.
2023-06-20 15:28:21 -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 6d532550f0 IntegrationTests: explicit StoreKit 1 mode (#2636)
I noticed that `BaseBackendIntegrationTests` sets the `StoreKit2Setting`
to `.default`, but in these `StoreKit 1` tests we weren't overriding
that setting.

When the default changes to `StoreKit 2`, this would have unknowingly
changed and we'd have stopped testing `StoreKit 1`.
2023-06-13 11:17:00 -07:00
NachoSoto 4b1426007d StoreKitObserverModeIntegrationTests: fixed and disabled SK2 testPurchaseInDevicePostsReceipt (#2589)
Turns out this test was only passing because it was waiting for the
receipt to be posted during a renewal, not the initial purchase!
This updates the test to reflect the correct expectation (disabling
renewals), and added the `XCTExpectFailure` so we can detect if it
starts passing in a future iOS version.

Also changed the test to not use `customerInfo()` because of #2563.
2023-06-06 15:15:38 -07:00
NachoSoto e9e6d887c2 Offline Entitlements: integration tests (#2501)
## Example tests:
```swift
func testOfferingsAreCachedInMemory() async throws {
    let onlineOfferings = try await Purchases.shared.offerings()
    expect(onlineOfferings.all).toNot(beEmpty())

    self.serverDown()

    let offlineOfferings = try await Purchases.shared.offerings()
    expect(offlineOfferings) === onlineOfferings
}

func testOfferingsAreCachedOnDisk() async throws {
    let onlineOfferings = try await Purchases.shared.offerings()
    expect(onlineOfferings.all).toNot(beEmpty())

    self.serverDown()
    await self.resetPurchases()

    let offlineOfferings = try await Purchases.shared.offerings()
    expect(offlineOfferings.response) == onlineOfferings.response

    let offering = try XCTUnwrap(offlineOfferings.current)
    expect(offering.availablePackages.count) == onlineOfferings.current?.availablePackages.count
    expect(offering.monthly?.storeProduct.productIdentifier) == "com.revenuecat.monthly_4.99.1_week_intro"
}
```
2023-05-19 10:54:42 -07: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