@@ -570,6 +570,180 @@ struct POSTabEligibilityCheckerTests {
570570 // Then
571571 #expect( result == . eligible)
572572 }
573+
574+ // MARK: - `refreshEligibility` Tests
575+
576+ @Test func refreshEligibility_returns_ineligible_for_unsupportedIOSVersion( ) async throws {
577+ // Given
578+ let checker = POSTabEligibilityChecker ( siteID: siteID,
579+ siteSettings: siteSettings,
580+ pluginsService: pluginsService,
581+ stores: stores)
582+
583+ // When
584+ let result = try await checker. refreshEligibility ( ineligibleReason: . unsupportedIOSVersion)
585+
586+ // Then
587+ #expect( result == . ineligible( reason: . unsupportedIOSVersion) )
588+ }
589+
590+ @Test ( arguments: [
591+ POSIneligibleReason . siteSettingsNotAvailable,
592+ POSIneligibleReason . unsupportedCurrency ( supportedCurrencies: [ . USD] )
593+ ] )
594+ fileprivate func refreshEligibility_syncs_site_settings_and_checks_eligibility_for_site_settings_issues( ineligibleReason: POSIneligibleReason ) async throws {
595+ // Given
596+ setupCountry ( country: . us, currency: . USD)
597+ setupWooCommerceVersion ( " 9.6.0 " )
598+ setupPOSFeatureEnabled ( . success( true ) )
599+
600+ var syncCalled = false
601+ stores. whenReceivingAction ( ofType: SettingAction . self) { action in
602+ switch action {
603+ case . synchronizeGeneralSiteSettings( _, let completion) :
604+ syncCalled = true
605+ completion ( nil ) // Success
606+ case . isFeatureEnabled( _, _, let completion) :
607+ completion ( . success( true ) )
608+ default :
609+ break
610+ }
611+ }
612+
613+ let checker = POSTabEligibilityChecker ( siteID: siteID,
614+ siteSettings: siteSettings,
615+ pluginsService: pluginsService,
616+ stores: stores)
617+
618+ // When
619+ let result = try await checker. refreshEligibility ( ineligibleReason: ineligibleReason)
620+
621+ // Then
622+ #expect( syncCalled == true )
623+ #expect( result == . eligible)
624+ }
625+
626+ @Test ( arguments: [
627+ POSIneligibleReason . siteSettingsNotAvailable,
628+ POSIneligibleReason . unsupportedCurrency ( supportedCurrencies: [ . USD] )
629+ ] )
630+ fileprivate func refreshEligibility_returns_siteSettingsNotAvailable_when_site_settings_sync_fails( ineligibleReason: POSIneligibleReason ) async throws {
631+ // Given
632+ setupCountry ( country: . us, currency: . USD)
633+ setupWooCommerceVersion ( " 9.6.0 " )
634+
635+ var syncCalled = false
636+ stores. whenReceivingAction ( ofType: SettingAction . self) { action in
637+ switch action {
638+ case . synchronizeGeneralSiteSettings( _, let completion) :
639+ syncCalled = true
640+ completion ( NSError ( domain: " test " , code: 500 ) ) // Network error
641+ default :
642+ break
643+ }
644+ }
645+
646+ let checker = POSTabEligibilityChecker ( siteID: siteID,
647+ siteSettings: siteSettings,
648+ pluginsService: pluginsService,
649+ stores: stores)
650+
651+ // When & Then - Should throw the network error
652+ #expect( syncCalled == false ) // Not called yet
653+ await #expect( throws: NSError . self) {
654+ try await checker. refreshEligibility ( ineligibleReason: ineligibleReason)
655+ }
656+ #expect( syncCalled == true ) // Called during the attempt
657+ }
658+
659+ @Test func refreshEligibility_checks_eligibility_for_unsupportedWooCommerceVersion( ) async throws {
660+ // Given
661+ setupCountry ( country: . us, currency: . USD)
662+ setupWooCommerceVersion ( " 9.5.0 " ) // Still below minimum
663+
664+ let checker = POSTabEligibilityChecker ( siteID: siteID,
665+ siteSettings: siteSettings,
666+ pluginsService: pluginsService,
667+ stores: stores)
668+
669+ // When
670+ let result = try await checker. refreshEligibility ( ineligibleReason: . unsupportedWooCommerceVersion( minimumVersion: " 9.6.0-beta " ) )
671+
672+ // Then - Should check eligibility again (still ineligible due to version)
673+ #expect( result == . ineligible( reason: . unsupportedWooCommerceVersion( minimumVersion: " 9.6.0-beta " ) ) )
674+ }
675+
676+ @Test func refreshEligibility_checks_eligibility_for_wooCommercePluginNotFound( ) async throws {
677+ // Given
678+ setupCountry ( country: . us, currency: . USD)
679+ setupWooCommerceVersion ( " 9.6.0 " ) // Now eligible version
680+ setupPOSFeatureEnabled ( . success( true ) )
681+
682+ let checker = POSTabEligibilityChecker ( siteID: siteID,
683+ siteSettings: siteSettings,
684+ pluginsService: pluginsService,
685+ stores: stores)
686+
687+ // When
688+ let result = try await checker. refreshEligibility ( ineligibleReason: . wooCommercePluginNotFound)
689+
690+ // Then - Should check eligibility again (now eligible)
691+ #expect( result == . eligible)
692+ }
693+
694+ @Test func refreshEligibility_checks_eligibility_for_featureSwitchDisabled( ) async throws {
695+ // Given
696+ setupCountry ( country: . us, currency: . USD)
697+ setupWooCommerceVersion ( " 10.0.0 " ) // Version that supports feature switch
698+ setupPOSFeatureEnabled ( . success( true ) ) // Now enabled
699+
700+ let checker = POSTabEligibilityChecker ( siteID: siteID,
701+ siteSettings: siteSettings,
702+ pluginsService: pluginsService,
703+ stores: stores)
704+
705+ // When
706+ let result = try await checker. refreshEligibility ( ineligibleReason: . featureSwitchDisabled)
707+
708+ // Then - Should check eligibility again (now eligible)
709+ #expect( result == . eligible)
710+ }
711+
712+ @Test func refreshEligibility_checks_eligibility_for_featureSwitchSyncFailure( ) async throws {
713+ // Given
714+ setupCountry ( country: . us, currency: . USD)
715+ setupWooCommerceVersion ( " 10.0.0 " )
716+ setupPOSFeatureEnabled ( . failure( NSError ( domain: " test " , code: 0 ) ) ) // Still failing
717+
718+ let checker = POSTabEligibilityChecker ( siteID: siteID,
719+ siteSettings: siteSettings,
720+ pluginsService: pluginsService,
721+ stores: stores)
722+
723+ // When
724+ let result = try await checker. refreshEligibility ( ineligibleReason: . featureSwitchSyncFailure)
725+
726+ // Then - Should check eligibility again (still failing)
727+ #expect( result == . ineligible( reason: . featureSwitchSyncFailure) )
728+ }
729+
730+ @Test func refreshEligibility_checks_eligibility_for_selfDeallocated( ) async throws {
731+ // Given
732+ setupCountry ( country: . us, currency: . USD)
733+ setupWooCommerceVersion ( " 9.6.0 " )
734+ setupPOSFeatureEnabled ( . success( true ) )
735+
736+ let checker = POSTabEligibilityChecker ( siteID: siteID,
737+ siteSettings: siteSettings,
738+ pluginsService: pluginsService,
739+ stores: stores)
740+
741+ // When
742+ let result = try await checker. refreshEligibility ( ineligibleReason: . selfDeallocated)
743+
744+ // Then - Should check eligibility again (now eligible)
745+ #expect( result == . eligible)
746+ }
573747}
574748
575749private extension POSTabEligibilityCheckerTests {
0 commit comments