@@ -19,6 +19,14 @@ const fakeConsentInfo = {
1919 ] ,
2020} ;
2121
22+ const fakeConsentInfoWithOrgScope = {
23+ ...fakeConsentInfo ,
24+ scopes : [
25+ ...fakeConsentInfo . scopes ,
26+ { scope : 'user:org:read' , description : 'Access your organizations' , requiresConsent : true } ,
27+ ] ,
28+ } ;
29+
2230/**
2331 * `oauthApplication` is a getter on the Clerk prototype and cannot be assigned
2432 * directly. Use Object.defineProperty to replace it with a configurable mock.
@@ -319,7 +327,7 @@ describe('OAuthConsent', () => {
319327 } ) ;
320328
321329 describe ( 'org selection' , ( ) => {
322- it ( 'does not render the org selector when __internal_enableOrgSelection is not set ' , async ( ) => {
330+ it ( 'does not render the org selector when user:org:read scope is absent ' , async ( ) => {
323331 const { wrapper, fixtures, props } = await createFixtures ( f => {
324332 f . withUser ( {
325333 email_addresses : [ 'jane@example.com' ] ,
@@ -339,7 +347,7 @@ describe('OAuthConsent', () => {
339347 } ) ;
340348
341349 it ( 'does not render the org selector when organizations feature is disabled in the dashboard' , async ( ) => {
342- // SDK-63: enableOrgSelection is set but organizationSettings.enabled is false,
350+ // SDK-63: user:org:read scope is present but organizationSettings.enabled is false,
343351 // so no org select and no useOrganizationList call.
344352 const { wrapper, fixtures, props } = await createFixtures ( f => {
345353 f . withUser ( {
@@ -349,8 +357,10 @@ describe('OAuthConsent', () => {
349357 // intentionally NOT calling f.withOrganizations()
350358 } ) ;
351359
352- props . setProps ( { componentName : 'OAuthConsent' , __internal_enableOrgSelection : true } as any ) ;
353- mockOAuthApplication ( fixtures . clerk , { getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfo ) } ) ;
360+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
361+ mockOAuthApplication ( fixtures . clerk , {
362+ getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfoWithOrgScope ) ,
363+ } ) ;
354364
355365 const { queryByRole } = render ( < OAuthConsent /> , { wrapper } ) ;
356366
@@ -359,7 +369,7 @@ describe('OAuthConsent', () => {
359369 } ) ;
360370 } ) ;
361371
362- it ( 'renders the org selector when __internal_enableOrgSelection is true and user has memberships' , async ( ) => {
372+ it ( 'renders the org selector when user:org:read scope is present and user has memberships' , async ( ) => {
363373 const { wrapper, fixtures, props } = await createFixtures ( f => {
364374 f . withUser ( {
365375 email_addresses : [ 'jane@example.com' ] ,
@@ -368,8 +378,10 @@ describe('OAuthConsent', () => {
368378 f . withOrganizations ( ) ;
369379 } ) ;
370380
371- props . setProps ( { componentName : 'OAuthConsent' , __internal_enableOrgSelection : true } as any ) ;
372- mockOAuthApplication ( fixtures . clerk , { getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfo ) } ) ;
381+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
382+ mockOAuthApplication ( fixtures . clerk , {
383+ getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfoWithOrgScope ) ,
384+ } ) ;
373385
374386 const { getByText } = render ( < OAuthConsent /> , { wrapper } ) ;
375387
@@ -378,7 +390,7 @@ describe('OAuthConsent', () => {
378390 } ) ;
379391 } ) ;
380392
381- it ( 'includes a hidden organization_id input when org selection is enabled and user has memberships ' , async ( ) => {
393+ it ( 'renders the org selector when __internal_enableOrgSelection is true (fallback for existing apps) ' , async ( ) => {
382394 const { wrapper, fixtures, props } = await createFixtures ( f => {
383395 f . withUser ( {
384396 email_addresses : [ 'jane@example.com' ] ,
@@ -390,6 +402,48 @@ describe('OAuthConsent', () => {
390402 props . setProps ( { componentName : 'OAuthConsent' , __internal_enableOrgSelection : true } as any ) ;
391403 mockOAuthApplication ( fixtures . clerk , { getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfo ) } ) ;
392404
405+ const { getByText } = render ( < OAuthConsent /> , { wrapper } ) ;
406+
407+ await waitFor ( ( ) => {
408+ expect ( getByText ( 'Acme Corp' ) ) . toBeVisible ( ) ;
409+ } ) ;
410+ } ) ;
411+
412+ it ( 'does not display user:org:read in the scopes list' , async ( ) => {
413+ const { wrapper, fixtures, props } = await createFixtures ( f => {
414+ f . withUser ( {
415+ email_addresses : [ 'jane@example.com' ] ,
416+ organization_memberships : [ { id : 'org_1' , name : 'Acme Corp' } ] ,
417+ } ) ;
418+ f . withOrganizations ( ) ;
419+ } ) ;
420+
421+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
422+ mockOAuthApplication ( fixtures . clerk , {
423+ getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfoWithOrgScope ) ,
424+ } ) ;
425+
426+ const { queryByText } = render ( < OAuthConsent /> , { wrapper } ) ;
427+
428+ await waitFor ( ( ) => {
429+ expect ( queryByText ( 'Access your organizations' ) ) . toBeNull ( ) ;
430+ } ) ;
431+ } ) ;
432+
433+ it ( 'includes a hidden organization_id input when user:org:read scope is present and user has memberships' , async ( ) => {
434+ const { wrapper, fixtures, props } = await createFixtures ( f => {
435+ f . withUser ( {
436+ email_addresses : [ 'jane@example.com' ] ,
437+ organization_memberships : [ { id : 'org_1' , name : 'Acme Corp' } ] ,
438+ } ) ;
439+ f . withOrganizations ( ) ;
440+ } ) ;
441+
442+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
443+ mockOAuthApplication ( fixtures . clerk , {
444+ getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfoWithOrgScope ) ,
445+ } ) ;
446+
393447 const { baseElement } = render ( < OAuthConsent /> , { wrapper } ) ;
394448
395449 await waitFor ( ( ) => {
@@ -400,7 +454,7 @@ describe('OAuthConsent', () => {
400454 } ) ;
401455 } ) ;
402456
403- it ( 'does not include organization_id in the form when org selection is disabled ' , async ( ) => {
457+ it ( 'does not include organization_id in the form when user: org:read scope is absent ' , async ( ) => {
404458 const { wrapper, fixtures, props } = await createFixtures ( f => {
405459 f . withUser ( { email_addresses : [ 'jane@example.com' ] } ) ;
406460 } ) ;
@@ -431,8 +485,10 @@ describe('OAuthConsent', () => {
431485
432486 fixtures . clerk . session . lastActiveOrganizationId = 'org_3' ;
433487
434- props . setProps ( { componentName : 'OAuthConsent' , __internal_enableOrgSelection : true } as any ) ;
435- mockOAuthApplication ( fixtures . clerk , { getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfo ) } ) ;
488+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
489+ mockOAuthApplication ( fixtures . clerk , {
490+ getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfoWithOrgScope ) ,
491+ } ) ;
436492
437493 const { baseElement } = render ( < OAuthConsent /> , { wrapper } ) ;
438494
@@ -458,8 +514,10 @@ describe('OAuthConsent', () => {
458514
459515 fixtures . clerk . session . lastActiveOrganizationId = 'org_deleted' ;
460516
461- props . setProps ( { componentName : 'OAuthConsent' , __internal_enableOrgSelection : true } as any ) ;
462- mockOAuthApplication ( fixtures . clerk , { getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfo ) } ) ;
517+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
518+ mockOAuthApplication ( fixtures . clerk , {
519+ getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfoWithOrgScope ) ,
520+ } ) ;
463521
464522 const { baseElement } = render ( < OAuthConsent /> , { wrapper } ) ;
465523
@@ -485,8 +543,10 @@ describe('OAuthConsent', () => {
485543
486544 fixtures . clerk . session . lastActiveOrganizationId = null ;
487545
488- props . setProps ( { componentName : 'OAuthConsent' , __internal_enableOrgSelection : true } as any ) ;
489- mockOAuthApplication ( fixtures . clerk , { getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfo ) } ) ;
546+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
547+ mockOAuthApplication ( fixtures . clerk , {
548+ getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfoWithOrgScope ) ,
549+ } ) ;
490550
491551 const { baseElement } = render ( < OAuthConsent /> , { wrapper } ) ;
492552
0 commit comments