File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,27 @@ describe("ApiClient", () => {
135135 } ) ;
136136 } ) ;
137137
138+ it ( "should fall back to unauthenticated endpoint when token is undefined" , async ( ) => {
139+ const mockFetch = jest . spyOn ( global , "fetch" ) ;
140+ mockFetch . mockResolvedValueOnce ( new Response ( null , { status : 200 } ) ) ;
141+
142+ // @ts -expect-error accessing private property for testing
143+ apiClient . getAccessToken = jest . fn ( ) . mockRejectedValue ( undefined ) ;
144+
145+ await apiClient . sendEvents ( mockEvents ) ;
146+
147+ const url = new URL ( "api/private/unauth/telemetry/events" , "https://api.test.com" ) ;
148+ expect ( mockFetch ) . toHaveBeenCalledWith ( url , {
149+ method : "POST" ,
150+ headers : {
151+ "Content-Type" : "application/json" ,
152+ Accept : "application/json" ,
153+ "User-Agent" : "test-user-agent" ,
154+ } ,
155+ body : JSON . stringify ( mockEvents ) ,
156+ } ) ;
157+ } ) ;
158+
138159 it ( "should fall back to unauthenticated endpoint on 401 error" , async ( ) => {
139160 const mockFetch = jest . spyOn ( global , "fetch" ) ;
140161 mockFetch
You can’t perform that action at this time.
0 commit comments