Skip to content

Commit

Permalink
Paywalls: don't display "Purchases restored successfully" with no e…
Browse files Browse the repository at this point in the history
…ntitlements

We can improve the logic here, but this is a simple improvement for the obvious case where nothing was actually restored.
We don't have an easy way to test this, but at least I added coverage for `onRestoreCompleted` which was missing.
  • Loading branch information
NachoSoto committed Sep 20, 2023
1 parent f54372b commit 9c141a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions RevenueCatUI/Views/FooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ private struct RestorePurchasesButton: View {

var body: some View {
AsyncButton {
_ = try await self.purchaseHandler.restorePurchases()
self.displayRestoredAlert = true
let customerInfo = try await self.purchaseHandler.restorePurchases()

if !customerInfo.entitlements.active.isEmpty {
self.displayRestoredAlert = true
}
} label: {
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, *) {
ViewThatFits {
Expand Down
21 changes: 21 additions & 0 deletions Tests/RevenueCatUITests/PurchaseCompletedHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ class PurchaseCompletedHandlerTests: TestCase {
expect(customerInfo).toEventually(be(TestData.customerInfo))
}

func testOnRestoreCompleted() throws {
var customerInfo: CustomerInfo?

try PaywallView(
offering: Self.offering.withLocalImages,
customerInfo: TestData.customerInfo,
introEligibility: .producing(eligibility: .eligible),
purchaseHandler: Self.purchaseHandler
)
.onRestoreCompleted {
customerInfo = $0
}
.addToHierarchy()

Task {
_ = try await Self.purchaseHandler.restorePurchases()
}

expect(customerInfo).toEventually(be(TestData.customerInfo))
}

private static let purchaseHandler: PurchaseHandler = .mock()
private static let offering = TestData.offeringWithNoIntroOffer
private static let package = TestData.annualPackage
Expand Down

0 comments on commit 9c141a4

Please sign in to comment.