@@ -91,3 +91,47 @@ def test_updates_the_authorization_header_on_auth_events() -> None:
9191
9292 assert client .storage .session .headers .get ("apiKey" ) == key
9393 assert client .storage .session .headers .get ("Authorization" ) == updated_authorization
94+
95+
96+ def test_sign_out_resets_auth_headers () -> None :
97+ url = os .environ .get ("SUPABASE_TEST_URL" )
98+ key = os .environ .get ("SUPABASE_TEST_KEY" )
99+
100+ client = create_client (url , key )
101+
102+ mock_session = MagicMock (access_token = "secretuserjwt" )
103+ client ._listen_to_auth_events ("SIGNED_IN" , mock_session )
104+
105+ updated_authorization = f"Bearer { mock_session .access_token } "
106+ assert client .options .headers .get ("Authorization" ) == updated_authorization
107+
108+ client .sign_out ()
109+
110+ assert client .options .headers .get ("Authorization" ) == f"Bearer { key } "
111+ assert client ._postgrest is None
112+ assert client ._storage is None
113+ assert client ._functions is None
114+
115+
116+ def test_sign_out_calls_auth_sign_out () -> None :
117+ url = os .environ .get ("SUPABASE_TEST_URL" )
118+ key = os .environ .get ("SUPABASE_TEST_KEY" )
119+
120+ client = create_client (url , key )
121+ client .auth .sign_out = MagicMock ()
122+
123+ client .sign_out ()
124+
125+ client .auth .sign_out .assert_called_once ()
126+
127+
128+ def test_sign_out_triggers_auth_event () -> None :
129+ url = os .environ .get ("SUPABASE_TEST_URL" )
130+ key = os .environ .get ("SUPABASE_TEST_KEY" )
131+
132+ client = create_client (url , key )
133+ client ._listen_to_auth_events = MagicMock ()
134+
135+ client .sign_out ()
136+
137+ client ._listen_to_auth_events .assert_called_once_with ("SIGNED_OUT" , None )
0 commit comments