Skip to content

Commit b5c9813

Browse files
test(tables): fix async-import route tests for workspace-scoped fileKey + name uniquification
1 parent 6993ae9 commit b5c9813

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function makeRequest(body: unknown, tableId = 'tbl_1') {
6363

6464
const validBody = {
6565
workspaceId: 'workspace-1',
66-
fileKey: 'workspace/123-data.csv',
66+
fileKey: 'workspace/workspace-1/123-data.csv',
6767
fileName: 'data.csv',
6868
mode: 'append',
6969
}

apps/sim/app/api/table/import-async/route.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@ import { hybridAuthMockFns, permissionsMock, permissionsMockFns } from '@sim/tes
55
import { NextRequest } from 'next/server'
66
import { beforeEach, describe, expect, it, vi } from 'vitest'
77

8-
const { mockCreateTable, mockGetLimits, mockRunTableImport, mockRunDetached } = vi.hoisted(() => ({
8+
const {
9+
mockCreateTable,
10+
mockGetLimits,
11+
mockListTables,
12+
mockRunTableImport,
13+
mockRunDetached,
14+
MockTableConflictError,
15+
} = vi.hoisted(() => ({
916
mockCreateTable: vi.fn(),
1017
mockGetLimits: vi.fn(),
18+
mockListTables: vi.fn(),
1119
mockRunTableImport: vi.fn(),
1220
mockRunDetached: vi.fn(),
21+
MockTableConflictError: class extends Error {
22+
readonly code = 'TABLE_EXISTS' as const
23+
},
1324
}))
1425

1526
vi.mock('@sim/utils/id', () => ({
@@ -20,8 +31,10 @@ vi.mock('@sim/utils/id', () => ({
2031
vi.mock('@/lib/table', () => ({
2132
createTable: mockCreateTable,
2233
getWorkspaceTableLimits: mockGetLimits,
34+
listTables: mockListTables,
2335
sanitizeName: (name: string) => name.replace(/[^a-zA-Z0-9_]/g, '_'),
2436
TABLE_LIMITS: { MAX_TABLE_NAME_LENGTH: 128 },
37+
TableConflictError: MockTableConflictError,
2538
}))
2639
vi.mock('@/lib/table/import-runner', () => ({ runTableImport: mockRunTableImport }))
2740
vi.mock('@/lib/core/utils/background', () => ({
@@ -45,7 +58,7 @@ function makeRequest(body: unknown): NextRequest {
4558

4659
const validBody = {
4760
workspaceId: 'workspace-1',
48-
fileKey: 'workspace/123-data.csv',
61+
fileKey: 'workspace/workspace-1/123-data.csv',
4962
fileName: 'data.csv',
5063
}
5164

@@ -59,6 +72,7 @@ describe('POST /api/table/import-async', () => {
5972
})
6073
permissionsMockFns.mockGetUserEntityPermissions.mockResolvedValue('write')
6174
mockGetLimits.mockResolvedValue({ maxRowsPerTable: 1_000_000, maxTables: 50 })
75+
mockListTables.mockResolvedValue([])
6276
mockCreateTable.mockResolvedValue({ id: 'tbl_async', name: 'data' })
6377
mockRunTableImport.mockResolvedValue(undefined)
6478
})

0 commit comments

Comments
 (0)