@@ -64,6 +64,16 @@ describe("Proxy OAuth Server Provider", () => {
64
64
} ) ;
65
65
} ) ;
66
66
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
+
67
77
afterEach ( ( ) => {
68
78
global . fetch = originalFetch ;
69
79
jest . clearAllMocks ( ) ;
@@ -178,13 +188,7 @@ describe("Proxy OAuth Server Provider", () => {
178
188
} ) ;
179
189
180
190
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 ( ) ;
188
192
await expect (
189
193
provider . exchangeAuthorizationCode ( validClient , "invalid-code" )
190
194
) . rejects . toThrow ( ServerError ) ;
@@ -221,13 +225,7 @@ describe("Proxy OAuth Server Provider", () => {
221
225
} ) ;
222
226
223
227
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 ( ) ;
231
229
const newClient : OAuthClientInformationFull = {
232
230
client_id : "new-client" ,
233
231
redirect_uris : [ "https://new-client.com/callback" ] ,
@@ -265,13 +263,7 @@ describe("Proxy OAuth Server Provider", () => {
265
263
} ) ;
266
264
267
265
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 ( ) ;
275
267
await expect (
276
268
provider . revokeToken ! ( validClient , {
277
269
token : "invalid-token" ,
0 commit comments