-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paywalls
: more unit tests for purchasing state (#2931)
Follow up to #2930. Added `PresentIfNecessaryTests` and `PurchaseHandlerTests`. This also removes the last source of "crashes" whenever `Purchases` isn't configured, leading to errors instead.
- Loading branch information
Showing
7 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// PresentIfNecessaryTests.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/31/23. | ||
// | ||
|
||
import Nimble | ||
import RevenueCat | ||
@testable import RevenueCatUI | ||
import SwiftUI | ||
import XCTest | ||
|
||
#if !os(macOS) | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
@MainActor | ||
class PresentIfNecessaryTests: TestCase { | ||
|
||
func testPresentWithPurchaseHandler() throws { | ||
var customerInfo: CustomerInfo? | ||
|
||
Text("") | ||
.presentPaywallIfNecessary(offering: Self.offering, | ||
introEligibility: .producing(eligibility: .eligible), | ||
purchaseHandler: Self.purchaseHandler) { _ in | ||
return true | ||
} purchaseCompleted: { | ||
customerInfo = $0 | ||
} customerInfoFetcher: { | ||
return TestData.customerInfo | ||
} | ||
.addToHierarchy() | ||
|
||
Task { | ||
_ = try await Self.purchaseHandler.purchase(package: Self.package) | ||
} | ||
|
||
expect(customerInfo).toEventually(be(TestData.customerInfo)) | ||
} | ||
|
||
private static let purchaseHandler: PurchaseHandler = .mock() | ||
private static let offering = TestData.offeringWithNoIntroOffer | ||
private static let package = TestData.annualPackage | ||
|
||
} | ||
|
||
#endif |
57 changes: 57 additions & 0 deletions
57
Tests/RevenueCatUITests/Purchasing/PurchaseHandlerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// PurchaseHandlerTests.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/31/23. | ||
// | ||
|
||
import Nimble | ||
import RevenueCat | ||
@testable import RevenueCatUI | ||
import XCTest | ||
|
||
#if !os(macOS) | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
@MainActor | ||
class PurchaseHandlerTests: TestCase { | ||
|
||
func testInitialState() async throws { | ||
let handler: PurchaseHandler = .mock() | ||
|
||
expect(handler.purchasedCustomerInfo).to(beNil()) | ||
expect(handler.purchased) == false | ||
expect(handler.restored) == false | ||
expect(handler.actionInProgress) == false | ||
} | ||
|
||
func testPurchaseSetsCustomerInfo() async throws { | ||
let handler: PurchaseHandler = .mock() | ||
|
||
_ = try await handler.purchase(package: TestData.packageWithIntroOffer) | ||
|
||
expect(handler.purchasedCustomerInfo) === TestData.customerInfo | ||
expect(handler.purchased) == true | ||
expect(handler.actionInProgress) == false | ||
} | ||
|
||
func testCancellingPurchase() async throws { | ||
let handler: PurchaseHandler = .cancelling() | ||
|
||
_ = try await handler.purchase(package: TestData.packageWithIntroOffer) | ||
expect(handler.purchasedCustomerInfo).to(beNil()) | ||
expect(handler.purchased) == false | ||
expect(handler.actionInProgress) == false | ||
} | ||
|
||
func testRestorePurchases() async throws { | ||
let handler: PurchaseHandler = .mock() | ||
|
||
_ = try await handler.restorePurchases() | ||
expect(handler.restored) == true | ||
expect(handler.actionInProgress) == false | ||
} | ||
|
||
} | ||
|
||
#endif |
Binary file modified
BIN
+7.83 KB
(100%)
.../__Snapshots__/MultiPackageBoldPaywallViewTests/iOS16-testPurchasingState.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.