From c61d815461b5262faf7bdf647ffa6c74a38f421f Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Sat, 25 Jun 2022 14:39:11 -0700 Subject: [PATCH] Added Integration Test for upgrading subscription with a different entitlement See [CF-788]. --- .../StoreKitIntegrationTests.swift | 30 ++++++++++++++++ ...rationPurchaseTesterConfiguration.storekit | 34 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift b/Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift index 66c47d2b2f..83a4290f35 100644 --- a/Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift +++ b/Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift @@ -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 { diff --git a/Tests/TestingApps/PurchaseTester/RevenueCat_IntegrationPurchaseTesterConfiguration.storekit b/Tests/TestingApps/PurchaseTester/RevenueCat_IntegrationPurchaseTesterConfiguration.storekit index da62d85564..084bf7fc02 100644 --- a/Tests/TestingApps/PurchaseTester/RevenueCat_IntegrationPurchaseTesterConfiguration.storekit +++ b/Tests/TestingApps/PurchaseTester/RevenueCat_IntegrationPurchaseTesterConfiguration.storekit @@ -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" } ] },