Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Packages/App/Sources/CommonIAP/Domain/AppProduct+Features.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ extension AppProduct {
}
}

public var isEssentials: Bool {
switch self {
case .Essentials.iOS,
.Essentials.macOS,
.Essentials.iOS_macOS:
return true
default:
return false
}
}

public var isRecurring: Bool {
switch self {
case .Complete.Recurring.monthly, .Complete.Recurring.yearly:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ extension IAPManager {
}
}

// TODO: ###, this condition may be improved by excluding very old products
let isEligibleForComplete = purchasedProducts.isEmpty
if filter != .excludingComplete && isEligibleForComplete {
if filter != .excludingComplete && purchasedProducts.isEligibleForComplete {
suggested.insert(.Complete.Recurring.yearly)
suggested.insert(.Complete.Recurring.monthly)
suggested.insert(.Complete.OneTime.lifetime)
Expand All @@ -113,3 +111,11 @@ extension IAPManager {
return suggested
}
}

private extension Collection where Element == AppProduct {
var isEligibleForComplete: Bool {
!contains {
$0.isComplete || $0.isEssentials || $0 == .Features.appleTV
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,26 @@ extension IAPManagerTests {
])
}

func test_givenNonFree_whenWithComplete_thenSuggestsEssentials() async {
func test_givenOldProducts_whenWithComplete_thenSuggestsEssentialsAndComplete() async {
let sut = await IAPManager(products: [.Features.trustedNetworks])
XCTAssertEqual(sut.suggestedProducts(for: .iOS, filter: .includingComplete), [
.Essentials.iOS_macOS,
.Essentials.iOS,
.Complete.OneTime.lifetime,
.Complete.Recurring.monthly,
.Complete.Recurring.yearly
])
XCTAssertEqual(sut.suggestedProducts(for: .macOS, filter: .includingComplete), [
.Essentials.iOS_macOS,
.Essentials.macOS,
.Complete.OneTime.lifetime,
.Complete.Recurring.monthly,
.Complete.Recurring.yearly
])
}

func test_givenNewProducts_whenWithComplete_thenSuggestsEssentials() async {
let sut = await IAPManager(products: [.Features.appleTV])
XCTAssertEqual(sut.suggestedProducts(for: .iOS, filter: .includingComplete), [
.Essentials.iOS_macOS,
.Essentials.iOS
Expand Down