@@ -15,7 +15,7 @@ import {
1515} from './auth.js' ;
1616import { ServerError } from '../server/auth/errors.js' ;
1717import { AuthorizationServerMetadata } from '../shared/auth.js' ;
18- import { vi , type Mock } from 'vitest' ;
18+ import { expect , vi , type Mock } from 'vitest' ;
1919
2020// Mock pkce-challenge
2121vi . mock ( 'pkce-challenge' , ( ) => ( {
@@ -1119,12 +1119,21 @@ describe('OAuth Authorization', () => {
11191119 } ) ;
11201120
11211121 expect ( tokens ) . toEqual ( validTokens ) ;
1122- expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 ) ;
1123- expect ( mockFetch . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe ( 'https://auth.example.com/token' ) ;
1124- expect ( mockFetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'POST' ) ;
1125- expect ( mockFetch . mock . calls [ 0 ] [ 1 ] . headers . get ( 'Content-Type' ) ) . toBe ( 'application/x-www-form-urlencoded' ) ;
1122+ expect ( mockFetch ) . toHaveBeenCalledWith (
1123+ expect . objectContaining ( {
1124+ href : 'https://auth.example.com/token'
1125+ } ) ,
1126+ expect . objectContaining ( {
1127+ method : 'POST'
1128+ } )
1129+ ) ;
11261130
1127- const body = mockFetch . mock . calls [ 0 ] [ 1 ] . body as URLSearchParams ;
1131+ const options = mockFetch . mock . calls [ 0 ] [ 1 ] ;
1132+ expect ( options . headers ) . toBeInstanceOf ( Headers ) ;
1133+ expect ( options . headers . get ( 'Content-Type' ) ) . toBe ( 'application/x-www-form-urlencoded' ) ;
1134+ expect ( options . body ) . toBeInstanceOf ( URLSearchParams ) ;
1135+
1136+ const body = options . body as URLSearchParams ;
11281137 expect ( body . get ( 'grant_type' ) ) . toBe ( 'authorization_code' ) ;
11291138 expect ( body . get ( 'code' ) ) . toBe ( 'code123' ) ;
11301139 expect ( body . get ( 'code_verifier' ) ) . toBe ( 'verifier123' ) ;
0 commit comments