44
55use super :: { invalid_transition, Event , InternalStateMachine , State } ;
66use crate :: { Error , FxaEvent , FxaState , Result } ;
7+ use error_support:: report_error;
78
89pub struct AuthIssuesStateMachine ;
910
@@ -18,13 +19,20 @@ impl InternalStateMachine for AuthIssuesStateMachine {
1819 scopes : scopes. clone ( ) ,
1920 entrypoint : entrypoint. clone ( ) ,
2021 } ) ,
21- FxaEvent :: Disconnect => Ok ( Complete ( FxaState :: Disconnected ) ) ,
22+ FxaEvent :: Disconnect => Ok ( Disconnect ) ,
2223 e => Err ( Error :: InvalidStateTransition ( format ! ( "AuthIssues -> {e}" ) ) ) ,
2324 }
2425 }
2526
2627 fn next_state ( & self , state : State , event : Event ) -> Result < State > {
2728 Ok ( match ( state, event) {
29+ ( Disconnect , DisconnectSuccess ) => Complete ( FxaState :: Disconnected ) ,
30+ ( Disconnect , CallError ) => {
31+ // disconnect() is currently infallible, but let's handle errors anyway in case we
32+ // refactor it in the future.
33+ report_error ! ( "fxa-state-machine-error" , "saw CallError after Disconnect" ) ;
34+ Complete ( FxaState :: Disconnected )
35+ }
2836 ( BeginOAuthFlow { .. } , BeginOAuthFlowSuccess { oauth_url } ) => {
2937 Complete ( FxaState :: Authenticating { oauth_url } )
3038 }
@@ -70,6 +78,14 @@ mod test {
7078 #[ test]
7179 fn test_disconnect ( ) {
7280 let tester = StateMachineTester :: new ( AuthIssuesStateMachine , FxaEvent :: Disconnect ) ;
73- assert_eq ! ( tester. state, Complete ( FxaState :: Disconnected ) ) ;
81+ assert_eq ! ( tester. state, Disconnect ) ;
82+ assert_eq ! (
83+ tester. peek_next_state( CallError ) ,
84+ Complete ( FxaState :: Disconnected )
85+ ) ;
86+ assert_eq ! (
87+ tester. peek_next_state( DisconnectSuccess ) ,
88+ Complete ( FxaState :: Disconnected )
89+ ) ;
7490 }
7591}
0 commit comments