diff --git a/Modules/Sources/Fakes/Networking.generated.swift b/Modules/Sources/Fakes/Networking.generated.swift index 479305984dd..c640e2ae555 100644 --- a/Modules/Sources/Fakes/Networking.generated.swift +++ b/Modules/Sources/Fakes/Networking.generated.swift @@ -1774,7 +1774,10 @@ extension Networking.Site { isAdmin: .fake(), wasEcommerceTrial: .fake(), hasSSOEnabled: .fake(), - applicationPasswordAvailable: .fake() + applicationPasswordAvailable: .fake(), + isGarden: false, + gardenName: nil, + gardenPartner: nil ) } } diff --git a/Modules/Sources/Networking/Model/Copiable/Models+Copiable.generated.swift b/Modules/Sources/Networking/Model/Copiable/Models+Copiable.generated.swift index d253c95e65b..cd2809a36bc 100644 --- a/Modules/Sources/Networking/Model/Copiable/Models+Copiable.generated.swift +++ b/Modules/Sources/Networking/Model/Copiable/Models+Copiable.generated.swift @@ -2747,7 +2747,10 @@ extension Networking.Site { isAdmin: CopiableProp = .copy, wasEcommerceTrial: CopiableProp = .copy, hasSSOEnabled: CopiableProp = .copy, - applicationPasswordAvailable: CopiableProp = .copy + applicationPasswordAvailable: CopiableProp = .copy, + isGarden: CopiableProp = .copy, + gardenName: CopiableProp = .copy, + gardenPartner: CopiableProp = .copy ) -> Networking.Site { let siteID = siteID ?? self.siteID let name = name ?? self.name @@ -2772,6 +2775,9 @@ extension Networking.Site { let wasEcommerceTrial = wasEcommerceTrial ?? self.wasEcommerceTrial let hasSSOEnabled = hasSSOEnabled ?? self.hasSSOEnabled let applicationPasswordAvailable = applicationPasswordAvailable ?? self.applicationPasswordAvailable + let isGarden = isGarden ?? self.isGarden + let gardenName = gardenName ?? self.gardenName + let gardenPartner = gardenPartner ?? self.gardenPartner return Networking.Site( siteID: siteID, @@ -2796,7 +2802,10 @@ extension Networking.Site { isAdmin: isAdmin, wasEcommerceTrial: wasEcommerceTrial, hasSSOEnabled: hasSSOEnabled, - applicationPasswordAvailable: applicationPasswordAvailable + applicationPasswordAvailable: applicationPasswordAvailable, + isGarden: isGarden, + gardenName: gardenName, + gardenPartner: gardenPartner ) } } diff --git a/Modules/Sources/Networking/Model/Site.swift b/Modules/Sources/Networking/Model/Site.swift index e602b369426..a99d1afe5b0 100644 --- a/Modules/Sources/Networking/Model/Site.swift +++ b/Modules/Sources/Networking/Model/Site.swift @@ -97,6 +97,18 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated /// public let applicationPasswordAvailable: Bool + /// Whether the site is running on Garden architecture + /// + public let isGarden: Bool + + /// The site Garden name is present + /// + public let gardenName: String? + + /// The site Garden partner if present + /// + public let gardenPartner: String? + /// Decodable Conformance. /// public init(from decoder: Decoder) throws { @@ -140,6 +152,10 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated return jetpackModules.contains(OptionKeys.sso.rawValue) == true }() + let isGarden = try siteContainer.decodeIfPresent(Bool.self, forKey: .isGarden) ?? false + let gardenName = try siteContainer.decodeIfPresent(String.self, forKey: .gardenName) + let gardenPartner = try siteContainer.decodeIfPresent(String.self, forKey: .gardenPartner) + self.init(siteID: siteID, name: name, description: description, @@ -162,7 +178,10 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated isAdmin: isAdmin, wasEcommerceTrial: wasEcommerceTrial, hasSSOEnabled: hasSSOEnabled, - applicationPasswordAvailable: false) // to be updated by fetching SiteAPI + applicationPasswordAvailable: false, // to be updated by fetching SiteAPI + isGarden: isGarden, + gardenName: gardenName, + gardenPartner: gardenPartner) } /// Designated Initializer. @@ -189,7 +208,10 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated isAdmin: Bool, wasEcommerceTrial: Bool, hasSSOEnabled: Bool, - applicationPasswordAvailable: Bool) { + applicationPasswordAvailable: Bool, + isGarden: Bool, + gardenName: String?, + gardenPartner: String?) { self.siteID = siteID self.name = name self.description = description @@ -213,6 +235,9 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated self.wasEcommerceTrial = wasEcommerceTrial self.hasSSOEnabled = hasSSOEnabled self.applicationPasswordAvailable = applicationPasswordAvailable + self.isGarden = isGarden + self.gardenName = gardenName + self.gardenPartner = gardenPartner } } @@ -264,6 +289,9 @@ private extension Site { case isJetpackConnected = "jetpack_connection" case wasEcommerceTrial = "was_ecommerce_trial" case jetpackModules = "jetpack_modules" + case isGarden = "is_garden" + case gardenName = "garden_name" + case gardenPartner = "garden_partner" } enum PlanInfo: String, CodingKey { diff --git a/Modules/Sources/Networking/Model/WordPressSite.swift b/Modules/Sources/Networking/Model/WordPressSite.swift index 31eae08d56b..9e6eda3d617 100644 --- a/Modules/Sources/Networking/Model/WordPressSite.swift +++ b/Modules/Sources/Networking/Model/WordPressSite.swift @@ -110,7 +110,10 @@ public extension WordPressSite { isAdmin: false, wasEcommerceTrial: false, hasSSOEnabled: false, - applicationPasswordAvailable: false) + applicationPasswordAvailable: false, + isGarden: false, + gardenName: nil, + gardenPartner: nil) } struct Authentication: Decodable { diff --git a/Modules/Sources/Networking/Remote/SiteRemote.swift b/Modules/Sources/Networking/Remote/SiteRemote.swift index 25c5cc5de89..0ca57477482 100644 --- a/Modules/Sources/Networking/Remote/SiteRemote.swift +++ b/Modules/Sources/Networking/Remote/SiteRemote.swift @@ -338,12 +338,37 @@ extension SiteRemote { enum SiteParameter { enum Fields { static let key = "fields" - static let value = "ID,name,description,URL,options,jetpack,jetpack_connection,capabilities,was_ecommerce_trial,plan,jetpack_modules" + static let value = [ + "ID", + "name", + "description", + "URL", + "options", + "jetpack", + "jetpack_connection", + "capabilities", + "was_ecommerce_trial", + "plan", + "jetpack_modules", + "is_garden", + "garden_name", + "garden_partner" + ].joined(separator: ",") } enum Options { static let key = "options" - static let value = - "timezone,is_wpcom_store,woocommerce_is_active,gmt_offset,jetpack_connection_active_plugins,admin_url,login_url,frame_nonce,blog_public,can_blaze" + static let value = [ + "timezone", + "is_wpcom_store", + "woocommerce_is_active", + "gmt_offset", + "jetpack_connection_active_plugins", + "admin_url", + "login_url", + "frame_nonce", + "blog_public", + "can_blaze" + ].joined(separator: ",") } } } diff --git a/Modules/Sources/Storage/Model/MIGRATIONS.md b/Modules/Sources/Storage/Model/MIGRATIONS.md index dd77c1d55b2..4f75348ec89 100644 --- a/Modules/Sources/Storage/Model/MIGRATIONS.md +++ b/Modules/Sources/Storage/Model/MIGRATIONS.md @@ -2,6 +2,12 @@ This file documents changes in the WCiOS Storage data model. Please explain any changes to the data model as well as any custom migrations. +## Model 126 (Release 23.3.0.0) +- @rafaelkayumov 2025-09-15 + - Added `isGarden` attribute to `Site` entity. + - Added `gardenName` attribute to `Site` entity. + - Added `gardenPartner` attribute to `Site` entity. + ## Model 125 (Release 23.2.0.0) - @itsmeichigo 2025-09-04 - Added `hazmatCategory` attribute to `ShippingLabel` entity. diff --git a/Modules/Sources/Storage/Model/Site+CoreDataProperties.swift b/Modules/Sources/Storage/Model/Site+CoreDataProperties.swift index 59ec7cc40d1..e69cfc2c045 100644 --- a/Modules/Sources/Storage/Model/Site+CoreDataProperties.swift +++ b/Modules/Sources/Storage/Model/Site+CoreDataProperties.swift @@ -29,6 +29,9 @@ extension Site { @NSManaged public var canBlaze: Bool @NSManaged public var wasEcommerceTrial: Bool @NSManaged public var hasSSOEnabled: Bool + @NSManaged public var isGarden: Bool + @NSManaged public var gardenName: String? + @NSManaged public var gardenPartner: String? } diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion index a3ea46178c4..014e45c214a 100644 --- a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - Model 125.xcdatamodel + Model 126.xcdatamodel diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 126.xcdatamodel/contents b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 126.xcdatamodel/contents new file mode 100644 index 00000000000..7540d6924e9 --- /dev/null +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 126.xcdatamodel/contents @@ -0,0 +1,1108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Modules/Sources/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift b/Modules/Sources/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift index a3d8cd798bc..91066706e66 100644 --- a/Modules/Sources/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift +++ b/Modules/Sources/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift @@ -56,7 +56,10 @@ struct ScreenshotObjectGraph: MockObjectGraph { isAdmin: false, wasEcommerceTrial: false, hasSSOEnabled: false, - applicationPasswordAvailable: false + applicationPasswordAvailable: false, + isGarden: false, + gardenName: nil, + gardenPartner: nil ) /// May not be needed anymore if we're not mocking the API diff --git a/Modules/Sources/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift b/Modules/Sources/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift index b4cd827246a..543dc85dcf0 100644 --- a/Modules/Sources/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift +++ b/Modules/Sources/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift @@ -31,6 +31,9 @@ extension Storage.Site: ReadOnlyConvertible { isAdmin = site.isAdmin wasEcommerceTrial = site.wasEcommerceTrial hasSSOEnabled = site.hasSSOEnabled + isGarden = site.isGarden + gardenName = site.gardenName + gardenPartner = site.gardenPartner } /// Returns a ReadOnly version of the receiver. @@ -58,6 +61,9 @@ extension Storage.Site: ReadOnlyConvertible { isAdmin: isAdmin, wasEcommerceTrial: wasEcommerceTrial, hasSSOEnabled: hasSSOEnabled, - applicationPasswordAvailable: false) // to be updated separately + applicationPasswordAvailable: false, // to be updated separately + isGarden: isGarden, + gardenName: gardenName, + gardenPartner: gardenPartner) } } diff --git a/WooCommerce/Classes/CIAB/CIABEligibilityChecker.swift b/WooCommerce/Classes/CIAB/CIABEligibilityChecker.swift index 102ca3cc023..b3627647e1c 100644 --- a/WooCommerce/Classes/CIAB/CIABEligibilityChecker.swift +++ b/WooCommerce/Classes/CIAB/CIABEligibilityChecker.swift @@ -20,11 +20,7 @@ extension CIABEligibilityChecker: CIABEligibilityCheckerProtocol { } func isSiteCIAB(_ site: Site) -> Bool { - /// Temp logic - /// If site name contains either `garden` or `ciab` then it's considered a CIAB site - return isCIABSupportedForBuildEnvironment && CIABUnlockingSiteNameSubstrings.allCases.contains { - site.name.lowercased().contains($0.rawValue) - } + return site.isCIAB } func isFeatureSupportedForCurrentSite(_ feature: CIABAffectedFeature) -> Bool { @@ -39,22 +35,15 @@ extension CIABEligibilityChecker: CIABEligibilityCheckerProtocol { } } -// MARK: - Temporary constants for CIAB identifying logic +// MARK: - Site checks -fileprivate extension CIABEligibilityChecker { - enum CIABUnlockingSiteNameSubstrings: String, CaseIterable { - case garden - case ciab +private extension Site { + var isCIAB: Bool { + return isGarden && gardenName == GardenName.commerce.rawValue } } -// MARK: - Temporary environment checks - -import enum WooFoundationCore.BuildConfiguration - -private extension CIABEligibilityChecker { - var isCIABSupportedForBuildEnvironment: Bool { - let buildConfig = BuildConfiguration.current - return buildConfig == .localDeveloper || buildConfig == .alpha - } +private enum GardenName: String { + /// Garden name for CIAB sites + case commerce } diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index 3de330f8a68..2535e31c2e4 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -1237,6 +1237,7 @@ 26FFC50D2BED7C5B0067B3A4 /* WatchDependencies.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B249702BEC801400730730 /* WatchDependencies.swift */; }; 2D09E0D12E61BC7F005C26F3 /* ApplicationPasswordsExperimentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D09E0D02E61BC7D005C26F3 /* ApplicationPasswordsExperimentState.swift */; }; 2D09E0D52E65C9B9005C26F3 /* ApplicationPasswordsExperimentStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D09E0D42E65C9B9005C26F3 /* ApplicationPasswordsExperimentStateTests.swift */; }; + 2D7A3E232E7891DB00C46401 /* CIABEligibilityCheckerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D7A3E222E7891D200C46401 /* CIABEligibilityCheckerTests.swift */; }; 2D880B492DFB2F3F00A6FB2C /* OptionalBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D880B482DFB2F3D00A6FB2C /* OptionalBinding.swift */; }; 2D88C1112DF883C300A6FB2C /* AttributedString+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D88C1102DF883BD00A6FB2C /* AttributedString+Helpers.swift */; }; 2DA63E042E69B6D400B0CB28 /* ApplicationPasswordsExperimentAvailabilityCheckerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA63E032E69B6D200B0CB28 /* ApplicationPasswordsExperimentAvailabilityCheckerTests.swift */; }; @@ -4434,6 +4435,7 @@ 26FFD32928C6A0F4002E5E5E /* UIImage+Widgets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Widgets.swift"; sourceTree = ""; }; 2D09E0D02E61BC7D005C26F3 /* ApplicationPasswordsExperimentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationPasswordsExperimentState.swift; sourceTree = ""; }; 2D09E0D42E65C9B9005C26F3 /* ApplicationPasswordsExperimentStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationPasswordsExperimentStateTests.swift; sourceTree = ""; }; + 2D7A3E222E7891D200C46401 /* CIABEligibilityCheckerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CIABEligibilityCheckerTests.swift; sourceTree = ""; }; 2D880B482DFB2F3D00A6FB2C /* OptionalBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionalBinding.swift; sourceTree = ""; }; 2D88C1102DF883BD00A6FB2C /* AttributedString+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AttributedString+Helpers.swift"; sourceTree = ""; }; 2DA63E032E69B6D200B0CB28 /* ApplicationPasswordsExperimentAvailabilityCheckerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationPasswordsExperimentAvailabilityCheckerTests.swift; sourceTree = ""; }; @@ -9071,6 +9073,14 @@ path = Images; sourceTree = ""; }; + 2D7A3E212E7891C400C46401 /* CIAB */ = { + isa = PBXGroup; + children = ( + 2D7A3E222E7891D200C46401 /* CIABEligibilityCheckerTests.swift */, + ); + path = CIAB; + sourceTree = ""; + }; 2DCB54F82E6AE8C900621F90 /* CIAB */ = { isa = PBXGroup; children = ( @@ -12959,6 +12969,7 @@ D816DDBA22265D8000903E59 /* ViewRelated */ = { isa = PBXGroup; children = ( + 2D7A3E212E7891C400C46401 /* CIAB */, 864059FE2C6F67A000DA04DC /* Custom Fields */, 86023FAB2B16D80E00A28F07 /* Themes */, EE45E2C02A42C9C70085F227 /* Feature Highlight */, @@ -17454,6 +17465,7 @@ B517EA1A218B2D2600730EC4 /* StringFormatterTests.swift in Sources */, 200BA15B2CF0A2130006DC5B /* MockPointOfSaleItemsService.swift in Sources */, 26F65C9E25DEDE67008FAE29 /* GenerateVariationUseCaseTests.swift in Sources */, + 2D7A3E232E7891DB00C46401 /* CIABEligibilityCheckerTests.swift in Sources */, 03D798602A960FDF00809B0E /* MockPaymentCaptureOrchestrator.swift in Sources */, 77307809251EA07100178696 /* ProductDownloadSettingsViewModelTests.swift in Sources */, 02EA6BFC2435EC3500FFF90A /* MockImageDownloader.swift in Sources */, diff --git a/WooCommerce/WooCommerceTests/ViewRelated/CIAB/CIABEligibilityCheckerTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/CIAB/CIABEligibilityCheckerTests.swift new file mode 100644 index 00000000000..6c42affe685 --- /dev/null +++ b/WooCommerce/WooCommerceTests/ViewRelated/CIAB/CIABEligibilityCheckerTests.swift @@ -0,0 +1,140 @@ +import XCTest +@testable import WooCommerce +@testable import Yosemite + +class CIABEligibilityCheckerTests: XCTestCase { + private var storesManager: MockStoresManager! + private var sessionManager: SessionManager! + private var checker: CIABEligibilityChecker! + + override func setUp() { + super.setUp() + sessionManager = .makeForTesting() + storesManager = MockStoresManager(sessionManager: sessionManager) + checker = CIABEligibilityChecker(stores: storesManager) + } + + override func tearDown() { + checker = nil + storesManager = nil + sessionManager = nil + super.tearDown() + } + + // MARK: - isCurrentSiteCIAB + + func test_is_current_site_ciab_when_no_default_site_returns_false() { + // Given + sessionManager.defaultSite = nil + + // Then + XCTAssertFalse(checker.isCurrentSiteCIAB) + } + + func test_is_current_site_ciab_when_default_site_is_ciab_returns_true() { + // Given + sessionManager.defaultSite = makeCIABSite() + + // Then + XCTAssertTrue(checker.isCurrentSiteCIAB) + } + + func test_is_current_site_ciab_when_default_site_is_not_ciab_returns_false() { + // Given + sessionManager.defaultSite = makeNonCIABGardenSite() + + // Then + XCTAssertFalse(checker.isCurrentSiteCIAB) + } + + func test_is_current_site_ciab_when_default_site_is_non_garden_returns_false() { + // Given + sessionManager.defaultSite = makeNonGardenSite() + + // Then + XCTAssertFalse(checker.isCurrentSiteCIAB) + } + + // MARK: - isSiteCIAB + + func test_is_site_ciab_with_ciab_site_returns_true() { + // Given + let site = makeCIABSite() + + // Then + XCTAssertTrue(checker.isSiteCIAB(site)) + } + + func test_is_site_ciab_with_non_ciab_garden_site_returns_false() { + // Given + let site = makeNonCIABGardenSite() + + // Then + XCTAssertFalse(checker.isSiteCIAB(site)) + } + + func test_is_site_ciab_with_non_garden_site_returns_false() { + // Given + let site = makeNonGardenSite() + + // Then + XCTAssertFalse(checker.isSiteCIAB(site)) + } + + // MARK: - isFeatureSupportedForCurrentSite + + func test_is_feature_supported_for_current_site_when_not_ciab_returns_true() { + // Given + sessionManager.defaultSite = makeNonCIABGardenSite() + + // Then + XCTAssertTrue(checker.isFeatureSupportedForCurrentSite(.payments)) + } + + func test_is_feature_supported_for_current_site_when_ciab_and_feature_unsupported_returns_false() { + // Given + sessionManager.defaultSite = makeCIABSite() + + // Then + XCTAssertFalse(checker.isFeatureSupportedForCurrentSite(.payments)) + } + + // MARK: - isFeatureSupported(for:) + + func test_is_feature_supported_for_site_when_not_ciab_returns_true() { + // Given + let site = makeNonCIABGardenSite() + + // Then + XCTAssertTrue(checker.isFeatureSupported(.payments, for: site)) + } + + func test_is_feature_supported_for_site_when_ciab_and_feature_unsupported_returns_false() { + // Given + let site = makeCIABSite() + + // Then + XCTAssertFalse(checker.isFeatureSupported(.payments, for: site)) + } +} + +// MARK: - Helpers +private extension CIABEligibilityCheckerTests { + func makeCIABSite() -> Site { + Site.fake().copy( + isGarden: true, + gardenName: "commerce" + ) + } + + func makeNonCIABGardenSite() -> Site { + Site.fake().copy( + isGarden: true, + gardenName: "not-commerce" + ) + } + + func makeNonGardenSite() -> Site { + Site.fake().copy(isGarden: false) + } +}