@@ -24,7 +24,7 @@ vi.mock('@/lib/table/rows/service', () => ({
2424 queryRows : mockQueryRows ,
2525} ) )
2626
27- import { GET } from '@/app/api/table/[tableId]/export/route'
27+ import { GET , HEAD } from '@/app/api/table/[tableId]/export/route'
2828
2929/** Table with an id-native column whose stable id (`col_email`) differs from its display name. */
3030function buildTable ( ) : TableDefinition {
@@ -56,6 +56,13 @@ function callGet(format: string) {
5656 return GET ( req , { params : Promise . resolve ( { tableId : 'tbl_1' } ) } )
5757}
5858
59+ function callHead ( format : string ) {
60+ const req = new NextRequest ( `http://localhost:3000/api/table/tbl_1/export?format=${ format } ` , {
61+ method : 'HEAD' ,
62+ } )
63+ return HEAD ( req , { params : Promise . resolve ( { tableId : 'tbl_1' } ) } )
64+ }
65+
5966describe ( 'table export route — id→name translation' , ( ) => {
6067 beforeEach ( ( ) => {
6168 vi . clearAllMocks ( )
@@ -92,4 +99,12 @@ describe('table export route — id→name translation', () => {
9299 expect ( parsed ) . toEqual ( [ { email : 'a@b.c' , legacy : 'x' } ] )
93100 expect ( JSON . stringify ( parsed ) ) . not . toContain ( 'col_email' )
94101 } )
102+
103+ it ( 'preflights authorization without starting the export query' , async ( ) => {
104+ const res = await callHead ( 'csv' )
105+
106+ expect ( res . status ) . toBe ( 204 )
107+ expect ( mockCheckAccess ) . toHaveBeenCalledWith ( 'tbl_1' , 'user-1' , 'read' )
108+ expect ( mockQueryRows ) . not . toHaveBeenCalled ( )
109+ } )
95110} )
0 commit comments