@@ -41,7 +41,22 @@ vi.mock('@/app/workspace/[workspaceId]/settings/navigation', () => ({
4141 resolveSettingsSection : vi . fn ( ( section : string ) => {
4242 const aliases : Record < string , string > = { subscription : 'billing' }
4343 const id = aliases [ section ] ?? section
44- return [ 'general' , 'billing' , 'secrets' ] . includes ( id ) ? { id, meta : { title : id } } : null
44+ return [
45+ 'general' ,
46+ 'billing' ,
47+ 'secrets' ,
48+ 'organization' ,
49+ 'usage' ,
50+ 'access-control' ,
51+ 'audit-logs' ,
52+ 'sso' ,
53+ 'sessions' ,
54+ 'data-retention' ,
55+ 'data-drains' ,
56+ 'whitelabeling' ,
57+ ] . includes ( id )
58+ ? { id, meta : { title : id } }
59+ : null
4560 } ) ,
4661} ) )
4762vi . mock ( '@/app/workspace/[workspaceId]/settings/[section]/prefetch' , ( ) => ( {
@@ -51,6 +66,7 @@ vi.mock('@/app/workspace/[workspaceId]/settings/[section]/settings', () => ({
5166 SettingsPage : vi . fn ( ( ) => null ) ,
5267} ) )
5368
69+ import { UNIFIED_TO_ORGANIZATION_SECTION } from '@/components/settings/navigation'
5470import WorkspaceSettingsSectionPage from '@/app/workspace/[workspaceId]/settings/[section]/page'
5571
5672function pageProps ( section : string ) {
@@ -79,7 +95,10 @@ describe('WorkspaceSettingsSectionPage', () => {
7995 } )
8096
8197 it ( 'preserves legacy organization settings query state on the canonical org destination' , async ( ) => {
82- mockGetHostContext . mockResolvedValue ( { hostOrganizationId : 'org-target' } )
98+ mockGetHostContext . mockResolvedValue ( {
99+ hostOrganizationId : 'org-target' ,
100+ features : { organizationSearch : true } ,
101+ } )
83102 await expect (
84103 WorkspaceSettingsSectionPage ( {
85104 ...pageProps ( 'subscription' ) ,
@@ -91,6 +110,53 @@ describe('WorkspaceSettingsSectionPage', () => {
91110 expect ( mockSectionPrefetch ) . not . toHaveBeenCalled ( )
92111 } )
93112
113+ it . each ( Object . entries ( UNIFIED_TO_ORGANIZATION_SECTION ) ) (
114+ 'keeps %s in the workspace outside the organization rollout' ,
115+ async ( section ) => {
116+ mockGetHostContext . mockResolvedValue ( {
117+ hostOrganizationId : 'org-target' ,
118+ features : { organizationSearch : false , knowledgeMemberAccess : true } ,
119+ } )
120+
121+ const element = await WorkspaceSettingsSectionPage ( pageProps ( section ) )
122+
123+ expect ( element ) . toBeTruthy ( )
124+ expect ( mockRedirect ) . not . toHaveBeenCalled ( )
125+ expect ( mockAuthorizeSection ) . toHaveBeenCalledWith ( {
126+ workspaceId : 'workspace-b' ,
127+ userId : 'viewer-a' ,
128+ section,
129+ } )
130+ }
131+ )
132+
133+ it . each ( [ undefined , { credentialGroups : true , knowledgeMemberAccess : true } ] ) (
134+ 'keeps settings in the workspace when older host context omits the org rollout' ,
135+ async ( features ) => {
136+ mockGetHostContext . mockResolvedValue ( { hostOrganizationId : 'org-target' , features } )
137+
138+ await WorkspaceSettingsSectionPage ( pageProps ( 'billing' ) )
139+
140+ expect ( mockRedirect ) . not . toHaveBeenCalled ( )
141+ expect ( mockSectionPrefetch ) . toHaveBeenCalledTimes ( 1 )
142+ }
143+ )
144+
145+ it . each ( Object . entries ( UNIFIED_TO_ORGANIZATION_SECTION ) ) (
146+ 'routes %s to organization %s only within the organization rollout' ,
147+ async ( section , organizationSection ) => {
148+ mockGetHostContext . mockResolvedValue ( {
149+ hostOrganizationId : 'org-target' ,
150+ features : { organizationSearch : true , knowledgeMemberAccess : false } ,
151+ } )
152+
153+ await expect ( WorkspaceSettingsSectionPage ( pageProps ( section ) ) ) . rejects . toThrow (
154+ `NEXT_REDIRECT:/o/org-target/settings/${ organizationSection } `
155+ )
156+ expect ( mockSectionPrefetch ) . not . toHaveBeenCalled ( )
157+ }
158+ )
159+
94160 it ( 'conceals inaccessible workspaces and platform-only sections' , async ( ) => {
95161 mockAuthorizeSection . mockResolvedValue ( { allowed : false , disposition : 'not-found' } )
96162
0 commit comments