@@ -150,56 +150,51 @@ describe('Client Singleton', () => {
150150 } ) ;
151151
152152 describe ( '__internal_signOut' , ( ) => {
153- it . each ( [ true , false ] ) (
154- 'returns the response URL and clears sessions with persistClient=%s' ,
155- async persistClient => {
156- const user = createUser ( { id : 'user_1' } ) ;
157- const initial : ClientJSON = {
158- object : 'client' ,
159- id : 'client_before' ,
160- sessions : [ createSession ( { id : 'session_1' } , user ) ] ,
161- sign_in : createSignIn ( { id : 'sign_in_before' } , user ) ,
162- sign_up : createSignUp ( { id : 'sign_up_before' } ) ,
163- last_active_session_id : 'session_1' ,
164- last_authentication_strategy : 'password' ,
165- cookie_expires_at : Date . now ( ) + 30 * 24 * 60 * 60 * 1000 ,
166- created_at : Date . now ( ) - 1000 ,
167- updated_at : Date . now ( ) ,
168- } ;
169- const response = { ...initial , id : 'client_after' , sessions : [ ] , last_active_session_id : null } ;
170- const request = vi . fn ( ) . mockResolvedValue ( { response, sign_out_url : 'https://primary.test/sign-out' } ) ;
171- BaseResource . _fetch = request ;
172- const clearCache = vi . spyOn ( SessionTokenCache , 'clear' ) ;
173- const client = Client . getOrCreateInstance ( ) . fromJSON ( initial ) ;
174- const result = await client . __internal_signOut ( {
175- persistClient,
176- redirectUrl : 'https://satellite.test/after?tab=security#settings' ,
177- } ) ;
178-
179- expect ( request ) . toHaveBeenCalledWith ( {
180- method : 'DELETE' ,
181- path : persistClient ? '/client/sessions' : '/client' ,
182- search : { sign_out_redirect_url : 'https://satellite.test/after?tab=security#settings' } ,
183- } ) ;
184- expect ( result ) . toEqual ( { signOutUrl : 'https://primary.test/sign-out' } ) ;
185- expect ( clearCache ) . toHaveBeenCalledOnce ( ) ;
186- expect ( client . sessions ) . toEqual ( [ ] ) ;
187- expect ( client . id ) . toBe ( persistClient ? 'client_after' : '' ) ;
188- expect ( client . signIn . id ) . toBe ( persistClient ? 'sign_in_before' : undefined ) ;
189- expect ( client . signUp . id ) . toBe ( persistClient ? 'sign_up_before' : undefined ) ;
190- expect ( client . lastActiveSessionId ) . toBeNull ( ) ;
191- expect ( client . lastAuthenticationStrategy ) . toBe ( persistClient ? 'password' : null ) ;
192- expect ( client . cookieExpiresAt ) . toEqual ( persistClient ? new Date ( initial . cookie_expires_at ! ) : null ) ;
193- expect ( client . createdAt ) . toEqual ( persistClient ? new Date ( initial . created_at ! ) : null ) ;
194- expect ( client . updatedAt ) . toEqual ( persistClient ? new Date ( initial . updated_at ! ) : null ) ;
195- clearCache . mockRestore ( ) ;
196- } ,
197- ) ;
153+ it ( 'returns the response URL and clears sessions while retaining the client' , async ( ) => {
154+ const user = createUser ( { id : 'user_1' } ) ;
155+ const initial : ClientJSON = {
156+ object : 'client' ,
157+ id : 'client_before' ,
158+ sessions : [ createSession ( { id : 'session_1' } , user ) ] ,
159+ sign_in : createSignIn ( { id : 'sign_in_before' } , user ) ,
160+ sign_up : createSignUp ( { id : 'sign_up_before' } ) ,
161+ last_active_session_id : 'session_1' ,
162+ last_authentication_strategy : 'password' ,
163+ cookie_expires_at : Date . now ( ) + 30 * 24 * 60 * 60 * 1000 ,
164+ created_at : Date . now ( ) - 1000 ,
165+ updated_at : Date . now ( ) ,
166+ } ;
167+ const response = { ...initial , id : 'client_after' , sessions : [ ] , last_active_session_id : null } ;
168+ const request = vi . fn ( ) . mockResolvedValue ( { response, sign_out_url : 'https://primary.test/sign-out' } ) ;
169+ BaseResource . _fetch = request ;
170+ const clearCache = vi . spyOn ( SessionTokenCache , 'clear' ) ;
171+ const client = Client . getOrCreateInstance ( ) . fromJSON ( initial ) ;
172+ const result = await client . __internal_signOut ( {
173+ redirectUrl : 'https://satellite.test/after?tab=security#settings' ,
174+ } ) ;
175+
176+ expect ( request ) . toHaveBeenCalledWith ( {
177+ method : 'DELETE' ,
178+ path : '/client/sessions' ,
179+ search : { sign_out_redirect_url : 'https://satellite.test/after?tab=security#settings' } ,
180+ } ) ;
181+ expect ( result ) . toEqual ( { signOutUrl : 'https://primary.test/sign-out' } ) ;
182+ expect ( clearCache ) . toHaveBeenCalledOnce ( ) ;
183+ expect ( client . sessions ) . toEqual ( [ ] ) ;
184+ expect ( client . id ) . toBe ( 'client_after' ) ;
185+ expect ( client . signIn . id ) . toBe ( 'sign_in_before' ) ;
186+ expect ( client . signUp . id ) . toBe ( 'sign_up_before' ) ;
187+ expect ( client . lastActiveSessionId ) . toBeNull ( ) ;
188+ expect ( client . lastAuthenticationStrategy ) . toBe ( 'password' ) ;
189+ expect ( client . cookieExpiresAt ) . toEqual ( new Date ( initial . cookie_expires_at ! ) ) ;
190+ expect ( client . createdAt ) . toEqual ( new Date ( initial . created_at ! ) ) ;
191+ expect ( client . updatedAt ) . toEqual ( new Date ( initial . updated_at ! ) ) ;
192+ clearCache . mockRestore ( ) ;
193+ } ) ;
198194
199195 it . each ( [ null , { response : null } ] ) ( 'accepts a response without a sign-out URL' , async response => {
200196 BaseResource . _fetch = vi . fn ( ) . mockResolvedValue ( response ) ;
201197 const result = await Client . getOrCreateInstance ( ) . __internal_signOut ( {
202- persistClient : true ,
203198 redirectUrl : 'https://satellite.test/' ,
204199 } ) ;
205200 expect ( result ) . toEqual ( { signOutUrl : undefined } ) ;
@@ -211,10 +206,10 @@ describe('Client Singleton', () => {
211206 . mockResolvedValueOnce ( { response : null , sign_out_url : 'https://primary.test/sign-out' } )
212207 . mockResolvedValueOnce ( null ) ;
213208 const client = Client . getOrCreateInstance ( ) ;
214- expect ( await client . __internal_signOut ( { persistClient : true , redirectUrl : 'https://satellite.test/' } ) ) . toEqual ( {
209+ expect ( await client . __internal_signOut ( { redirectUrl : 'https://satellite.test/' } ) ) . toEqual ( {
215210 signOutUrl : 'https://primary.test/sign-out' ,
216211 } ) ;
217- expect ( await client . __internal_signOut ( { persistClient : true , redirectUrl : 'https://satellite.test/' } ) ) . toEqual ( {
212+ expect ( await client . __internal_signOut ( { redirectUrl : 'https://satellite.test/' } ) ) . toEqual ( {
218213 signOutUrl : undefined ,
219214 } ) ;
220215 } ) ;
0 commit comments