@@ -246,100 +246,6 @@ describe('Clerk singleton', () => {
246246 await sut . setActive ( { session : mockSession as any as ActiveSessionResource } ) ;
247247 } ) ;
248248
249- it ( 'calls __unstable__onAfterSetActive after beforeEmit and session.touch' , async ( ) => {
250- const beforeEmitMock = vi . fn ( ) ;
251- mockSession . touch . mockReturnValueOnce ( Promise . resolve ( ) ) ;
252- mockClientFetch . mockReturnValue ( Promise . resolve ( { signedInSessions : [ mockSession ] } ) ) ;
253-
254- ( window as any ) . __unstable__onAfterSetActive = ( ) => {
255- expect ( mockSession . touch ) . toHaveBeenCalled ( ) ;
256- expect ( beforeEmitMock ) . toHaveBeenCalled ( ) ;
257- } ;
258-
259- const sut = new Clerk ( productionPublishableKey ) ;
260- await sut . load ( ) ;
261- await sut . setActive ( { session : mockSession as any as ActiveSessionResource , beforeEmit : beforeEmitMock } ) ;
262- } ) ;
263-
264- // TODO: @dimkl include set transitive state
265- it ( 'calls session.touch -> set cookie -> before emit with touched session on session switch' , async ( ) => {
266- const mockSession2 = {
267- id : '2' ,
268- remove : vi . fn ( ) ,
269- status : 'active' ,
270- user : { } ,
271- touch : vi . fn ( ) ,
272- getToken : vi . fn ( ) ,
273- } ;
274- mockClientFetch . mockReturnValue (
275- Promise . resolve ( {
276- signedInSessions : [ mockSession , mockSession2 ] ,
277- } ) ,
278- ) ;
279-
280- const sut = new Clerk ( productionPublishableKey ) ;
281- await sut . load ( ) ;
282-
283- const executionOrder : string [ ] = [ ] ;
284- mockSession2 . touch . mockImplementationOnce ( ( ) => {
285- sut . session = mockSession2 as any ;
286- executionOrder . push ( 'session.touch' ) ;
287- return Promise . resolve ( ) ;
288- } ) ;
289- mockSession2 . getToken . mockImplementation ( ( ) => {
290- executionOrder . push ( 'set cookie' ) ;
291- return 'mocked-token-2' ;
292- } ) ;
293- const beforeEmitMock = vi . fn ( ) . mockImplementationOnce ( ( ) => {
294- executionOrder . push ( 'before emit' ) ;
295- return Promise . resolve ( ) ;
296- } ) ;
297-
298- await sut . setActive ( { session : mockSession2 as any as ActiveSessionResource , beforeEmit : beforeEmitMock } ) ;
299-
300- await waitFor ( ( ) => {
301- expect ( executionOrder ) . toEqual ( [ 'session.touch' , 'set cookie' , 'before emit' ] ) ;
302- expect ( mockSession2 . touch ) . toHaveBeenCalled ( ) ;
303- expect ( mockSession2 . getToken ) . toHaveBeenCalled ( ) ;
304- expect ( beforeEmitMock ) . toHaveBeenCalledWith ( mockSession2 ) ;
305- expect ( sut . session ) . toMatchObject ( mockSession2 ) ;
306- } ) ;
307- } ) ;
308-
309- // TODO: @dimkl include set transitive state
310- it ( 'calls with lastActiveOrganizationId session.touch -> set cookie -> before emit -> set accessors with touched session on organization switch' , async ( ) => {
311- mockClientFetch . mockReturnValue ( Promise . resolve ( { signedInSessions : [ mockSession ] } ) ) ;
312- const sut = new Clerk ( productionPublishableKey ) ;
313- await sut . load ( ) ;
314-
315- const executionOrder : string [ ] = [ ] ;
316- mockSession . touch . mockImplementationOnce ( ( ) => {
317- sut . session = mockSession as any ;
318- executionOrder . push ( 'session.touch' ) ;
319- return Promise . resolve ( ) ;
320- } ) ;
321- mockSession . getToken . mockImplementation ( ( ) => {
322- executionOrder . push ( 'set cookie' ) ;
323- return 'mocked-token' ;
324- } ) ;
325-
326- const beforeEmitMock = vi . fn ( ) . mockImplementationOnce ( ( ) => {
327- executionOrder . push ( 'before emit' ) ;
328- return Promise . resolve ( ) ;
329- } ) ;
330-
331- await sut . setActive ( { organization : { id : 'org_id' } as Organization , beforeEmit : beforeEmitMock } ) ;
332-
333- await waitFor ( ( ) => {
334- expect ( executionOrder ) . toEqual ( [ 'session.touch' , 'set cookie' , 'before emit' ] ) ;
335- expect ( mockSession . touch ) . toHaveBeenCalled ( ) ;
336- expect ( mockSession . getToken ) . toHaveBeenCalled ( ) ;
337- expect ( ( mockSession as any as ActiveSessionResource ) ?. lastActiveOrganizationId ) . toEqual ( 'org_id' ) ;
338- expect ( beforeEmitMock ) . toHaveBeenCalledWith ( mockSession ) ;
339- expect ( sut . session ) . toMatchObject ( mockSession ) ;
340- } ) ;
341- } ) ;
342-
343249 it ( 'sets active organization by slug' , async ( ) => {
344250 const mockSession2 = {
345251 id : '1' ,
@@ -465,24 +371,16 @@ describe('Clerk singleton', () => {
465371 const sut = new Clerk ( productionPublishableKey ) ;
466372 await sut . load ( { standardBrowser : false } ) ;
467373
468- const executionOrder : string [ ] = [ ] ;
469374 mockSession . touch . mockImplementationOnce ( ( ) => {
470375 sut . session = mockSession as any ;
471- executionOrder . push ( 'session.touch' ) ;
472- return Promise . resolve ( ) ;
473- } ) ;
474- const beforeEmitMock = vi . fn ( ) . mockImplementationOnce ( ( ) => {
475- executionOrder . push ( 'before emit' ) ;
476376 return Promise . resolve ( ) ;
477377 } ) ;
478378
479- await sut . setActive ( { organization : { id : 'org_id' } as Organization , beforeEmit : beforeEmitMock } ) ;
379+ await sut . setActive ( { organization : { id : 'org_id' } as Organization } ) ;
480380
481- expect ( executionOrder ) . toEqual ( [ 'session.touch' , 'before emit' ] ) ;
482381 expect ( mockSession . touch ) . toHaveBeenCalled ( ) ;
483382 expect ( ( mockSession as any as ActiveSessionResource ) ?. lastActiveOrganizationId ) . toEqual ( 'org_id' ) ;
484383 expect ( mockSession . getToken ) . toHaveBeenCalled ( ) ;
485- expect ( beforeEmitMock ) . toHaveBeenCalledWith ( mockSession ) ;
486384 expect ( sut . session ) . toMatchObject ( mockSession ) ;
487385 } ) ;
488386 } ) ;
0 commit comments