Skip to content

Commit 3c470ab

Browse files
authored
fix(workflows): disallow duplicate workflow names at the same folder level (#3260)
1 parent 2b5e436 commit 3c470ab

File tree

28 files changed

+639
-261
lines changed

28 files changed

+639
-261
lines changed

apps/sim/app/api/auth/oauth/token/route.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @vitest-environment node
55
*/
6-
import { createMockLogger, createMockRequest } from '@sim/testing'
6+
import { createMockLogger, createMockRequest, mockHybridAuth } from '@sim/testing'
77
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
88

99
describe('OAuth Token API Routes', () => {
@@ -12,7 +12,7 @@ describe('OAuth Token API Routes', () => {
1212
const mockRefreshTokenIfNeeded = vi.fn()
1313
const mockGetOAuthToken = vi.fn()
1414
const mockAuthorizeCredentialUse = vi.fn()
15-
const mockCheckSessionOrInternalAuth = vi.fn()
15+
let mockCheckSessionOrInternalAuth: ReturnType<typeof vi.fn>
1616

1717
const mockLogger = createMockLogger()
1818

@@ -41,9 +41,7 @@ describe('OAuth Token API Routes', () => {
4141
authorizeCredentialUse: mockAuthorizeCredentialUse,
4242
}))
4343

44-
vi.doMock('@/lib/auth/hybrid', () => ({
45-
checkSessionOrInternalAuth: mockCheckSessionOrInternalAuth,
46-
}))
44+
;({ mockCheckSessionOrInternalAuth } = mockHybridAuth())
4745
})
4846

4947
afterEach(() => {
@@ -73,23 +71,18 @@ describe('OAuth Token API Routes', () => {
7371
refreshed: false,
7472
})
7573

76-
// Create mock request
7774
const req = createMockRequest('POST', {
7875
credentialId: 'credential-id',
7976
})
8077

81-
// Import handler after setting up mocks
8278
const { POST } = await import('@/app/api/auth/oauth/token/route')
8379

84-
// Call handler
8580
const response = await POST(req)
8681
const data = await response.json()
8782

88-
// Verify request was handled correctly
8983
expect(response.status).toBe(200)
9084
expect(data).toHaveProperty('accessToken', 'fresh-token')
9185

92-
// Verify mocks were called correctly
9386
expect(mockAuthorizeCredentialUse).toHaveBeenCalled()
9487
expect(mockGetCredential).toHaveBeenCalled()
9588
expect(mockRefreshTokenIfNeeded).toHaveBeenCalled()

apps/sim/app/api/chat/[identifier]/route.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @vitest-environment node
55
*/
6-
import { loggerMock } from '@sim/testing'
6+
import { loggerMock, requestUtilsMock } from '@sim/testing'
77
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
88

99
/**
@@ -94,9 +94,7 @@ vi.mock('@/lib/core/utils/sse', () => ({
9494
},
9595
}))
9696

97-
vi.mock('@/lib/core/utils/request', () => ({
98-
generateRequestId: vi.fn().mockReturnValue('test-request-id'),
99-
}))
97+
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
10098

10199
vi.mock('@/lib/core/security/encryption', () => ({
102100
decryptSecret: vi.fn().mockResolvedValue({ decrypted: 'test-password' }),

apps/sim/app/api/chat/utils.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { databaseMock, loggerMock } from '@sim/testing'
1+
import { databaseMock, loggerMock, requestUtilsMock } from '@sim/testing'
22
import type { NextResponse } from 'next/server'
33
/**
44
* Tests for chat API utils
@@ -37,9 +37,7 @@ vi.mock('@/lib/core/security/encryption', () => ({
3737
decryptSecret: mockDecryptSecret,
3838
}))
3939

40-
vi.mock('@/lib/core/utils/request', () => ({
41-
generateRequestId: vi.fn(),
42-
}))
40+
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
4341

4442
vi.mock('@/lib/core/config/feature-flags', () => ({
4543
isDev: true,

apps/sim/app/api/files/delete/route.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
createMockRequest,
33
mockAuth,
44
mockCryptoUuid,
5+
mockHybridAuth,
56
mockUuid,
67
setupCommonApiMocks,
78
} from '@sim/testing'
@@ -28,13 +29,12 @@ function setupFileApiMocks(
2829
authMocks.setUnauthenticated()
2930
}
3031

31-
vi.doMock('@/lib/auth/hybrid', () => ({
32-
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
33-
success: authenticated,
34-
userId: authenticated ? 'test-user-id' : undefined,
35-
error: authenticated ? undefined : 'Unauthorized',
36-
}),
37-
}))
32+
const { mockCheckSessionOrInternalAuth } = mockHybridAuth()
33+
mockCheckSessionOrInternalAuth.mockResolvedValue({
34+
success: authenticated,
35+
userId: authenticated ? 'test-user-id' : undefined,
36+
error: authenticated ? undefined : 'Unauthorized',
37+
})
3838

3939
vi.doMock('@/app/api/files/authorization', () => ({
4040
verifyFileAccess: vi.fn().mockResolvedValue(true),

apps/sim/app/api/files/parse/route.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
createMockRequest,
99
mockAuth,
1010
mockCryptoUuid,
11+
mockHybridAuth,
1112
mockUuid,
1213
setupCommonApiMocks,
1314
} from '@sim/testing'
@@ -34,13 +35,12 @@ function setupFileApiMocks(
3435
authMocks.setUnauthenticated()
3536
}
3637

37-
vi.doMock('@/lib/auth/hybrid', () => ({
38-
checkInternalAuth: vi.fn().mockResolvedValue({
39-
success: authenticated,
40-
userId: authenticated ? 'test-user-id' : undefined,
41-
error: authenticated ? undefined : 'Unauthorized',
42-
}),
43-
}))
38+
const { mockCheckInternalAuth } = mockHybridAuth()
39+
mockCheckInternalAuth.mockResolvedValue({
40+
success: authenticated,
41+
userId: authenticated ? 'test-user-id' : undefined,
42+
error: authenticated ? undefined : 'Unauthorized',
43+
})
4444

4545
vi.doMock('@/app/api/files/authorization', () => ({
4646
verifyFileAccess: vi.fn().mockResolvedValue(true),

apps/sim/app/api/files/presigned/route.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { mockAuth, mockCryptoUuid, mockUuid, setupCommonApiMocks } from '@sim/testing'
1+
import {
2+
mockAuth,
3+
mockCryptoUuid,
4+
mockHybridAuth,
5+
mockUuid,
6+
setupCommonApiMocks,
7+
} from '@sim/testing'
28
import { NextRequest } from 'next/server'
39
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
410

@@ -28,13 +34,12 @@ function setupFileApiMocks(
2834
authMocks.setUnauthenticated()
2935
}
3036

31-
vi.doMock('@/lib/auth/hybrid', () => ({
32-
checkHybridAuth: vi.fn().mockResolvedValue({
33-
success: authenticated,
34-
userId: authenticated ? 'test-user-id' : undefined,
35-
error: authenticated ? undefined : 'Unauthorized',
36-
}),
37-
}))
37+
const { mockCheckHybridAuth } = mockHybridAuth()
38+
mockCheckHybridAuth.mockResolvedValue({
39+
success: authenticated,
40+
userId: authenticated ? 'test-user-id' : undefined,
41+
error: authenticated ? undefined : 'Unauthorized',
42+
})
3843

3944
vi.doMock('@/app/api/files/authorization', () => ({
4045
verifyFileAccess: vi.fn().mockResolvedValue(true),

apps/sim/app/api/files/serve/[...path]/route.test.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
defaultMockUser,
88
mockAuth,
99
mockCryptoUuid,
10+
mockHybridAuth,
1011
mockUuid,
1112
setupCommonApiMocks,
1213
} from '@sim/testing'
@@ -54,12 +55,11 @@ describe('File Serve API Route', () => {
5455
withUploadUtils: true,
5556
})
5657

57-
vi.doMock('@/lib/auth/hybrid', () => ({
58-
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
59-
success: true,
60-
userId: 'test-user-id',
61-
}),
62-
}))
58+
const { mockCheckSessionOrInternalAuth: serveAuthMock } = mockHybridAuth()
59+
serveAuthMock.mockResolvedValue({
60+
success: true,
61+
userId: 'test-user-id',
62+
})
6363

6464
vi.doMock('@/app/api/files/authorization', () => ({
6565
verifyFileAccess: vi.fn().mockResolvedValue(true),
@@ -164,12 +164,11 @@ describe('File Serve API Route', () => {
164164
findLocalFile: vi.fn().mockReturnValue('/test/uploads/nested/path/file.txt'),
165165
}))
166166

167-
vi.doMock('@/lib/auth/hybrid', () => ({
168-
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
169-
success: true,
170-
userId: 'test-user-id',
171-
}),
172-
}))
167+
const { mockCheckSessionOrInternalAuth: serveAuthMock } = mockHybridAuth()
168+
serveAuthMock.mockResolvedValue({
169+
success: true,
170+
userId: 'test-user-id',
171+
})
173172

174173
vi.doMock('@/app/api/files/authorization', () => ({
175174
verifyFileAccess: vi.fn().mockResolvedValue(true),
@@ -225,12 +224,11 @@ describe('File Serve API Route', () => {
225224
USE_BLOB_STORAGE: false,
226225
}))
227226

228-
vi.doMock('@/lib/auth/hybrid', () => ({
229-
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
230-
success: true,
231-
userId: 'test-user-id',
232-
}),
233-
}))
227+
const { mockCheckSessionOrInternalAuth: serveAuthMock } = mockHybridAuth()
228+
serveAuthMock.mockResolvedValue({
229+
success: true,
230+
userId: 'test-user-id',
231+
})
234232

235233
vi.doMock('@/app/api/files/authorization', () => ({
236234
verifyFileAccess: vi.fn().mockResolvedValue(true),
@@ -290,12 +288,11 @@ describe('File Serve API Route', () => {
290288
readFile: vi.fn().mockRejectedValue(new Error('ENOENT: no such file or directory')),
291289
}))
292290

293-
vi.doMock('@/lib/auth/hybrid', () => ({
294-
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
295-
success: true,
296-
userId: 'test-user-id',
297-
}),
298-
}))
291+
const { mockCheckSessionOrInternalAuth: serveAuthMock } = mockHybridAuth()
292+
serveAuthMock.mockResolvedValue({
293+
success: true,
294+
userId: 'test-user-id',
295+
})
299296

300297
vi.doMock('@/app/api/files/authorization', () => ({
301298
verifyFileAccess: vi.fn().mockResolvedValue(false), // File not found = no access
@@ -349,12 +346,11 @@ describe('File Serve API Route', () => {
349346

350347
for (const test of contentTypeTests) {
351348
it(`should serve ${test.ext} file with correct content type`, async () => {
352-
vi.doMock('@/lib/auth/hybrid', () => ({
353-
checkSessionOrInternalAuth: vi.fn().mockResolvedValue({
354-
success: true,
355-
userId: 'test-user-id',
356-
}),
357-
}))
349+
const { mockCheckSessionOrInternalAuth: ctAuthMock } = mockHybridAuth()
350+
ctAuthMock.mockResolvedValue({
351+
success: true,
352+
userId: 'test-user-id',
353+
})
358354

359355
vi.doMock('@/app/api/files/authorization', () => ({
360356
verifyFileAccess: vi.fn().mockResolvedValue(true),

apps/sim/app/api/files/upload/route.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
*
44
* @vitest-environment node
55
*/
6-
import { mockAuth, mockCryptoUuid, mockUuid, setupCommonApiMocks } from '@sim/testing'
6+
import {
7+
mockAuth,
8+
mockCryptoUuid,
9+
mockHybridAuth,
10+
mockUuid,
11+
setupCommonApiMocks,
12+
} from '@sim/testing'
713
import { NextRequest } from 'next/server'
814
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
915

@@ -27,13 +33,12 @@ function setupFileApiMocks(
2733
authMocks.setUnauthenticated()
2834
}
2935

30-
vi.doMock('@/lib/auth/hybrid', () => ({
31-
checkHybridAuth: vi.fn().mockResolvedValue({
32-
success: authenticated,
33-
userId: authenticated ? 'test-user-id' : undefined,
34-
error: authenticated ? undefined : 'Unauthorized',
35-
}),
36-
}))
36+
const { mockCheckHybridAuth } = mockHybridAuth()
37+
mockCheckHybridAuth.mockResolvedValue({
38+
success: authenticated,
39+
userId: authenticated ? 'test-user-id' : undefined,
40+
error: authenticated ? undefined : 'Unauthorized',
41+
})
3742

3843
vi.doMock('@/app/api/files/authorization', () => ({
3944
verifyFileAccess: vi.fn().mockResolvedValue(true),

apps/sim/app/api/knowledge/search/route.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
createMockRequest,
1111
mockConsoleLogger,
1212
mockKnowledgeSchemas,
13+
requestUtilsMock,
1314
} from '@sim/testing'
1415
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1516

@@ -29,9 +30,7 @@ mockKnowledgeSchemas()
2930

3031
vi.mock('@/lib/core/config/env', () => createEnvMock({ OPENAI_API_KEY: 'test-api-key' }))
3132

32-
vi.mock('@/lib/core/utils/request', () => ({
33-
generateRequestId: vi.fn(() => 'test-request-id'),
34-
}))
33+
vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
3534

3635
vi.mock('@/lib/documents/utils', () => ({
3736
retryWithExponentialBackoff: vi.fn().mockImplementation((fn) => fn()),

apps/sim/app/api/mcp/serve/[serverId]/route.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
*
44
* @vitest-environment node
55
*/
6+
import { mockHybridAuth } from '@sim/testing'
67
import { NextRequest } from 'next/server'
78
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
89

9-
const mockCheckHybridAuth = vi.fn()
10+
let mockCheckHybridAuth: ReturnType<typeof vi.fn>
1011
const mockGetUserEntityPermissions = vi.fn()
1112
const mockGenerateInternalToken = vi.fn()
1213
const mockDbSelect = vi.fn()
@@ -61,9 +62,7 @@ describe('MCP Serve Route', () => {
6162
isDeployed: 'isDeployed',
6263
},
6364
}))
64-
vi.doMock('@/lib/auth/hybrid', () => ({
65-
checkHybridAuth: mockCheckHybridAuth,
66-
}))
65+
;({ mockCheckHybridAuth } = mockHybridAuth())
6766
vi.doMock('@/lib/workspaces/permissions/utils', () => ({
6867
getUserEntityPermissions: mockGetUserEntityPermissions,
6968
}))

0 commit comments

Comments
 (0)