@@ -633,9 +633,55 @@ describe("AuthService", () => {
633633 expect ( authService . getUserInfo ( ) ) . toBeNull ( )
634634 } )
635635
636- it ( "should parse user info correctly" , async ( ) => {
637- // Set up with credentials
638- const credentials = { clientToken : "test-token" , sessionId : "test-session" }
636+ it ( "should parse user info correctly for personal accounts" , async ( ) => {
637+ // Set up with credentials for personal account (no organizationId)
638+ const credentials = { clientToken : "test-token" , sessionId : "test-session" , organizationId : null }
639+ mockContext . secrets . get . mockResolvedValue ( JSON . stringify ( credentials ) )
640+ await authService . initialize ( )
641+
642+ // Clear previous mock calls
643+ mockFetch . mockClear ( )
644+
645+ // Mock successful responses
646+ mockFetch
647+ . mockResolvedValueOnce ( {
648+ ok : true ,
649+ json : ( ) => Promise . resolve ( { jwt : "jwt-token" } ) ,
650+ } )
651+ . mockResolvedValueOnce ( {
652+ ok : true ,
653+ json : ( ) =>
654+ Promise . resolve ( {
655+ response : {
656+ first_name : "Jane" ,
657+ last_name : "Smith" ,
658+ image_url : "https://example.com/jane.jpg" ,
659+ primary_email_address_id : "email-2" ,
660+ email_addresses : [
661+ { id :
"email-1" , email_address :
"[email protected] " } , 662+ { id :
"email-2" , email_address :
"[email protected] " } , 663+ ] ,
664+ } ,
665+ } ) ,
666+ } )
667+
668+ const timerCallback = vi . mocked ( RefreshTimer ) . mock . calls [ 0 ] [ 0 ] . callback
669+ await timerCallback ( )
670+
671+ // Wait for async operations to complete
672+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) )
673+
674+ const userInfo = authService . getUserInfo ( )
675+ expect ( userInfo ) . toEqual ( {
676+ name : "Jane Smith" ,
677+ 678+ picture : "https://example.com/jane.jpg" ,
679+ } )
680+ } )
681+
682+ it ( "should parse user info correctly for organization accounts" , async ( ) => {
683+ // Set up with credentials for organization account
684+ const credentials = { clientToken : "test-token" , sessionId : "test-session" , organizationId : "org_1" }
639685 mockContext . secrets . get . mockResolvedValue ( JSON . stringify ( credentials ) )
640686 await authService . initialize ( )
641687
@@ -699,8 +745,8 @@ describe("AuthService", () => {
699745 } )
700746
701747 it ( "should handle missing user info fields" , async ( ) => {
702- // Set up with credentials
703- const credentials = { clientToken : "test-token" , sessionId : "test-session" }
748+ // Set up with credentials for personal account (no organizationId)
749+ const credentials = { clientToken : "test-token" , sessionId : "test-session" , organizationId : null }
704750 mockContext . secrets . get . mockResolvedValue ( JSON . stringify ( credentials ) )
705751 await authService . initialize ( )
706752
0 commit comments