Skip to content

Commit c00a52d

Browse files
committed
fix(tests): fix 4 failing test files with missing mocks
- socket/middleware/permissions: add vi.mock for @/lib/auth to prevent transitive getBaseUrl() call - workflow-handler: add vi.mock for @/executor/utils/http matching executor mock pattern - evaluator-handler: add db.query.account mock structure before vi.spyOn - router-handler: same db.query.account fix as evaluator
1 parent d40219f commit c00a52d

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

apps/sim/executor/handlers/evaluator/evaluator-handler.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ describe('EvaluatorBlockHandler', () => {
418418
refreshToken: 'mock-refresh-token',
419419
expiresAt: new Date(Date.now() + 3600000), // 1 hour from now
420420
}
421+
;(mockDb.db.query as any).account = { findFirst: vi.fn() }
421422
vi.spyOn(mockDb.db.query.account, 'findFirst').mockResolvedValue(mockAccount as any)
422423

423424
mockFetch.mockImplementationOnce(() => {

apps/sim/executor/handlers/router/router-handler.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ describe('RouterBlockHandler', () => {
287287
refreshToken: 'mock-refresh-token',
288288
expiresAt: new Date(Date.now() + 3600000),
289289
}
290+
;(mockDb.db.query as any).account = { findFirst: vi.fn() }
290291
vi.spyOn(mockDb.db.query.account, 'findFirst').mockResolvedValue(mockAccount as any)
291292

292293
await handler.execute(mockContext, mockBlock, inputs)

apps/sim/executor/handlers/workflow/workflow-handler.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ vi.mock('@/lib/auth/internal', () => ({
99
generateInternalToken: vi.fn().mockResolvedValue('test-token'),
1010
}))
1111

12+
vi.mock('@/executor/utils/http', () => ({
13+
buildAuthHeaders: vi.fn().mockResolvedValue({ 'Content-Type': 'application/json' }),
14+
buildAPIUrl: vi.fn((path: string) => new URL(path, 'http://localhost:3000')),
15+
extractAPIErrorMessage: vi.fn(async (response: Response) => {
16+
const defaultMessage = `API request failed with status ${response.status}`
17+
try {
18+
const errorData = await response.json()
19+
return errorData.error || defaultMessage
20+
} catch {
21+
return defaultMessage
22+
}
23+
}),
24+
}))
25+
1226
// Mock fetch globally
1327
setupGlobalFetchMock()
1428

apps/sim/socket/middleware/permissions.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import {
1313
ROLE_ALLOWED_OPERATIONS,
1414
SOCKET_OPERATIONS,
1515
} from '@sim/testing'
16-
import { describe, expect, it } from 'vitest'
16+
import { describe, expect, it, vi } from 'vitest'
17+
18+
vi.mock('@/lib/auth', () => ({
19+
auth: { api: { getSession: vi.fn() } },
20+
getSession: vi.fn(),
21+
}))
22+
1723
import { checkRolePermission } from '@/socket/middleware/permissions'
1824

1925
describe('checkRolePermission', () => {

0 commit comments

Comments
 (0)