Skip to content

Commit

Permalink
Added Integration Test for upgrading subscription with a different en…
Browse files Browse the repository at this point in the history
…titlement

See [CF-788].
  • Loading branch information
NachoSoto committed Sep 28, 2022
1 parent 3f76556 commit c61d815
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,41 @@ class StoreKit1IntegrationTests: BaseBackendIntegrationTests {
expect(transaction.offerType) == .promotional
}

func testUpgradingInSameSubscriptionGroupCancelsOldEntitlement() async throws {
let user = UUID().uuidString

let (_, created) = try await Purchases.shared.logIn(user)
expect(created) == true

let customerInfo = try await self.purchaseMonthlyOffering().customerInfo

let superPremiumProduct = try await XCTAsyncUnwrap(
await Purchases.shared.products([
"com.revenuecat.monthly_9.99.super_premium.1_week_intro"
]).first
)

let entitlements = try await Purchases.shared.purchase(product: superPremiumProduct)
.customerInfo
.entitlements

expect(entitlements.active).to(haveCount(1))
expect(entitlements[Self.entitlementIdentifier]?.isActive).to(
beFalse(),
description: "Old entitlement should not be active anymore"
)
expect(entitlements[Self.superEntitlementIdentifier]?.isActive).to(
beTrue(),
description: "New upgraded entitlement should be active"
)
}

}

private extension StoreKit1IntegrationTests {

static let entitlementIdentifier = "premium"
static let superEntitlementIdentifier = "super_premium"

private var currentOffering: Offering {
get async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,40 @@
"referenceName" : "weekly free trial",
"subscriptionGroupID" : "7096FF06",
"type" : "RecurringSubscription"
},
{
"adHocOffers" : [

],
"codeOffers" : [

],
"displayPrice" : "9.99",
"familyShareable" : true,
"groupNumber" : 1,
"internalID" : "42778756",
"introductoryOffer" : {
"internalID" : "AA450462",
"paymentMode" : "free",
"subscriptionPeriod" : "P1W"
},
"localizations" : [
{
"description" : "Monthly subscription with a 1-week free trial",
"displayName" : "Super Premium Monthly",
"locale" : "en_US"
},
{
"description" : "Subscripción mensual con 1 semana gratis",
"displayName" : "Super Premium mensual",
"locale" : "es_ES"
}
],
"productID" : "com.revenuecat.monthly_9.99.super_premium.1_week_intro",
"recurringSubscriptionPeriod" : "P1M",
"referenceName" : "super premium monthly free trial",
"subscriptionGroupID" : "7096FF06",
"type" : "RecurringSubscription"
}
]
},
Expand Down

0 comments on commit c61d815

Please sign in to comment.