@@ -64,6 +64,16 @@ describe("Proxy OAuth Server Provider", () => {
6464 } ) ;
6565 } ) ;
6666
67+ // Add helper function for failed responses
68+ const mockFailedResponse = ( ) => {
69+ ( global . fetch as jest . Mock ) . mockImplementation ( ( ) =>
70+ Promise . resolve ( {
71+ ok : false ,
72+ status : 400 ,
73+ } )
74+ ) ;
75+ } ;
76+
6777 afterEach ( ( ) => {
6878 global . fetch = originalFetch ;
6979 jest . clearAllMocks ( ) ;
@@ -178,13 +188,7 @@ describe("Proxy OAuth Server Provider", () => {
178188 } ) ;
179189
180190 it ( "handles token exchange failure" , async ( ) => {
181- ( global . fetch as jest . Mock ) . mockImplementation ( ( ) =>
182- Promise . resolve ( {
183- ok : false ,
184- status : 400 ,
185- } )
186- ) ;
187-
191+ mockFailedResponse ( ) ;
188192 await expect (
189193 provider . exchangeAuthorizationCode ( validClient , "invalid-code" )
190194 ) . rejects . toThrow ( ServerError ) ;
@@ -221,13 +225,7 @@ describe("Proxy OAuth Server Provider", () => {
221225 } ) ;
222226
223227 it ( "handles registration failure" , async ( ) => {
224- ( global . fetch as jest . Mock ) . mockImplementation ( ( ) =>
225- Promise . resolve ( {
226- ok : false ,
227- status : 400 ,
228- } )
229- ) ;
230-
228+ mockFailedResponse ( ) ;
231229 const newClient : OAuthClientInformationFull = {
232230 client_id : "new-client" ,
233231 redirect_uris : [ "https://new-client.com/callback" ] ,
@@ -265,13 +263,7 @@ describe("Proxy OAuth Server Provider", () => {
265263 } ) ;
266264
267265 it ( "handles revocation failure" , async ( ) => {
268- ( global . fetch as jest . Mock ) . mockImplementation ( ( ) =>
269- Promise . resolve ( {
270- ok : false ,
271- status : 400 ,
272- } )
273- ) ;
274-
266+ mockFailedResponse ( ) ;
275267 await expect (
276268 provider . revokeToken ! ( validClient , {
277269 token : "invalid-token" ,
0 commit comments