@@ -137,7 +137,7 @@ describe("NylasConnect (fundamentals)", () => {
137137 expect ( localStorage . getItem ( "@nylas/connect:token_g" ) ) . toBeNull ( ) ;
138138 } ) ;
139139
140- it ( "enableDebug() and disableDebug() control logger levels correctly" , ( ) => {
140+ it ( "setLogLevel controls logger levels correctly" , ( ) => {
141141 const auth = new NylasConnect ( {
142142 clientId,
143143 redirectUri,
@@ -153,43 +153,7 @@ describe("NylasConnect (fundamentals)", () => {
153153 } ;
154154
155155 try {
156- // Test enableDebug - should enable debug level logging
157- auth . enableDebug ( ) ;
158-
159- // Reset spies
160- Object . values ( consoleSpy ) . forEach ( ( spy ) => spy . mockClear ( ) ) ;
161-
162- // Test that debug messages now show
163- logger . debug ( "test debug message" ) ;
164- logger . info ( "test info message" ) ;
165-
166- expect ( consoleSpy . log ) . toHaveBeenCalledWith (
167- expect . stringMatching ( / \[ .* \] \[ N Y L A S - A U T H \] \[ D E B U G \] / ) ,
168- "test debug message" ,
169- ) ;
170- expect ( consoleSpy . info ) . toHaveBeenCalledWith (
171- expect . stringMatching ( / \[ .* \] \[ N Y L A S - A U T H \] \[ I N F O \] / ) ,
172- "test info message" ,
173- ) ;
174-
175- // Test disableDebug - should disable all logging
176- auth . disableDebug ( ) ;
177-
178- // Reset spies
179- Object . values ( consoleSpy ) . forEach ( ( spy ) => spy . mockClear ( ) ) ;
180-
181- // Test that no messages show now
182- logger . debug ( "debug should not show" ) ;
183- logger . info ( "info should not show" ) ;
184- logger . warn ( "warn should not show" ) ;
185- logger . error ( "error should not show" ) ;
186-
187- expect ( consoleSpy . log ) . not . toHaveBeenCalled ( ) ;
188- expect ( consoleSpy . info ) . not . toHaveBeenCalled ( ) ;
189- expect ( consoleSpy . warn ) . not . toHaveBeenCalled ( ) ;
190- expect ( consoleSpy . error ) . not . toHaveBeenCalled ( ) ;
191-
192- // Test setLogLevel method
156+ // Set WARN level - only warn and error messages should show
193157 auth . setLogLevel ( LogLevel . WARN ) ;
194158
195159 // Reset spies
@@ -211,6 +175,18 @@ describe("NylasConnect (fundamentals)", () => {
211175 expect . stringMatching ( / \[ .* \] \[ N Y L A S - A U T H \] \[ E R R O R \] / ) ,
212176 "error should show" ,
213177 ) ;
178+
179+ // Disable all logs
180+ auth . setLogLevel ( "off" ) ;
181+ Object . values ( consoleSpy ) . forEach ( ( spy ) => spy . mockClear ( ) ) ;
182+ logger . debug ( "debug off" ) ;
183+ logger . info ( "info off" ) ;
184+ logger . warn ( "warn off" ) ;
185+ logger . error ( "error off" ) ;
186+ expect ( consoleSpy . log ) . not . toHaveBeenCalled ( ) ;
187+ expect ( consoleSpy . info ) . not . toHaveBeenCalled ( ) ;
188+ expect ( consoleSpy . warn ) . not . toHaveBeenCalled ( ) ;
189+ expect ( consoleSpy . error ) . not . toHaveBeenCalled ( ) ;
214190 } finally {
215191 // Clean up spies
216192 Object . values ( consoleSpy ) . forEach ( ( spy ) => spy . mockRestore ( ) ) ;
@@ -672,84 +648,6 @@ describe("NylasConnect (sessions, validation, and events)", () => {
672648 expect ( localStorage . getItem ( "@nylas/connect:token_default" ) ) . toBeNull ( ) ;
673649 } ) ;
674650
675- it ( "validateToken returns true when response ok and has data" , async ( ) => {
676- const auth = new NylasConnect ( {
677- clientId,
678- redirectUri,
679- apiUrl : "https://api.nylas.com" ,
680- } ) ;
681-
682- const validSession = {
683- accessToken : "t_ok" ,
684- idToken : "h.e.y" ,
685- grantId : "g_ok" ,
686- expiresAt : Date . now ( ) + 60_000 ,
687- scope : "email" ,
688- } ;
689- localStorage . setItem (
690- "@nylas/connect:token_default" ,
691- JSON . stringify ( validSession ) ,
692- ) ;
693-
694- const spy = vi . fn ( ) ;
695- auth . onConnectStateChange ( spy ) ;
696-
697- vi . stubGlobal (
698- "fetch" ,
699- vi . fn ( ) . mockResolvedValue ( {
700- ok : true ,
701- json : async ( ) => ( { data : { grant_id : "g_ok" } } ) ,
702- } ) ,
703- ) ;
704-
705- const result = await auth . validateToken ( ) ;
706- expect ( result ) . toBe ( true ) ;
707- expect ( spy ) . not . toHaveBeenCalledWith (
708- "TOKEN_VALIDATION_ERROR" ,
709- expect . anything ( ) ,
710- expect . anything ( ) ,
711- ) ;
712- } ) ;
713-
714- it ( "validateToken returns false and emits TOKEN_VALIDATION_ERROR when invalid" , async ( ) => {
715- const auth = new NylasConnect ( {
716- clientId,
717- redirectUri,
718- apiUrl : "https://api.nylas.com" ,
719- } ) ;
720-
721- const session = {
722- accessToken : "t_bad" ,
723- idToken : "h.e.y" ,
724- grantId : "g_bad" ,
725- expiresAt : Date . now ( ) + 60_000 ,
726- scope : "email" ,
727- } ;
728- localStorage . setItem (
729- "@nylas/connect:token_default" ,
730- JSON . stringify ( session ) ,
731- ) ;
732-
733- const spy = vi . fn ( ) ;
734- auth . onConnectStateChange ( spy ) ;
735-
736- vi . stubGlobal (
737- "fetch" ,
738- vi . fn ( ) . mockResolvedValue ( {
739- ok : true ,
740- json : async ( ) => ( { } ) ,
741- } ) ,
742- ) ;
743-
744- const result = await auth . validateToken ( ) ;
745- expect ( result ) . toBe ( false ) ;
746- expect ( spy ) . toHaveBeenCalledWith (
747- "TOKEN_VALIDATION_ERROR" ,
748- null ,
749- expect . objectContaining ( { grantId : "g_bad" } ) ,
750- ) ;
751- } ) ;
752-
753651 it ( "onAuthStateChange unsubscribe stops subsequent emissions" , async ( ) => {
754652 const auth = new NylasConnect ( {
755653 clientId,
@@ -769,48 +667,6 @@ describe("NylasConnect (sessions, validation, and events)", () => {
769667 expect ( spy ) . not . toHaveBeenCalled ( ) ;
770668 } ) ;
771669
772- it ( "getGrantInfo emits GRANT_PROFILE_LOADED with source 'token'" , async ( ) => {
773- const auth = new NylasConnect ( {
774- clientId,
775- redirectUri,
776- apiUrl : "https://api.nylas.com" ,
777- } ) ;
778-
779- const grantInfo = {
780- id : "user_1" ,
781- email : "alice@example.com" ,
782- name : "Alice" ,
783- picture : "https://example.com/p.png" ,
784- provider : "google" ,
785- emailVerified : true ,
786- } ;
787-
788- const session = {
789- accessToken : "t" ,
790- idToken : "h.e.y" ,
791- grantId : "g1" ,
792- expiresAt : Date . now ( ) + 60_000 ,
793- scope : "email profile" ,
794- grantInfo,
795- } ;
796- localStorage . setItem (
797- "@nylas/connect:token_default" ,
798- JSON . stringify ( session ) ,
799- ) ;
800-
801- const spy = vi . fn ( ) ;
802- auth . onConnectStateChange ( spy ) ;
803-
804- const result = await auth . getGrantInfo ( ) ;
805- expect ( result ) . toEqual ( grantInfo ) ;
806-
807- expect ( spy ) . toHaveBeenCalledWith (
808- "GRANT_PROFILE_LOADED" ,
809- expect . objectContaining ( { grantId : "g1" } ) ,
810- { grantInfo, source : "token" } ,
811- ) ;
812- } ) ;
813-
814670 describe ( "getConnectionStatus" , ( ) => {
815671 it ( "returns not_connected when no session" , async ( ) => {
816672 const auth = new NylasConnect ( {
0 commit comments