@@ -13,13 +13,15 @@ const {
1313 mockDispatchAfterBatchInsert,
1414 mockMarkTableImporting,
1515 mockReleaseImportClaim,
16+ mockGetMaxRowsPerTable,
1617} = vi . hoisted ( ( ) => ( {
1718 mockCheckAccess : vi . fn ( ) ,
1819 mockImportAppendRows : vi . fn ( ) ,
1920 mockImportReplaceRows : vi . fn ( ) ,
2021 mockDispatchAfterBatchInsert : vi . fn ( ) ,
2122 mockMarkTableImporting : vi . fn ( ) ,
2223 mockReleaseImportClaim : vi . fn ( ) ,
24+ mockGetMaxRowsPerTable : vi . fn ( ) ,
2325} ) )
2426
2527vi . mock ( '@sim/utils/id' , ( ) => ( {
@@ -65,6 +67,13 @@ vi.mock('@/lib/table/rows/service', () => ({
6567 dispatchAfterBatchInsert : mockDispatchAfterBatchInsert ,
6668} ) )
6769
70+ /** The append pre-check reads the workspace's current plan row limit, not the frozen `table.maxRows`. */
71+ vi . mock ( '@/lib/table/billing' , ( ) => ( {
72+ getMaxRowsPerTable : mockGetMaxRowsPerTable ,
73+ wouldExceedRowLimit : ( limit : number , current : number , added : number ) =>
74+ limit >= 0 && current + added > limit ,
75+ } ) )
76+
6877import { POST } from '@/app/api/table/[tableId]/import/route'
6978
7079function createCsvFile ( contents : string , name = 'data.csv' , type = 'text/csv' ) : File {
@@ -167,6 +176,7 @@ describe('POST /api/table/[tableId]/import', () => {
167176 mockImportReplaceRows . mockResolvedValue ( { deletedCount : 0 , insertedCount : 0 } )
168177 mockMarkTableImporting . mockResolvedValue ( true )
169178 mockReleaseImportClaim . mockResolvedValue ( undefined )
179+ mockGetMaxRowsPerTable . mockResolvedValue ( 1_000_000 )
170180 } )
171181
172182 it ( 'returns 401 when the user is not authenticated' , async ( ) => {
@@ -288,11 +298,9 @@ describe('POST /api/table/[tableId]/import', () => {
288298 expect ( mockImportAppendRows ) . toHaveBeenCalledTimes ( 1 )
289299 } )
290300
291- it ( 'rejects append when it would exceed maxRows' , async ( ) => {
292- mockCheckAccess . mockResolvedValueOnce ( {
293- ok : true ,
294- table : buildTable ( { rowCount : 99 , maxRows : 100 } ) ,
295- } )
301+ it ( 'rejects append when it would exceed the current plan row limit' , async ( ) => {
302+ mockCheckAccess . mockResolvedValueOnce ( { ok : true , table : buildTable ( { rowCount : 99 } ) } )
303+ mockGetMaxRowsPerTable . mockResolvedValueOnce ( 100 )
296304 const response = await callPost (
297305 createFormData ( createCsvFile ( 'name,age\nAlice,30\nBob,40' ) , { mode : 'append' } )
298306 )
0 commit comments