File tree Expand file tree Collapse file tree 7 files changed +37
-24
lines changed
Tests/YosemiteTests/Tools/POS Expand file tree Collapse file tree 7 files changed +37
-24
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,10 @@ public protocol StoresManager {
6565 ///
6666 var site : AnyPublisher < Site ? , Never > { get }
6767
68+ /// Provides access to the session-scoped POS catalog sync coordinator
69+ ///
70+ var posCatalogSyncCoordinator : POSCatalogSyncCoordinatorProtocol ? { get }
71+
6872 /// Indicates if we need a Default StoreID, or there's one already set.
6973 ///
7074 var needsDefaultStore : Bool { get }
Original file line number Diff line number Diff line change @@ -253,6 +253,10 @@ public class MockStoresManager: StoresManager {
253253 public func shouldAuthenticateAdminPage( for site: Site ) -> Bool {
254254 return false
255255 }
256+
257+ public var posCatalogSyncCoordinator : ( any POSCatalogSyncCoordinatorProtocol ) ? {
258+ nil
259+ }
256260}
257261
258262private extension MockStoresManager {
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ struct POSCatalogSyncCoordinatorTests {
4646 mockSyncService. startFullSyncResult = . success( expectedCatalog)
4747
4848 // When
49- _ = try await sut. performFullSync ( for: sampleSiteID)
49+ try await sut. performFullSync ( for: sampleSiteID)
5050 let afterSync = Date ( )
5151
5252 // Then
@@ -66,7 +66,7 @@ struct POSCatalogSyncCoordinatorTests {
6666
6767 // When/Then
6868 await #expect( throws: expectedError) {
69- _ = try await sut. performFullSync ( for: sampleSiteID)
69+ try await sut. performFullSync ( for: sampleSiteID)
7070 }
7171
7272 // Should not store timestamp on failure
Original file line number Diff line number Diff line change @@ -112,10 +112,6 @@ final class ServiceLocator {
112112 ///
113113 private static var _startupWaitingTimeTracker : AppStartupWaitingTimeTracker = AppStartupWaitingTimeTracker ( )
114114
115- /// POS catalog sync coordinator
116- ///
117- private static var _posCatalogSyncCoordinator : POSCatalogSyncCoordinatorProtocol ?
118-
119115 // MARK: - Getters
120116
121117 /// Provides the access point to the analytics.
@@ -305,25 +301,14 @@ final class ServiceLocator {
305301 }
306302
307303 /// Provides access point to the `POSCatalogSyncCoordinator`.
304+ /// Returns nil if feature flag is disabled or user is not authenticated.
308305 ///
309- static var posCatalogSyncCoordinator : POSCatalogSyncCoordinatorProtocol {
306+ static var posCatalogSyncCoordinator : POSCatalogSyncCoordinatorProtocol ? {
310307 guard featureFlagService. isFeatureFlagEnabled ( . pointOfSaleLocalCatalogi1) else {
311- fatalError ( " POSCatalogSyncCoordinator accessed when pointOfSaleLocalCatalogi1 feature flag is disabled " )
312- }
313-
314- guard let coordinator = _posCatalogSyncCoordinator else {
315- guard let credentials = stores. sessionManager. defaultCredentials,
316- let fullSyncService = POSCatalogFullSyncService ( credentials: credentials, grdbManager: grdbManager)
317- else {
318- fatalError ( " Failed to create POSCatalogSyncCoordinator due to missing credentials " )
319- }
320-
321- let coordinator = POSCatalogSyncCoordinator ( fullSyncService: fullSyncService, grdbManager: grdbManager)
322- _posCatalogSyncCoordinator = coordinator
323- return coordinator
308+ return nil
324309 }
325310
326- return coordinator
311+ return stores . posCatalogSyncCoordinator
327312 }
328313}
329314
Original file line number Diff line number Diff line change @@ -767,9 +767,8 @@ private extension MainTabBarController {
767767 )
768768
769769 // Configure POS catalog sync coordinator for local catalog syncing
770- if ServiceLocator . featureFlagService. isFeatureFlagEnabled ( . pointOfSaleLocalCatalogi1) {
771- posCatalogSyncCoordinator = ServiceLocator . posCatalogSyncCoordinator
772- }
770+ // Get POS catalog sync coordinator (will be nil if feature flag disabled or not authenticated)
771+ posCatalogSyncCoordinator = ServiceLocator . posCatalogSyncCoordinator
773772
774773 // Configure hub menu tab coordinator once per logged in session potentially with multiple sites.
775774 if hubMenuTabCoordinator == nil {
Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ class AuthenticatedState: StoresManagerState {
2828
2929 private var cancellables : Set < AnyCancellable > = [ ]
3030
31+ /// POS Catalog Sync Coordinator (session-scoped)
32+ ///
33+ private( set) var posCatalogSyncCoordinator : POSCatalogSyncCoordinator ?
34+
3135 /// Designated Initializer
3236 ///
3337 init ( credentials: Credentials , sessionManager: SessionManagerProtocol ) {
@@ -136,6 +140,17 @@ class AuthenticatedState: StoresManagerState {
136140
137141 self . services = services
138142
143+ // Initialize POS catalog sync coordinator if feature flag is enabled
144+ if ServiceLocator . featureFlagService. isFeatureFlagEnabled ( . pointOfSaleLocalCatalogi1) ,
145+ let fullSyncService = POSCatalogFullSyncService ( credentials: credentials, grdbManager: ServiceLocator . grdbManager) {
146+ posCatalogSyncCoordinator = POSCatalogSyncCoordinator (
147+ fullSyncService: fullSyncService,
148+ grdbManager: ServiceLocator . grdbManager
149+ )
150+ } else {
151+ posCatalogSyncCoordinator = nil
152+ }
153+
139154 trackEventRequestNotificationHandler = TrackEventRequestNotificationHandler ( )
140155
141156 startListeningToNotifications ( )
Original file line number Diff line number Diff line change @@ -120,6 +120,12 @@ class DefaultStoresManager: StoresManager {
120120 sessionManager. defaultSitePublisher
121121 }
122122
123+ /// Provides access to the session-scoped POS catalog sync coordinator
124+ ///
125+ var posCatalogSyncCoordinator : POSCatalogSyncCoordinatorProtocol ? {
126+ ( state as? AuthenticatedState ) ? . posCatalogSyncCoordinator
127+ }
128+
123129 /// Designated Initializer
124130 ///
125131 init ( sessionManager: SessionManagerProtocol ,
You can’t perform that action at this time.
0 commit comments