Skip to content

Commit

Permalink
Integration Tests: simplified `testIneligibleForIntroAfterPurchaseE…
Browse files Browse the repository at this point in the history
…xpires` to fix flakiness (#1952)

Fixes [CSDK-479].

### Changes:
- Removed extra `verifyEntitlementWentThrough`. #1880 introduced a
change so that weekly subscriptions aren't verified, because they expire
within a second. This make the test flaky due to that race condition.
- Removed `assertNoActiveSubscription`: I tried calling
`SKTestSession.disableAutoRenewForTransaction`, but sometimes the server
still thinks the subscription has auto-renewed. This was making the test
flaky. Turns out that even if it's not active, the eligibility test
still passes as expected.
- Removed call to `syncPurchases`. It doesn't matter what state the
server is in, as long as locally `SKTestSession` has an expired
subscription.

This, together with #1945, should fix the last of the issues causing
flaky integration tests 🤞🏻

[CSDK-479]:
https://revenuecats.atlassian.net/browse/CSDK-479?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
NachoSoto authored Sep 29, 2022
1 parent cc81b3f commit b31399d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,14 @@ class StoreKit1IntegrationTests: BaseBackendIntegrationTests {
func testIneligibleForIntroAfterPurchaseExpires() async throws {
let product = try await self.weeklyPackage.storeProduct

// 1. Purchase weekly offering
let customerInfo = try await self.purchaseWeeklyOffering().customerInfo
let entitlement = try await self.verifyEntitlementWentThrough(customerInfo)

// 2. Expire subscription
let entitlement = try XCTUnwrap(customerInfo.entitlements[Self.entitlementIdentifier])
try await self.expireSubscription(entitlement)

let info = try await Purchases.shared.syncPurchases()

self.assertNoActiveSubscription(info)

// 3. Check eligibility
let eligibility = await Purchases.shared.checkTrialOrIntroDiscountEligibility(product: product)
expect(eligibility) == .ineligible
}
Expand Down

0 comments on commit b31399d

Please sign in to comment.