From 4ac524eb011c780f376e9f6604b57ea59b6c9c86 Mon Sep 17 00:00:00 2001 From: Davide Date: Mon, 11 Nov 2024 20:10:27 +0100 Subject: [PATCH] Exclude interactive login from v2 (#852) --- .../CommonLibrary/IAP/AppFeature.swift | 11 ++- .../IAP/AppFeatureProviding.swift | 12 ++-- .../CommonLibrary/IAP/AppUserLevel.swift | 6 +- .../CommonLibraryTests/IAPManagerTests.swift | 72 +++++++++++-------- 4 files changed, 61 insertions(+), 40 deletions(-) diff --git a/Passepartout/Library/Sources/CommonLibrary/IAP/AppFeature.swift b/Passepartout/Library/Sources/CommonLibrary/IAP/AppFeature.swift index cd831e08..8b1a4508 100644 --- a/Passepartout/Library/Sources/CommonLibrary/IAP/AppFeature.swift +++ b/Passepartout/Library/Sources/CommonLibrary/IAP/AppFeature.swift @@ -42,9 +42,14 @@ public enum AppFeature: String, CaseIterable { case sharing - public static let allButAppleTV: [AppFeature] = allCases.filter { - $0 != .appleTV - } + public static let fullV2Features: [AppFeature] = [ + .dns, + .httpProxy, + .onDemand, + .providers, + .routing, + .sharing + ] } extension AppFeature: Identifiable { diff --git a/Passepartout/Library/Sources/CommonLibrary/IAP/AppFeatureProviding.swift b/Passepartout/Library/Sources/CommonLibrary/IAP/AppFeatureProviding.swift index 3d94ea94..9622d6e6 100644 --- a/Passepartout/Library/Sources/CommonLibrary/IAP/AppFeatureProviding.swift +++ b/Passepartout/Library/Sources/CommonLibrary/IAP/AppFeatureProviding.swift @@ -35,10 +35,10 @@ extension AppUserLevel: AppFeatureProviding { case .beta: return [.interactiveLogin, .sharing] - case .fullVersion: - return AppFeature.allButAppleTV + case .fullV2: + return AppFeature.fullV2Features - case .fullVersionPlusTV: + case .subscriber: return AppFeature.allCases default: @@ -71,18 +71,18 @@ extension AppProduct: AppFeatureProviding { return [.onDemand] case .Full.allPlatforms: - return AppFeature.allButAppleTV + return AppFeature.fullV2Features case .Full.iOS: #if os(iOS) - return AppFeature.allButAppleTV + return AppFeature.fullV2Features #else return [] #endif case .Full.macOS: #if os(macOS) - return AppFeature.allButAppleTV + return AppFeature.fullV2Features #else return [] #endif diff --git a/Passepartout/Library/Sources/CommonLibrary/IAP/AppUserLevel.swift b/Passepartout/Library/Sources/CommonLibrary/IAP/AppUserLevel.swift index 6d0c7cc6..17dc8af4 100644 --- a/Passepartout/Library/Sources/CommonLibrary/IAP/AppUserLevel.swift +++ b/Passepartout/Library/Sources/CommonLibrary/IAP/AppUserLevel.swift @@ -32,13 +32,13 @@ public enum AppUserLevel: Int, Sendable { case beta = 1 - case fullVersion = 2 + case fullV2 = 2 - case fullVersionPlusTV = 3 + case subscriber = 3 var isFullVersion: Bool { switch self { - case .fullVersion, .fullVersionPlusTV: + case .fullV2, .subscriber: return true default: diff --git a/Passepartout/Library/Tests/CommonLibraryTests/IAPManagerTests.swift b/Passepartout/Library/Tests/CommonLibraryTests/IAPManagerTests.swift index e5f9f5cc..219c5668 100644 --- a/Passepartout/Library/Tests/CommonLibraryTests/IAPManagerTests.swift +++ b/Passepartout/Library/Tests/CommonLibraryTests/IAPManagerTests.swift @@ -53,7 +53,7 @@ extension IAPManagerTests { return [] } await sut.reloadReceipt() - XCTAssertTrue(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertTrue(sut.isEligible(for: AppFeature.fullV2Features)) } func test_givenBuildProducts_whenNewer_thenFreeVersion() async { @@ -66,7 +66,7 @@ extension IAPManagerTests { return [] } await sut.reloadReceipt() - XCTAssertFalse(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertFalse(sut.isEligible(for: AppFeature.fullV2Features)) } // MARK: Eligibility @@ -75,13 +75,13 @@ extension IAPManagerTests { let reader = MockAppReceiptReader() let sut = IAPManager(receiptReader: reader) - XCTAssertFalse(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertFalse(sut.isEligible(for: AppFeature.fullV2Features)) await reader.setReceipt(withBuild: defaultBuildNumber, products: [.Full.allPlatforms]) - XCTAssertFalse(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertFalse(sut.isEligible(for: AppFeature.fullV2Features)) await sut.reloadReceipt() - XCTAssertTrue(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertTrue(sut.isEligible(for: AppFeature.fullV2Features)) } func test_givenPurchasedFeatures_thenIsOnlyEligibleForFeatures() async { @@ -97,7 +97,7 @@ extension IAPManagerTests { XCTAssertFalse(sut.isEligible(for: .onDemand)) XCTAssertTrue(sut.isEligible(for: .routing)) XCTAssertFalse(sut.isEligible(for: .sharing)) - XCTAssertFalse(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertFalse(sut.isEligible(for: AppFeature.fullV2Features)) } func test_givenPurchasedAndCancelledFeature_thenIsNotEligible() async { @@ -110,7 +110,7 @@ extension IAPManagerTests { let sut = IAPManager(receiptReader: reader) await sut.reloadReceipt() - XCTAssertFalse(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertFalse(sut.isEligible(for: AppFeature.fullV2Features)) } func test_givenFreeVersion_thenIsNotEligibleForAnyFeature() async { @@ -120,7 +120,7 @@ extension IAPManagerTests { await sut.reloadReceipt() XCTAssertFalse(sut.userLevel.isFullVersion) - AppFeature.allButAppleTV.forEach { + AppFeature.fullV2Features.forEach { XCTAssertFalse(sut.isEligible(for: $0)) } } @@ -134,16 +134,24 @@ extension IAPManagerTests { XCTAssertFalse(sut.isEligible(for: .appleTV)) } - func test_givenFullVersion_thenIsEligibleForAnyFeatureExceptAppleTV() async { + func test_givenFullV2Version_thenIsEligibleForAnyFeatureExceptExcluded() async { let reader = MockAppReceiptReader() await reader.setReceipt(withBuild: defaultBuildNumber, products: [.Full.allPlatforms]) let sut = IAPManager(receiptReader: reader) await sut.reloadReceipt() - AppFeature.allButAppleTV.forEach { - XCTAssertTrue(sut.isEligible(for: $0)) + let excluded: Set = [ + .appleTV, + .interactiveLogin + ] + AppFeature.allCases.forEach { + if AppFeature.fullV2Features.contains($0) { + XCTAssertTrue(sut.isEligible(for: $0)) + } else { + XCTAssertTrue(excluded.contains($0)) + XCTAssertFalse(sut.isEligible(for: $0)) + } } - XCTAssertFalse(sut.isEligible(for: .appleTV)) } func test_givenAppleTV_thenIsEligibleForAppleTV() async { @@ -162,11 +170,11 @@ extension IAPManagerTests { #if os(macOS) await reader.setReceipt(withBuild: defaultBuildNumber, products: [.Full.macOS, .Features.networkSettings]) await sut.reloadReceipt() - XCTAssertTrue(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertTrue(sut.isEligible(for: AppFeature.fullV2Features)) #else await reader.setReceipt(withBuild: defaultBuildNumber, products: [.Full.iOS, .Features.networkSettings]) await sut.reloadReceipt() - XCTAssertTrue(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertTrue(sut.isEligible(for: AppFeature.fullV2Features)) #endif } @@ -177,11 +185,11 @@ extension IAPManagerTests { #if os(macOS) await reader.setReceipt(withBuild: defaultBuildNumber, products: [.Full.iOS, .Features.networkSettings]) await sut.reloadReceipt() - XCTAssertFalse(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertFalse(sut.isEligible(for: AppFeature.fullV2Features)) #else await reader.setReceipt(withBuild: defaultBuildNumber, products: [.Full.macOS, .Features.networkSettings]) await sut.reloadReceipt() - XCTAssertFalse(sut.isEligible(for: AppFeature.allButAppleTV)) + XCTAssertFalse(sut.isEligible(for: AppFeature.fullV2Features)) #endif } @@ -224,39 +232,47 @@ extension IAPManagerTests { XCTAssertTrue(sut.isEligible(for: eligible)) } - func test_givenFullApp_thenIsFullVersion() async { + func test_givenFullV2App_thenIsFullVersion() async { let reader = MockAppReceiptReader() - let sut = IAPManager(customUserLevel: .fullVersion, receiptReader: reader) + let sut = IAPManager(customUserLevel: .fullV2, receiptReader: reader) await sut.reloadReceipt() XCTAssertTrue(sut.userLevel.isFullVersion) } - func test_givenFullPlusTVApp_thenIsFullVersion() async { + func test_givenSubscriberApp_thenIsFullVersion() async { let reader = MockAppReceiptReader() - let sut = IAPManager(customUserLevel: .fullVersionPlusTV, receiptReader: reader) + let sut = IAPManager(customUserLevel: .subscriber, receiptReader: reader) await sut.reloadReceipt() XCTAssertTrue(sut.userLevel.isFullVersion) } - func test_givenFullApp_thenIsEligibleForAnyFeatureExceptAppleTV() async { + func test_givenFullV2App_thenIsEligibleForAnyFeatureExceptExcluded() async { let reader = MockAppReceiptReader() - let sut = IAPManager(customUserLevel: .fullVersion, receiptReader: reader) + let sut = IAPManager(customUserLevel: .fullV2, receiptReader: reader) await sut.reloadReceipt() - AppFeature.allButAppleTV.forEach { - XCTAssertTrue(sut.isEligible(for: $0)) + let excluded: Set = [ + .appleTV, + .interactiveLogin + ] + AppFeature.allCases.forEach { + if AppFeature.fullV2Features.contains($0) { + XCTAssertTrue(sut.isEligible(for: $0)) + } else { + XCTAssertTrue(excluded.contains($0)) + XCTAssertFalse(sut.isEligible(for: $0)) + } } - XCTAssertFalse(sut.isEligible(for: .appleTV)) } - func test_givenFullPlusTVApp_thenIsEligibleForAnyFeature() async { + func test_givenSubscriberApp_thenIsEligibleForAnyFeature() async { let reader = MockAppReceiptReader() - let sut = IAPManager(customUserLevel: .fullVersionPlusTV, receiptReader: reader) + let sut = IAPManager(customUserLevel: .subscriber, receiptReader: reader) await sut.reloadReceipt() - AppFeature.allButAppleTV.forEach { + AppFeature.fullV2Features.forEach { XCTAssertTrue(sut.isEligible(for: $0)) } XCTAssertTrue(sut.isEligible(for: .appleTV))