@@ -39,6 +39,12 @@ vi.mock('@/app/api/table/utils', async () => {
3939 { error : error . message } ,
4040 { status : error . code === 'FILE_TOO_LARGE' ? 413 : 400 }
4141 ) ,
42+ rowWriteErrorResponse : ( error : unknown ) => {
43+ const message = error instanceof Error ? error . message : String ( error )
44+ return message . includes ( 'row limit' )
45+ ? NextResponse . json ( { error : message } , { status : 400 } )
46+ : null
47+ } ,
4248 }
4349} )
4450vi . mock ( '@/lib/workspaces/permissions/utils' , ( ) => permissionsMock )
@@ -175,6 +181,17 @@ describe('POST /api/table/import-csv', () => {
175181 expect ( mockCreateTable ) . not . toHaveBeenCalled ( )
176182 } )
177183
184+ it ( 'returns 400 with the reason when an insert exceeds the plan row limit' , async ( ) => {
185+ mockBatchInsertRows . mockRejectedValueOnce (
186+ new Error ( 'This table has reached its row limit (1,000 rows) on your current plan.' )
187+ )
188+ const response = await POST ( makeRequest ( uploadParts ( csvWithRows ( 250 ) ) ) )
189+ const data = await response . json ( )
190+
191+ expect ( response . status ) . toBe ( 400 )
192+ expect ( data . error ) . toMatch ( / r o w l i m i t / )
193+ } )
194+
178195 it ( 'rolls back the created table when a batch insert fails mid-stream' , async ( ) => {
179196 mockBatchInsertRows
180197 . mockResolvedValueOnce ( Array . from ( { length : 100 } , ( ) => ( { id : 'row' } ) ) )
0 commit comments