@@ -99,6 +99,7 @@ describe('Jira member indexing and authorization in PostgreSQL', () => {
9999 const failures = new Map < string , 400 | 401 > ( )
100100 const requests : { token : string ; page : string | null } [ ] = [ ]
101101 const refreshAttempts : string [ ] = [ ]
102+ let refreshError : 'invalid_grant' | 'unauthorized_client' = 'invalid_grant'
102103 let billing : Awaited < ReturnType < typeof resolveBillingAttribution > >
103104 const actor = ( userId : string ) : Principal => ( {
104105 kind : 'session' ,
@@ -126,10 +127,7 @@ describe('Jira member indexing and authorization in PostgreSQL', () => {
126127 if ( ! person || failures . get ( person . accessToken ) !== 401 )
127128 throw new Error ( 'Unexpected Jira fixture token refresh' )
128129 refreshAttempts . push ( person . userId )
129- return Response . json (
130- { error : 'invalid_grant' , error_description : 'Unknown or invalid refresh token.' } ,
131- { status : 403 }
132- )
130+ return Response . json ( { error : refreshError } , { status : 403 } )
133131 }
134132 const headers = new Headers ( init ?. headers ?? ( input instanceof Request ? input . headers : { } ) )
135133 const token = headers . get ( 'Authorization' ) ?. replace ( / ^ B e a r e r / , '' ) ?? ''
@@ -262,6 +260,7 @@ describe('Jira member indexing and authorization in PostgreSQL', () => {
262260 } )
263261
264262 beforeEach ( async ( ) => {
263+ refreshError = 'invalid_grant'
265264 failures . clear ( )
266265 requests . length = 0
267266 refreshAttempts . length = 0
@@ -526,20 +525,27 @@ describe('Jira member indexing and authorization in PostgreSQL', () => {
526525 await assertAccess ( alice , [ '1' , '2' ] )
527526 } )
528527
529- it ( 'marks a provider-rejected credential for reconnect and immediately hides that member corpus' , async ( ) => {
530- failures . set ( alice . accessToken , 401 )
531- const result = await sync ( )
532- expect ( result . membersFailed ) . toBe ( 1 )
533- expect ( refreshAttempts ) . toEqual ( [ alice . userId ] )
534- const [ saved ] = await db . select ( ) . from ( credential ) . where ( eq ( credential . id , alice . credentialId ) )
535- expect ( saved . managedOauthStatus ) . toBe ( 'needs_reauth' )
536- await assertAccess ( alice , [ ] )
537- await assertAccess ( bob , [ '1' , '3' ] )
538- expect (
539- await db
528+ it . each ( [ 'invalid_grant' , 'unauthorized_client' ] as const ) (
529+ 'marks a %s refresh rejection for reconnect and immediately hides that member corpus' ,
530+ async ( errorCode ) => {
531+ refreshError = errorCode
532+ failures . set ( alice . accessToken , 401 )
533+ const result = await sync ( )
534+ expect ( result . membersFailed ) . toBe ( 1 )
535+ expect ( refreshAttempts ) . toEqual ( [ alice . userId ] )
536+ const [ saved ] = await db
540537 . select ( )
541- . from ( document )
542- . where ( and ( eq ( document . connectorId , connectorId ) , isNull ( document . deletedAt ) ) )
543- ) . toHaveLength ( 4 )
544- } )
538+ . from ( credential )
539+ . where ( eq ( credential . id , alice . credentialId ) )
540+ expect ( saved . managedOauthStatus ) . toBe ( 'needs_reauth' )
541+ await assertAccess ( alice , [ ] )
542+ await assertAccess ( bob , [ '1' , '3' ] )
543+ expect (
544+ await db
545+ . select ( )
546+ . from ( document )
547+ . where ( and ( eq ( document . connectorId , connectorId ) , isNull ( document . deletedAt ) ) )
548+ ) . toHaveLength ( 4 )
549+ }
550+ )
545551} )
0 commit comments