Skip to content

Commit 78744eb

Browse files
committed
test(table): pin the governed subject at the import route, the deletion filter, and the mock
The shared schemaMock lacked `capability_governed_user_id`, so the account-deletion cancellation ran its filter against `undefined` and the test could not tell the governed subject from the billing attribution it replaced. Adds both columns to the mock and asserts the filter names the subject and only the two live statuses.
1 parent b028ce6 commit 78744eb

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

apps/sim/app/api/table/[tableId]/import/route.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ vi.mock('@/app/api/table/utils', async () => {
3838
const { TableLockedError } = await import('@/lib/table/mutation-locks')
3939
return {
4040
checkAccess: mockCheckAccess,
41+
/** Mirrors the real helper: only a `user` principal names a governed subject. */
42+
capabilityGovernedUserId: (principal: { kind: string; userId?: string }) =>
43+
principal.kind === 'user' ? (principal.userId ?? null) : null,
4144
accessError: (result: { status: number }) => {
4245
const message = result.status === 404 ? 'Table not found' : 'Access denied'
4346
return NextResponse.json({ error: message }, { status: result.status })
@@ -281,6 +284,23 @@ describe('POST /api/table/[tableId]/import', () => {
281284
expect(mockImportReplaceRows).not.toHaveBeenCalled()
282285
})
283286

287+
/**
288+
* The appended rows auto-fire the table's workflow columns, and those cells
289+
* gate their tools on the governed subject. Leaving it null ran the importing
290+
* member's cells with no per-tool gate at all.
291+
*/
292+
it('dispatches the auto-fired cells under the person it just gated', async () => {
293+
await callPost(createFormData(createCsvFile('name,age\nAlice,30'), { mode: 'append' }))
294+
295+
expect(mockDispatchAfterBatchInsert).toHaveBeenCalledWith(
296+
expect.anything(),
297+
expect.anything(),
298+
expect.anything(),
299+
'user-1',
300+
'user-1'
301+
)
302+
})
303+
284304
it('accepts chunked multipart imports without a content-length header', async () => {
285305
const form = createFormData(createCsvFile('name,age\nAlice,30'), { mode: 'append' })
286306
const req = new NextRequest('http://localhost:3000/api/table/tbl_1/import', {

apps/sim/background/drain-governed-subject.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,5 @@ describe('draining another dispatch’s pre-stamped marker', () => {
148148
([, , ctx]) => (ctx as { userId: string | null }).userId
149149
)
150150
expect(subjects).toEqual([null, 'requesting-member'])
151-
})
151+
}, 20_000)
152152
})

apps/sim/lib/table/prestamp-governed-subject.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ describe('the dispatcher pre-stamp', () => {
8181
}),
8282
})
8383
)
84-
})
84+
}, 20_000)
8585
})

0 commit comments

Comments
 (0)