-
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.
Some missing tests for the logic added in #2798. I've also moved this function to be fined in `PaywallData` instead of the `TemplateViewType` protocol, which makes more sense.
- Loading branch information
Showing
3 changed files
with
93 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// PackageFilteringTests.swift | ||
// | ||
// | ||
// Created by Nacho Soto on 7/13/23. | ||
// | ||
|
||
import Nimble | ||
import RevenueCat | ||
@testable import RevenueCatUI | ||
import XCTest | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
class PackageFilteringTests: TestCase { | ||
|
||
func testFilterNoPackages() { | ||
expect(PaywallData.filter(packages: [], with: [.monthly])) == [] | ||
} | ||
|
||
func testFilterPackagesWithEmptyList() { | ||
expect(PaywallData.filter(packages: [Self.monthly], with: [])) == [] | ||
} | ||
|
||
func testFilterOutSinglePackge() { | ||
expect(PaywallData.filter(packages: [Self.monthly], with: [.annual])) == [] | ||
} | ||
|
||
func testFilterOutNonSubscriptions() { | ||
expect(PaywallData.filter(packages: [Self.consumable], with: [.custom])) == [] | ||
} | ||
|
||
func testFilterByPackageType() { | ||
expect(PaywallData.filter(packages: [Self.monthly, Self.annual], with: [.monthly])) == [Self.monthly] | ||
} | ||
|
||
func testFilterWithDuplicatedPackageTypes() { | ||
expect(PaywallData.filter(packages: [Self.monthly, Self.annual], with: [.monthly, .monthly])) == [ | ||
Self.monthly, | ||
Self.monthly | ||
] | ||
} | ||
|
||
func testFilterReturningMultiplePackages() { | ||
expect(PaywallData.filter(packages: [Self.weekly, Self.monthly, Self.annual], with: [.weekly, .monthly])) == [ | ||
Self.weekly, | ||
Self.monthly | ||
] | ||
} | ||
|
||
} | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
private extension PackageFilteringTests { | ||
|
||
static let weekly = Package( | ||
identifier: "weekly", | ||
packageType: .weekly, | ||
storeProduct: TestData.productWithIntroOffer.toStoreProduct(), | ||
offeringIdentifier: offeringIdentifier | ||
) | ||
static let monthly = Package( | ||
identifier: "monthly", | ||
packageType: .monthly, | ||
storeProduct: TestData.productWithIntroOffer.toStoreProduct(), | ||
offeringIdentifier: offeringIdentifier | ||
) | ||
static let annual = Package( | ||
identifier: "annual", | ||
packageType: .annual, | ||
storeProduct: TestData.productWithNoIntroOffer.toStoreProduct(), | ||
offeringIdentifier: offeringIdentifier | ||
) | ||
|
||
static let consumable = Package( | ||
identifier: "consumable", | ||
packageType: .custom, | ||
storeProduct: consumableProduct.toStoreProduct(), | ||
offeringIdentifier: offeringIdentifier | ||
) | ||
|
||
private static let consumableProduct = TestStoreProduct( | ||
localizedTitle: "Coins", | ||
price: 199.99, | ||
localizedPriceString: "$199.99", | ||
productIdentifier: "com.revenuecat.coins", | ||
productType: .consumable, | ||
localizedDescription: "Coins" | ||
) | ||
|
||
private static let offeringIdentifier = "offering" | ||
|
||
} |