Skip to content

Commit 499e2dc

Browse files
fix tests
1 parent 56151c4 commit 499e2dc

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

apps/sim/app/api/auth/forget-password/route.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ vi.mock('@/lib/auth', () => ({
3434
}))
3535
vi.mock('@sim/logger', () => ({
3636
createLogger: vi.fn().mockReturnValue(mockLogger),
37+
runWithRequestContext: <T>(_ctx: unknown, fn: () => T): T => fn(),
38+
getRequestContext: () => undefined,
3739
}))
3840

3941
import { POST } from '@/app/api/auth/forget-password/route'

apps/sim/app/api/auth/reset-password/route.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ vi.mock('@/lib/auth', () => ({
3131
}))
3232
vi.mock('@sim/logger', () => ({
3333
createLogger: vi.fn().mockReturnValue(mockLogger),
34+
runWithRequestContext: <T>(_ctx: unknown, fn: () => T): T => fn(),
35+
getRequestContext: () => undefined,
3436
}))
3537

3638
import { POST } from '@/app/api/auth/reset-password/route'

apps/sim/app/api/folders/[id]/route.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const mockGetUserEntityPermissions = permissionsMockFns.mockGetUserEntityPermiss
4040
vi.mock('@/lib/audit/log', () => auditMock)
4141
vi.mock('@sim/logger', () => ({
4242
createLogger: vi.fn().mockReturnValue(mockLogger),
43+
runWithRequestContext: <T>(_ctx: unknown, fn: () => T): T => fn(),
44+
getRequestContext: () => undefined,
4345
}))
4446
vi.mock('@/lib/workspaces/permissions/utils', () => permissionsMock)
4547
vi.mock('@sim/db', () => ({

apps/sim/app/api/folders/route.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ vi.mock('drizzle-orm', () => ({
3737
}))
3838
vi.mock('@sim/logger', () => ({
3939
createLogger: vi.fn().mockReturnValue(mockLogger),
40+
runWithRequestContext: <T>(_ctx: unknown, fn: () => T): T => fn(),
41+
getRequestContext: () => undefined,
4042
}))
4143
vi.mock('@/lib/workspaces/permissions/utils', () => permissionsMock)
4244

apps/sim/lib/core/utils/with-route-handler.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export function withRouteHandler<T>(handler: RouteHandler<T>): RouteHandler<T> {
2323
return async (request: NextRequest, context: T) => {
2424
const requestId = generateRequestId()
2525
const startTime = Date.now()
26-
const method = request.method
26+
const method = request?.method ?? 'UNKNOWN'
2727
const path =
28-
request.nextUrl?.pathname ?? new URL(request.url ?? '/', 'http://localhost').pathname
28+
request?.nextUrl?.pathname ?? new URL(request?.url ?? '/', 'http://localhost').pathname
2929

3030
return runWithRequestContext({ requestId, method, path }, async () => {
3131
let response: NextResponse | Response
@@ -36,22 +36,22 @@ export function withRouteHandler<T>(handler: RouteHandler<T>): RouteHandler<T> {
3636
const message = error instanceof Error ? error.message : 'Unknown error'
3737
logger.error('Unhandled route error', { duration, error: message })
3838
response = NextResponse.json({ error: 'Internal server error', requestId }, { status: 500 })
39-
response.headers.set('x-request-id', requestId)
39+
response?.headers?.set('x-request-id', requestId)
4040
return response
4141
}
4242

43-
const status = response.status
43+
const status = response?.status ?? 0
4444
const duration = Date.now() - startTime
4545

4646
if (status >= 500) {
4747
logger.error('Server error response', { status, duration })
4848
} else if (status >= 400) {
4949
logger.warn('Client error response', { status, duration })
50-
} else {
50+
} else if (status > 0) {
5151
logger.info('OK', { status, duration })
5252
}
5353

54-
response.headers.set('x-request-id', requestId)
54+
response?.headers?.set('x-request-id', requestId)
5555
return response
5656
})
5757
}

0 commit comments

Comments
 (0)