Skip to content
Snippets Groups Projects
Commit 1d4953ff authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add MyIdentityState.isMakingIdentity property

parent 6853eb53
No related branches found
No related tags found
1 merge request!14[Example App] Make identity & contact
......@@ -7,14 +7,17 @@ import ErrorFeature
public struct MyIdentityState: Equatable {
public init(
id: UUID,
isMakingIdentity: Bool = false,
error: ErrorState? = nil
) {
self.id = id
self.isMakingIdentity = isMakingIdentity
self.error = error
}
public var id: UUID
public var identity: Identity?
public var isMakingIdentity: Bool
public var error: ErrorState?
}
......@@ -23,7 +26,7 @@ public enum MyIdentityAction: Equatable {
case observeMyIdentity
case didUpdateMyIdentity(Identity?)
case makeIdentity
case didFailMakingIdentity(NSError)
case didFinishMakingIdentity(NSError?)
case didDismissError
case error(ErrorAction)
}
......@@ -78,14 +81,14 @@ public let myIdentityReducer = Reducer<MyIdentityState, MyIdentityAction, MyIden
return .none
case .makeIdentity:
return Effect.run { subscriber in
state.isMakingIdentity = true
return Effect.future { fulfill in
do {
env.updateIdentity(try env.getClient()?.makeIdentity())
fulfill(.success(.didFinishMakingIdentity(nil)))
} catch {
subscriber.send(.didFailMakingIdentity(error as NSError))
fulfill(.success(.didFinishMakingIdentity(error as NSError)))
}
subscriber.send(completion: .finished)
return AnyCancellable {}
}
.subscribe(on: env.bgScheduler)
.receive(on: env.mainScheduler)
......@@ -95,8 +98,11 @@ public let myIdentityReducer = Reducer<MyIdentityState, MyIdentityAction, MyIden
state.error = nil
return .none
case .didFailMakingIdentity(let error):
state.error = ErrorState(error: error)
case .didFinishMakingIdentity(let error):
state.isMakingIdentity = false
if let error = error {
state.error = ErrorState(error: error)
}
return .none
}
}
......
......@@ -68,13 +68,19 @@ final class MyIdentityFeatureTests: XCTestCase {
environment: env
)
store.send(.makeIdentity)
store.send(.makeIdentity) {
$0.isMakingIdentity = true
}
bgScheduler.advance()
XCTAssertNoDifference(didUpdateIdentity, [newIdentity])
mainScheduler.advance()
store.receive(.didFinishMakingIdentity(nil)) {
$0.isMakingIdentity = false
}
}
func testMakeIdentityFailure() {
......@@ -97,12 +103,15 @@ final class MyIdentityFeatureTests: XCTestCase {
environment: env
)
store.send(.makeIdentity)
store.send(.makeIdentity) {
$0.isMakingIdentity = true
}
bgScheduler.advance()
mainScheduler.advance()
store.receive(.didFailMakingIdentity(error)) {
store.receive(.didFinishMakingIdentity(error)) {
$0.isMakingIdentity = false
$0.error = ErrorState(error: error)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment