diff --git a/RevenueCatUI/Templates/Example1Template.swift b/RevenueCatUI/Templates/Example1Template.swift index 14f36f5269..fad4cb31d7 100644 --- a/RevenueCatUI/Templates/Example1Template.swift +++ b/RevenueCatUI/Templates/Example1Template.swift @@ -22,7 +22,7 @@ struct Example1Template: TemplateViewType { self.data = .failure(.noPackages) } else { let allPackages = paywall.config.packages - let packages = Self.filter(packages: packages, with: allPackages) + let packages = PaywallData.filter(packages: packages, with: allPackages) if let package = packages.first { self.data = .success(.init( diff --git a/RevenueCatUI/Templates/TemplateViewType.swift b/RevenueCatUI/Templates/TemplateViewType.swift index df882f8303..2a8d81daeb 100644 --- a/RevenueCatUI/Templates/TemplateViewType.swift +++ b/RevenueCatUI/Templates/TemplateViewType.swift @@ -26,10 +26,6 @@ extension PaywallData { ) } } -} - -@available(iOS 16.0, macOS 13.0, tvOS 16.0, *) -extension TemplateViewType { static func filter(packages: [Package], with list: [PackageType]) -> [Package] { // Only subscriptions are supported at the moment diff --git a/Tests/RevenueCatUITests/PackageFilteringTests.swift b/Tests/RevenueCatUITests/PackageFilteringTests.swift new file mode 100644 index 0000000000..dab75df211 --- /dev/null +++ b/Tests/RevenueCatUITests/PackageFilteringTests.swift @@ -0,0 +1,72 @@ +// +// 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] + } + +} + +@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) +private extension PackageFilteringTests { + + 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" + +}