From 5eda3f487f97cc5fd22fe5454ebd3fc7811a9691 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Fri, 30 Sep 2022 12:08:24 +0200 Subject: [PATCH] Improve failure handling in ContactLookupFeature --- .../Sources/ContactLookupFeature/ContactLookupFeature.swift | 4 +++- .../ContactLookupFeatureTests.swift | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift index 82a775dd..0b6f92dd 100644 --- a/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift +++ b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift @@ -57,6 +57,7 @@ public let contactLookupReducer = Reducer<ContactLookupState, ContactLookupActio switch action { case .lookupTapped: state.isLookingUp = true + state.failure = nil return Effect.result { [state] in do { let contact = try env.messenger.lookupContact(id: state.id) @@ -71,11 +72,12 @@ public let contactLookupReducer = Reducer<ContactLookupState, ContactLookupActio case .didLookup(_): state.isLookingUp = false + state.failure = nil return .none case .didFail(let error): - state.failure = error.localizedDescription state.isLookingUp = false + state.failure = error.localizedDescription return .none } } diff --git a/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift b/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift index 34ecabc3..76dde8d0 100644 --- a/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift +++ b/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift @@ -23,12 +23,14 @@ final class ContactLookupFeatureTests: XCTestCase { store.send(.lookupTapped) { $0.isLookingUp = true + $0.failure = nil } XCTAssertEqual(didLookupId, [id]) store.receive(.didLookup(lookedUpContact)) { $0.isLookingUp = false + $0.failure = nil } } @@ -47,11 +49,12 @@ final class ContactLookupFeatureTests: XCTestCase { store.send(.lookupTapped) { $0.isLookingUp = true + $0.failure = nil } store.receive(.didFail(failure)) { - $0.failure = failure.localizedDescription $0.isLookingUp = false + $0.failure = failure.localizedDescription } } } -- GitLab