diff --git a/Examples/xx-messenger/Sources/AppFeature/AppEnvironment+Live.swift b/Examples/xx-messenger/Sources/AppFeature/AppEnvironment+Live.swift index 3c75f40afb41be86846967f43d2b8fb0f8462b8c..c79d5b935e7f12255b852278256742608695734e 100644 --- a/Examples/xx-messenger/Sources/AppFeature/AppEnvironment+Live.swift +++ b/Examples/xx-messenger/Sources/AppFeature/AppEnvironment+Live.swift @@ -90,6 +90,7 @@ extension AppEnvironment { messenger: messenger, db: dbManager.getDB ), + log: .live(), mainQueue: mainQueue, bgQueue: bgQueue, welcome: { diff --git a/Examples/xx-messenger/Sources/AppFeature/AppFeature.swift b/Examples/xx-messenger/Sources/AppFeature/AppFeature.swift index 9424cbf2991248fa6369fb44a2a23982ff6fe8d8..caae3368d778873e89af41f51a8a9ecce581866c 100644 --- a/Examples/xx-messenger/Sources/AppFeature/AppFeature.swift +++ b/Examples/xx-messenger/Sources/AppFeature/AppFeature.swift @@ -50,6 +50,7 @@ struct AppEnvironment { var messenger: Messenger var authHandler: AuthCallbackHandler var messageListener: MessageListenerHandler + var log: Logger var mainQueue: AnySchedulerOf<DispatchQueue> var bgQueue: AnySchedulerOf<DispatchQueue> var welcome: () -> WelcomeEnvironment @@ -63,6 +64,7 @@ extension AppEnvironment { messenger: .unimplemented, authHandler: .unimplemented, messageListener: .unimplemented, + log: .unimplemented, mainQueue: .unimplemented, bgQueue: .unimplemented, welcome: { .unimplemented }, @@ -87,10 +89,10 @@ let appReducer = Reducer<AppState, AppAction, AppEnvironment> } cancellables.append(env.authHandler(onError: { error in - // TODO: handle error + env.log(.error(error as NSError)) })) cancellables.append(env.messageListener(onError: { error in - // TODO: handle error + env.log(.error(error as NSError)) })) let isLoaded = env.messenger.isLoaded() diff --git a/Examples/xx-messenger/Tests/AppFeatureTests/AppFeatureTests.swift b/Examples/xx-messenger/Tests/AppFeatureTests/AppFeatureTests.swift index 93d719030e6bd5554465078f957f1e0412c3da76..5bda4eb3f27c96014321e14766017b81a9f05f4e 100644 --- a/Examples/xx-messenger/Tests/AppFeatureTests/AppFeatureTests.swift +++ b/Examples/xx-messenger/Tests/AppFeatureTests/AppFeatureTests.swift @@ -351,6 +351,9 @@ final class AppFeatureTests: XCTestCase { actions.append(.didCancelMessageListener) } } + store.environment.log.run = { msg, _, _, _ in + actions.append(.didLog(msg)) + } store.send(.start) @@ -381,15 +384,21 @@ final class AppFeatureTests: XCTestCase { actions = [] struct AuthError: Error {} - authHandlerOnError.first?(AuthError()) + let authError = AuthError() + authHandlerOnError.first?(authError) - XCTAssertNoDifference(actions, []) + XCTAssertNoDifference(actions, [ + .didLog(.error(authError as NSError)) + ]) actions = [] struct MessageError: Error {} - messageListenerOnError.first?(MessageError()) + let messageError = MessageError() + messageListenerOnError.first?(messageError) - XCTAssertNoDifference(actions, []) + XCTAssertNoDifference(actions, [ + .didLog(.error(messageError as NSError)) + ]) actions = [] store.send(.stop) @@ -408,4 +417,5 @@ private enum Action: Equatable { case didLoadMessenger case didCancelAuthHandler case didCancelMessageListener + case didLog(Logger.Message) }