Skip to content

Commit 4d8118d

Browse files
authored
Extend the eligibility for the "Forever" product (#1377)
The condition for showing .complete was "no purchased products". Make it "any purchases but complete, core/essentials, and appletv", so that it excludes some very old legacy products.
1 parent ea6e122 commit 4d8118d

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

Packages/App/Sources/CommonIAP/Domain/AppProduct+Features.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ extension AppProduct {
104104
}
105105
}
106106

107+
public var isEssentials: Bool {
108+
switch self {
109+
case .Essentials.iOS,
110+
.Essentials.macOS,
111+
.Essentials.iOS_macOS:
112+
return true
113+
default:
114+
return false
115+
}
116+
}
117+
107118
public var isRecurring: Bool {
108119
switch self {
109120
case .Complete.Recurring.monthly, .Complete.Recurring.yearly:

Packages/App/Sources/CommonLibrary/IAP/IAPManager+Suggestions.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ extension IAPManager {
102102
}
103103
}
104104

105-
// TODO: ###, this condition may be improved by excluding very old products
106-
let isEligibleForComplete = purchasedProducts.isEmpty
107-
if filter != .excludingComplete && isEligibleForComplete {
105+
if filter != .excludingComplete && purchasedProducts.isEligibleForComplete {
108106
suggested.insert(.Complete.Recurring.yearly)
109107
suggested.insert(.Complete.Recurring.monthly)
110108
suggested.insert(.Complete.OneTime.lifetime)
@@ -113,3 +111,11 @@ extension IAPManager {
113111
return suggested
114112
}
115113
}
114+
115+
private extension Collection where Element == AppProduct {
116+
var isEligibleForComplete: Bool {
117+
!contains {
118+
$0.isComplete || $0.isEssentials || $0 == .Features.appleTV
119+
}
120+
}
121+
}

Packages/App/Tests/CommonLibraryTests/Business/IAPManagerTests.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,26 @@ extension IAPManagerTests {
361361
])
362362
}
363363

364-
func test_givenNonFree_whenWithComplete_thenSuggestsEssentials() async {
364+
func test_givenOldProducts_whenWithComplete_thenSuggestsEssentialsAndComplete() async {
365365
let sut = await IAPManager(products: [.Features.trustedNetworks])
366+
XCTAssertEqual(sut.suggestedProducts(for: .iOS, filter: .includingComplete), [
367+
.Essentials.iOS_macOS,
368+
.Essentials.iOS,
369+
.Complete.OneTime.lifetime,
370+
.Complete.Recurring.monthly,
371+
.Complete.Recurring.yearly
372+
])
373+
XCTAssertEqual(sut.suggestedProducts(for: .macOS, filter: .includingComplete), [
374+
.Essentials.iOS_macOS,
375+
.Essentials.macOS,
376+
.Complete.OneTime.lifetime,
377+
.Complete.Recurring.monthly,
378+
.Complete.Recurring.yearly
379+
])
380+
}
381+
382+
func test_givenNewProducts_whenWithComplete_thenSuggestsEssentials() async {
383+
let sut = await IAPManager(products: [.Features.appleTV])
366384
XCTAssertEqual(sut.suggestedProducts(for: .iOS, filter: .includingComplete), [
367385
.Essentials.iOS_macOS,
368386
.Essentials.iOS

0 commit comments

Comments
 (0)