22import { authMockFns } from '@sim/testing'
33import { beforeEach , describe , expect , it , vi } from 'vitest'
44
5- const { redirect } = vi . hoisted ( ( ) => ( { redirect : vi . fn ( ) } ) )
5+ const { redirect, organizationContext } = vi . hoisted ( ( ) => ( {
6+ redirect : vi . fn ( ) ,
7+ organizationContext : vi . fn ( ) ,
8+ } ) )
69vi . mock ( 'next/navigation' , ( ) => ( { redirect } ) )
10+ vi . mock ( '@/lib/organizations/surface' , ( ) => ( {
11+ getOrganizationSurfaceContext : organizationContext ,
12+ } ) )
713vi . mock ( '@/ee/access-requests/components/my-access-requests' , ( ) => ( {
814 MyAccessRequests : ( ) => null ,
915} ) )
@@ -12,6 +18,7 @@ vi.mock('@/ee/access-requests/components/organization-access-requests', () => ({
1218} ) )
1319
1420import AccessRequestsPage from '@/app/access-requests/page'
21+ import { MyAccessRequests } from '@/ee/access-requests/components/my-access-requests'
1522
1623describe ( 'access request sign-in redirect' , ( ) => {
1724 beforeEach ( ( ) => {
@@ -67,4 +74,71 @@ describe('access request sign-in redirect', () => {
6774 `/login?callbackUrl=${ encodeURIComponent ( '/access-requests?organizationId=organization' ) } `
6875 )
6976 } )
77+
78+ it ( 'opens saved requester links in the organization shell with their filters and selection' , async ( ) => {
79+ authMockFns . mockGetSession . mockResolvedValue ( { user : { id : 'viewer' } } )
80+ organizationContext . mockResolvedValue ( { searchAccess : { memberScoped : true } } )
81+ await expect (
82+ AccessRequestsPage ( {
83+ searchParams : Promise . resolve ( {
84+ organizationId : 'organization' ,
85+ view : 'catalog' ,
86+ requestId : 'request/a' ,
87+ search : 'Slack & Notion' ,
88+ page : '3' ,
89+ callbackUrl : 'https://example.com/untrusted' ,
90+ } ) ,
91+ } )
92+ ) . rejects . toThrow ( 'Redirect' )
93+ expect ( organizationContext ) . toHaveBeenCalledWith ( 'organization' , 'viewer' )
94+ const destination = new URL ( redirect . mock . calls [ 0 ] [ 0 ] , 'https://example.com' )
95+ expect ( destination . pathname ) . toBe ( '/o/organization/access-requests' )
96+ expect ( Object . fromEntries ( destination . searchParams ) ) . toEqual ( {
97+ view : 'catalog' ,
98+ requestId : 'request/a' ,
99+ search : 'Slack & Notion' ,
100+ page : '3' ,
101+ } )
102+ } )
103+
104+ it . each ( [ null , { searchAccess : { memberScoped : false } } ] ) (
105+ 'keeps the standalone route when the organization surface is unavailable: %j' ,
106+ async ( context ) => {
107+ authMockFns . mockGetSession . mockResolvedValue ( { user : { id : 'viewer' } } )
108+ organizationContext . mockResolvedValue ( context )
109+ await AccessRequestsPage ( {
110+ searchParams : Promise . resolve ( { organizationId : 'organization' } ) ,
111+ } )
112+ expect ( redirect ) . not . toHaveBeenCalled ( )
113+ }
114+ )
115+
116+ it ( 'keeps authenticated administrator email links on the review surface' , async ( ) => {
117+ authMockFns . mockGetSession . mockResolvedValue ( { user : { id : 'viewer' } } )
118+ await AccessRequestsPage ( {
119+ searchParams : Promise . resolve ( {
120+ organizationId : 'organization' ,
121+ view : 'admin' ,
122+ requestId : 'request' ,
123+ } ) ,
124+ } )
125+ expect ( redirect ) . not . toHaveBeenCalled ( )
126+ expect ( organizationContext ) . not . toHaveBeenCalled ( )
127+ } )
128+
129+ it ( 'renders the standalone requester when the optional organization navigation lookup fails' , async ( ) => {
130+ authMockFns . mockGetSession . mockResolvedValue ( { user : { id : 'viewer' } } )
131+ organizationContext . mockRejectedValue ( new Error ( 'Organization context unavailable' ) )
132+
133+ const page = await AccessRequestsPage ( {
134+ searchParams : Promise . resolve ( { organizationId : 'organization' , requestId : 'request' } ) ,
135+ } )
136+
137+ expect ( redirect ) . not . toHaveBeenCalled ( )
138+ expect ( page . props . children . type ) . toBe ( MyAccessRequests )
139+ expect ( page . props . children . props ) . toEqual ( {
140+ scope : { kind : 'organization' , organizationId : 'organization' } ,
141+ standalone : true ,
142+ } )
143+ } )
70144} )
0 commit comments