@@ -219,6 +219,38 @@ describe(SessionManager, () => {
219219 await sessionManager . logoutAsync ( ) ;
220220 expect ( sessionManager [ 'getSessionSecret' ] ( ) ) . toBe ( null ) ;
221221 } ) ;
222+
223+ it ( 'calls the server logout endpoint when session secret exists' , async ( ) => {
224+ jest . mocked ( fetchSessionSecretAndUserAsync ) . mockResolvedValue ( {
225+ sessionSecret : 'SESSION_SECRET' ,
226+ id : 'USER_ID' ,
227+ username : 'USERNAME' ,
228+ } ) ;
229+ const apiV2PostSpy = jest . spyOn ( ApiV2Client . prototype , 'postAsync' ) ;
230+
231+ const sessionManager = new SessionManager ( analytics ) ;
232+ await sessionManager [ 'loginAsync' ] ( { username : 'USERNAME' , password : 'PASSWORD' } ) ;
233+ await sessionManager . logoutAsync ( ) ;
234+
235+ expect ( apiV2PostSpy ) . toHaveBeenCalledWith ( 'auth/logout' , { body : { } } ) ;
236+ } ) ;
237+
238+ it ( 'clears the local session even if the server logout call fails' , async ( ) => {
239+ jest . mocked ( fetchSessionSecretAndUserAsync ) . mockResolvedValue ( {
240+ sessionSecret : 'SESSION_SECRET' ,
241+ id : 'USER_ID' ,
242+ username : 'USERNAME' ,
243+ } ) ;
244+ jest
245+ . spyOn ( ApiV2Client . prototype , 'postAsync' )
246+ . mockRejectedValueOnce ( new Error ( 'Network error' ) ) ;
247+
248+ const sessionManager = new SessionManager ( analytics ) ;
249+ await sessionManager [ 'loginAsync' ] ( { username : 'USERNAME' , password : 'PASSWORD' } ) ;
250+ await sessionManager . logoutAsync ( ) ;
251+
252+ expect ( sessionManager [ 'getSessionSecret' ] ( ) ) . toBe ( null ) ;
253+ } ) ;
222254 } ) ;
223255
224256 describe ( 'showLoginPromptAsync' , ( ) => {
0 commit comments