mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
refactor(imports): added aliased imports everywhere (#799)
* refactor(imports): added aliased imports everywhere * more aliased imports * add barrel exports * add more barrel exports * cleanup --------- Co-authored-by: waleedlatif <waleedlatif@waleedlatifs-MacBook-Pro.local>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { cn } from '@/lib/utils'
|
||||
import {
|
||||
AgentIcon,
|
||||
ApiIcon,
|
||||
@@ -7,7 +6,8 @@ import {
|
||||
ConditionalIcon,
|
||||
ConnectIcon,
|
||||
ResponseIcon,
|
||||
} from '../icons'
|
||||
} from '@/components/icons'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
// Custom Feature component specifically for BlockTypes to handle the 6-item layout
|
||||
const BlockFeature = ({
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import Image from 'next/image'
|
||||
import Link from 'next/link'
|
||||
import { GridPattern } from '../(landing)/components/grid-pattern'
|
||||
import { GridPattern } from '@/app/(landing)/components/grid-pattern'
|
||||
|
||||
export default function AuthLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
|
||||
@@ -6,7 +6,7 @@ import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { client } from '@/lib/auth-client'
|
||||
import LoginPage from './login-form'
|
||||
import LoginPage from '@/app/(auth)/login/login-form'
|
||||
|
||||
vi.mock('next/navigation', () => ({
|
||||
useRouter: vi.fn(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getOAuthProviderStatus } from '../components/oauth-provider-checker'
|
||||
import LoginForm from './login-form'
|
||||
import { getOAuthProviderStatus } from '@/app/(auth)/components/oauth-provider-checker'
|
||||
import LoginForm from '@/app/(auth)/login/login-form'
|
||||
|
||||
// Force dynamic rendering to avoid prerender errors with search params
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
CardTitle,
|
||||
} from '@/components/ui/card'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { SetNewPasswordForm } from './reset-password-form'
|
||||
import { SetNewPasswordForm } from '@/app/(auth)/reset-password/reset-password-form'
|
||||
|
||||
const logger = createLogger('ResetPasswordPage')
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { env, isTruthy } from '@/lib/env'
|
||||
import { getOAuthProviderStatus } from '../components/oauth-provider-checker'
|
||||
import SignupForm from './signup-form'
|
||||
import { getOAuthProviderStatus } from '@/app/(auth)/components/oauth-provider-checker'
|
||||
import SignupForm from '@/app/(auth)/signup/signup-form'
|
||||
|
||||
// Force dynamic rendering to avoid prerender errors with search params
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
@@ -6,7 +6,7 @@ import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { client } from '@/lib/auth-client'
|
||||
import SignupPage from './signup-form'
|
||||
import SignupPage from '@/app/(auth)/signup/signup-form'
|
||||
|
||||
vi.mock('next/navigation', () => ({
|
||||
useRouter: vi.fn(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { env } from '@/lib/env'
|
||||
import { isProd } from '@/lib/environment'
|
||||
import { getBaseUrl } from '@/lib/urls/utils'
|
||||
import { VerifyContent } from './verify-content'
|
||||
import { VerifyContent } from '@/app/(auth)/verify/verify-content'
|
||||
|
||||
// Force dynamic rendering to avoid prerender errors with search params
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Suspense, useEffect, useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useVerification } from './use-verification'
|
||||
import { useVerification } from '@/app/(auth)/verify/use-verification'
|
||||
|
||||
interface VerifyContentProps {
|
||||
hasResendKey: boolean
|
||||
|
||||
@@ -17,9 +17,9 @@ import ReactFlow, {
|
||||
} from 'reactflow'
|
||||
import 'reactflow/dist/style.css'
|
||||
|
||||
import { HeroBlock } from './hero-block'
|
||||
import { HeroEdge } from './hero-edge'
|
||||
import { useWindowSize } from './use-window-size'
|
||||
import { HeroBlock } from '@/app/(landing)/components/hero-block'
|
||||
import { HeroEdge } from '@/app/(landing)/components/hero-edge'
|
||||
import { useWindowSize } from '@/app/(landing)/components/use-window-size'
|
||||
|
||||
const nodeTypes: NodeTypes = { heroBlock: HeroBlock }
|
||||
const edgeTypes: EdgeTypes = { heroEdge: HeroEdge }
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
SheetTitle,
|
||||
SheetTrigger,
|
||||
} from '@/components/ui/sheet'
|
||||
import { usePrefetchOnHover } from '../utils/prefetch'
|
||||
import { usePrefetchOnHover } from '@/app/(landing)/utils/prefetch'
|
||||
|
||||
// --- Framer Motion Variants ---
|
||||
const desktopNavContainerVariants = {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { AnimatePresence, motion } from 'framer-motion'
|
||||
import { usePathname } from 'next/navigation'
|
||||
import { getFormattedGitHubStars } from '../actions/github'
|
||||
import GitHubStarsClient from './github-stars-client'
|
||||
import NavClient from './nav-client'
|
||||
import { getFormattedGitHubStars } from '@/app/(landing)/actions/github'
|
||||
import GitHubStarsClient from '@/app/(landing)/components/github-stars-client'
|
||||
import NavClient from '@/app/(landing)/components/nav-client'
|
||||
|
||||
interface NavWrapperProps {
|
||||
onOpenTypeformLink: () => void
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { motion } from 'framer-motion'
|
||||
import { BlogCard } from '../blog-card'
|
||||
import { BlogCard } from '@/app/(landing)/components/blog-card'
|
||||
|
||||
function Blogs() {
|
||||
return (
|
||||
|
||||
@@ -18,8 +18,8 @@ import 'reactflow/dist/style.css'
|
||||
|
||||
import { AgentIcon, ConnectIcon, StartIcon } from '@/components/icons'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { DotPattern } from '../dot-pattern'
|
||||
import { HeroBlock } from '../hero-block'
|
||||
import { DotPattern } from '@/app/(landing)/components/dot-pattern'
|
||||
import { HeroBlock } from '@/app/(landing)/components/hero-block'
|
||||
|
||||
// --- Types ---
|
||||
type Feature = {
|
||||
|
||||
@@ -6,8 +6,8 @@ import { useRouter } from 'next/navigation'
|
||||
import { DiscordIcon, GithubIcon, xIcon as XIcon } from '@/components/icons'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useSession } from '@/lib/auth-client'
|
||||
import { usePrefetchOnHover } from '../../utils/prefetch'
|
||||
import useIsMobile from '../hooks/use-is-mobile'
|
||||
import useIsMobile from '@/app/(landing)/components/hooks/use-is-mobile'
|
||||
import { usePrefetchOnHover } from '@/app/(landing)/utils/prefetch'
|
||||
|
||||
function Footer() {
|
||||
const router = useRouter()
|
||||
|
||||
@@ -5,8 +5,8 @@ import { Command, CornerDownLeft } from 'lucide-react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useSession } from '@/lib/auth-client'
|
||||
import { GridPattern } from '../grid-pattern'
|
||||
import HeroWorkflowProvider from '../hero-workflow'
|
||||
import { GridPattern } from '@/app/(landing)/components/grid-pattern'
|
||||
import HeroWorkflowProvider from '@/app/(landing)/components/hero-workflow'
|
||||
|
||||
function Hero() {
|
||||
const router = useRouter()
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
import { motion } from 'framer-motion'
|
||||
import { GitBranch, RefreshCcw } from 'lucide-react'
|
||||
import ReactFlow, { ConnectionLineType, Position, ReactFlowProvider } from 'reactflow'
|
||||
import { DotPattern } from '@/app/(landing)/components/dot-pattern'
|
||||
import { HeroBlock } from '@/app/(landing)/components/hero-block'
|
||||
import { OrbitingCircles } from '@/app/(landing)/components/magicui/orbiting-circles'
|
||||
import { DotPattern } from '../dot-pattern'
|
||||
import { HeroBlock } from '../hero-block'
|
||||
|
||||
function Integrations() {
|
||||
return (
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use client'
|
||||
|
||||
import { motion } from 'framer-motion'
|
||||
import useIsMobile from '@/app/(landing)/components/hooks/use-is-mobile'
|
||||
import { Marquee } from '@/app/(landing)/components/magicui/marquee'
|
||||
import useIsMobile from '../hooks/use-is-mobile'
|
||||
|
||||
const X_TESTIMONIALS = [
|
||||
{
|
||||
|
||||
@@ -26,10 +26,10 @@ import {
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { GridPattern } from '../components/grid-pattern'
|
||||
import NavWrapper from '../components/nav-wrapper'
|
||||
import Footer from '../components/sections/footer'
|
||||
import { getCachedContributorsData, prefetchContributorsData } from '../utils/prefetch'
|
||||
import { GridPattern } from '@/app/(landing)/components/grid-pattern'
|
||||
import NavWrapper from '@/app/(landing)/components/nav-wrapper'
|
||||
import Footer from '@/app/(landing)/components/sections/footer'
|
||||
import { getCachedContributorsData, prefetchContributorsData } from '@/app/(landing)/utils/prefetch'
|
||||
|
||||
interface Contributor {
|
||||
login: string
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
'use client'
|
||||
|
||||
import NavWrapper from './components/nav-wrapper'
|
||||
import Footer from './components/sections/footer'
|
||||
import Hero from './components/sections/hero'
|
||||
import Integrations from './components/sections/integrations'
|
||||
import Testimonials from './components/sections/testimonials'
|
||||
import NavWrapper from '@/app/(landing)/components/nav-wrapper'
|
||||
import Footer from '@/app/(landing)/components/sections/footer'
|
||||
import Hero from '@/app/(landing)/components/sections/hero'
|
||||
import Integrations from '@/app/(landing)/components/sections/integrations'
|
||||
import Testimonials from '@/app/(landing)/components/sections/testimonials'
|
||||
|
||||
export default function Landing() {
|
||||
const handleOpenTypeformLink = () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client'
|
||||
|
||||
import Link from 'next/link'
|
||||
import { GridPattern } from '../components/grid-pattern'
|
||||
import NavWrapper from '../components/nav-wrapper'
|
||||
import Footer from '../components/sections/footer'
|
||||
import { GridPattern } from '@/app/(landing)/components/grid-pattern'
|
||||
import NavWrapper from '@/app/(landing)/components/nav-wrapper'
|
||||
import Footer from '@/app/(landing)/components/sections/footer'
|
||||
|
||||
export default function PrivacyPolicy() {
|
||||
const handleOpenTypeformLink = () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client'
|
||||
|
||||
import Link from 'next/link'
|
||||
import { GridPattern } from '../components/grid-pattern'
|
||||
import NavWrapper from '../components/nav-wrapper'
|
||||
import Footer from '../components/sections/footer'
|
||||
import { GridPattern } from '@/app/(landing)/components/grid-pattern'
|
||||
import NavWrapper from '@/app/(landing)/components/nav-wrapper'
|
||||
import Footer from '@/app/(landing)/components/sections/footer'
|
||||
|
||||
export default function TermsOfService() {
|
||||
const handleOpenTypeformLink = () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Utility for prefetching and caching contributors page data
|
||||
import { getCommitsData, getContributors, getRepositoryStats } from '../actions/github'
|
||||
import { generateActivityData, generateCommitTimelineData } from './github'
|
||||
import { getCommitsData, getContributors, getRepositoryStats } from '@/app/(landing)/actions/github'
|
||||
import { generateActivityData, generateCommitTimelineData } from '@/app/(landing)/utils/github'
|
||||
|
||||
interface Contributor {
|
||||
login: string
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('Forget Password API Route', () => {
|
||||
redirectTo: 'https://example.com/reset',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/forget-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -56,7 +56,7 @@ describe('Forget Password API Route', () => {
|
||||
email: 'test@example.com',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/forget-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -79,7 +79,7 @@ describe('Forget Password API Route', () => {
|
||||
|
||||
const req = createMockRequest('POST', {})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/forget-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -98,7 +98,7 @@ describe('Forget Password API Route', () => {
|
||||
email: '',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/forget-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -126,7 +126,7 @@ describe('Forget Password API Route', () => {
|
||||
email: 'nonexistent@example.com',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/forget-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -156,7 +156,7 @@ describe('Forget Password API Route', () => {
|
||||
email: 'test@example.com',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/forget-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -96,7 +96,7 @@ describe('OAuth Connections API Route', () => {
|
||||
mockDb.limit.mockResolvedValueOnce(mockUserRecord)
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/connections/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -121,7 +121,7 @@ describe('OAuth Connections API Route', () => {
|
||||
mockGetSession.mockResolvedValueOnce(null)
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/connections/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -146,7 +146,7 @@ describe('OAuth Connections API Route', () => {
|
||||
mockDb.limit.mockResolvedValueOnce([])
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/connections/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -165,7 +165,7 @@ describe('OAuth Connections API Route', () => {
|
||||
mockDb.where.mockRejectedValueOnce(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/connections/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -209,7 +209,7 @@ describe('OAuth Connections API Route', () => {
|
||||
mockDb.limit.mockResolvedValueOnce([])
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/connections/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -111,7 +111,7 @@ describe('OAuth Credentials API Route', () => {
|
||||
|
||||
const req = createMockRequestWithQuery('GET', '?provider=google-email')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -135,7 +135,7 @@ describe('OAuth Credentials API Route', () => {
|
||||
|
||||
const req = createMockRequestWithQuery('GET', '?provider=google')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -152,7 +152,7 @@ describe('OAuth Credentials API Route', () => {
|
||||
|
||||
const req = createMockRequestWithQuery('GET')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -177,7 +177,7 @@ describe('OAuth Credentials API Route', () => {
|
||||
|
||||
const req = createMockRequestWithQuery('GET', '?provider=github')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -220,7 +220,7 @@ describe('OAuth Credentials API Route', () => {
|
||||
|
||||
const req = createMockRequestWithQuery('GET', '?provider=google')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -244,7 +244,7 @@ describe('OAuth Credentials API Route', () => {
|
||||
|
||||
const req = createMockRequestWithQuery('GET', '?provider=google')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/credentials/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -68,7 +68,7 @@ describe('OAuth Disconnect API Route', () => {
|
||||
provider: 'google',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/disconnect/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -91,7 +91,7 @@ describe('OAuth Disconnect API Route', () => {
|
||||
providerId: 'google-email',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/disconnect/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -108,7 +108,7 @@ describe('OAuth Disconnect API Route', () => {
|
||||
provider: 'google',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/disconnect/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -125,7 +125,7 @@ describe('OAuth Disconnect API Route', () => {
|
||||
|
||||
const req = createMockRequest('POST', {})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/disconnect/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -147,7 +147,7 @@ describe('OAuth Disconnect API Route', () => {
|
||||
provider: 'google',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/disconnect/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -2,9 +2,9 @@ import { eq } from 'drizzle-orm'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
import { db } from '@/db'
|
||||
import { account } from '@/db/schema'
|
||||
import { refreshAccessTokenIfNeeded } from '../../utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import { eq } from 'drizzle-orm'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
import { db } from '@/db'
|
||||
import { account } from '@/db/schema'
|
||||
import { refreshAccessTokenIfNeeded } from '../../utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('OAuth Token API Routes', () => {
|
||||
randomUUID: vi.fn().mockReturnValue(mockUUID),
|
||||
})
|
||||
|
||||
vi.doMock('../utils', () => ({
|
||||
vi.doMock('@/app/api/auth/oauth/utils', () => ({
|
||||
getUserId: mockGetUserId,
|
||||
getCredential: mockGetCredential,
|
||||
refreshTokenIfNeeded: mockRefreshTokenIfNeeded,
|
||||
@@ -67,7 +67,7 @@ describe('OAuth Token API Routes', () => {
|
||||
})
|
||||
|
||||
// Import handler after setting up mocks
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
// Call handler
|
||||
const response = await POST(req)
|
||||
@@ -102,7 +102,7 @@ describe('OAuth Token API Routes', () => {
|
||||
workflowId: 'workflow-id',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -121,7 +121,7 @@ describe('OAuth Token API Routes', () => {
|
||||
it('should handle missing credentialId', async () => {
|
||||
const req = createMockRequest('POST', {})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -138,7 +138,7 @@ describe('OAuth Token API Routes', () => {
|
||||
credentialId: 'credential-id',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -155,7 +155,7 @@ describe('OAuth Token API Routes', () => {
|
||||
workflowId: 'nonexistent-workflow-id',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -172,7 +172,7 @@ describe('OAuth Token API Routes', () => {
|
||||
credentialId: 'nonexistent-credential-id',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -196,7 +196,7 @@ describe('OAuth Token API Routes', () => {
|
||||
credentialId: 'credential-id',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -228,7 +228,7 @@ describe('OAuth Token API Routes', () => {
|
||||
'http://localhost:3000/api/auth/oauth/token?credentialId=credential-id'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await GET(req as any)
|
||||
const data = await response.json()
|
||||
@@ -244,7 +244,7 @@ describe('OAuth Token API Routes', () => {
|
||||
it('should handle missing credentialId', async () => {
|
||||
const req = new Request('http://localhost:3000/api/auth/oauth/token')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await GET(req as any)
|
||||
const data = await response.json()
|
||||
@@ -261,7 +261,7 @@ describe('OAuth Token API Routes', () => {
|
||||
'http://localhost:3000/api/auth/oauth/token?credentialId=credential-id'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await GET(req as any)
|
||||
const data = await response.json()
|
||||
@@ -278,7 +278,7 @@ describe('OAuth Token API Routes', () => {
|
||||
'http://localhost:3000/api/auth/oauth/token?credentialId=nonexistent-credential-id'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await GET(req as any)
|
||||
const data = await response.json()
|
||||
@@ -300,7 +300,7 @@ describe('OAuth Token API Routes', () => {
|
||||
'http://localhost:3000/api/auth/oauth/token?credentialId=credential-id'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await GET(req as any)
|
||||
const data = await response.json()
|
||||
@@ -325,7 +325,7 @@ describe('OAuth Token API Routes', () => {
|
||||
'http://localhost:3000/api/auth/oauth/token?credentialId=credential-id'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/auth/oauth/token/route')
|
||||
|
||||
const response = await GET(req as any)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { getCredential, getUserId, refreshTokenIfNeeded } from '../utils'
|
||||
import { getCredential, getUserId, refreshTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('OAuth Utils', () => {
|
||||
|
||||
describe('getUserId', () => {
|
||||
it('should get user ID from session when no workflowId is provided', async () => {
|
||||
const { getUserId } = await import('./utils')
|
||||
const { getUserId } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const userId = await getUserId('request-id')
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('OAuth Utils', () => {
|
||||
it('should get user ID from workflow when workflowId is provided', async () => {
|
||||
mockDb.limit.mockReturnValueOnce([{ userId: 'workflow-owner-id' }])
|
||||
|
||||
const { getUserId } = await import('./utils')
|
||||
const { getUserId } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const userId = await getUserId('request-id', 'workflow-id')
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('OAuth Utils', () => {
|
||||
getSession: vi.fn().mockResolvedValue(null),
|
||||
}))
|
||||
|
||||
const { getUserId } = await import('./utils')
|
||||
const { getUserId } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const userId = await getUserId('request-id')
|
||||
|
||||
@@ -87,7 +87,7 @@ describe('OAuth Utils', () => {
|
||||
it('should return undefined if workflow is not found', async () => {
|
||||
mockDb.limit.mockReturnValueOnce([])
|
||||
|
||||
const { getUserId } = await import('./utils')
|
||||
const { getUserId } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const userId = await getUserId('request-id', 'nonexistent-workflow-id')
|
||||
|
||||
@@ -101,7 +101,7 @@ describe('OAuth Utils', () => {
|
||||
const mockCredential = { id: 'credential-id', userId: 'test-user-id' }
|
||||
mockDb.limit.mockReturnValueOnce([mockCredential])
|
||||
|
||||
const { getCredential } = await import('./utils')
|
||||
const { getCredential } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const credential = await getCredential('request-id', 'credential-id', 'test-user-id')
|
||||
|
||||
@@ -116,7 +116,7 @@ describe('OAuth Utils', () => {
|
||||
it('should return undefined when credential is not found', async () => {
|
||||
mockDb.limit.mockReturnValueOnce([])
|
||||
|
||||
const { getCredential } = await import('./utils')
|
||||
const { getCredential } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const credential = await getCredential('request-id', 'nonexistent-id', 'test-user-id')
|
||||
|
||||
@@ -135,7 +135,7 @@ describe('OAuth Utils', () => {
|
||||
providerId: 'google',
|
||||
}
|
||||
|
||||
const { refreshTokenIfNeeded } = await import('./utils')
|
||||
const { refreshTokenIfNeeded } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const result = await refreshTokenIfNeeded('request-id', mockCredential, 'credential-id')
|
||||
|
||||
@@ -159,7 +159,7 @@ describe('OAuth Utils', () => {
|
||||
refreshToken: 'new-refresh-token',
|
||||
})
|
||||
|
||||
const { refreshTokenIfNeeded } = await import('./utils')
|
||||
const { refreshTokenIfNeeded } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const result = await refreshTokenIfNeeded('request-id', mockCredential, 'credential-id')
|
||||
|
||||
@@ -183,7 +183,7 @@ describe('OAuth Utils', () => {
|
||||
|
||||
mockRefreshOAuthToken.mockResolvedValueOnce(null)
|
||||
|
||||
const { refreshTokenIfNeeded } = await import('./utils')
|
||||
const { refreshTokenIfNeeded } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
await expect(
|
||||
refreshTokenIfNeeded('request-id', mockCredential, 'credential-id')
|
||||
@@ -201,7 +201,7 @@ describe('OAuth Utils', () => {
|
||||
providerId: 'google',
|
||||
}
|
||||
|
||||
const { refreshTokenIfNeeded } = await import('./utils')
|
||||
const { refreshTokenIfNeeded } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const result = await refreshTokenIfNeeded('request-id', mockCredential, 'credential-id')
|
||||
|
||||
@@ -222,7 +222,7 @@ describe('OAuth Utils', () => {
|
||||
}
|
||||
mockDb.limit.mockReturnValueOnce([mockCredential])
|
||||
|
||||
const { refreshAccessTokenIfNeeded } = await import('./utils')
|
||||
const { refreshAccessTokenIfNeeded } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const token = await refreshAccessTokenIfNeeded('credential-id', 'test-user-id', 'request-id')
|
||||
|
||||
@@ -247,7 +247,7 @@ describe('OAuth Utils', () => {
|
||||
refreshToken: 'new-refresh-token',
|
||||
})
|
||||
|
||||
const { refreshAccessTokenIfNeeded } = await import('./utils')
|
||||
const { refreshAccessTokenIfNeeded } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const token = await refreshAccessTokenIfNeeded('credential-id', 'test-user-id', 'request-id')
|
||||
|
||||
@@ -260,7 +260,7 @@ describe('OAuth Utils', () => {
|
||||
it('should return null if credential not found', async () => {
|
||||
mockDb.limit.mockReturnValueOnce([])
|
||||
|
||||
const { refreshAccessTokenIfNeeded } = await import('./utils')
|
||||
const { refreshAccessTokenIfNeeded } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const token = await refreshAccessTokenIfNeeded('nonexistent-id', 'test-user-id', 'request-id')
|
||||
|
||||
@@ -281,7 +281,7 @@ describe('OAuth Utils', () => {
|
||||
|
||||
mockRefreshOAuthToken.mockResolvedValueOnce(null)
|
||||
|
||||
const { refreshAccessTokenIfNeeded } = await import('./utils')
|
||||
const { refreshAccessTokenIfNeeded } = await import('@/app/api/auth/oauth/utils')
|
||||
|
||||
const token = await refreshAccessTokenIfNeeded('credential-id', 'test-user-id', 'request-id')
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import { eq } from 'drizzle-orm'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
import { db } from '@/db'
|
||||
import { account } from '@/db/schema'
|
||||
import { refreshAccessTokenIfNeeded } from '../../utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import { eq } from 'drizzle-orm'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
import { db } from '@/db'
|
||||
import { account } from '@/db/schema'
|
||||
import { refreshAccessTokenIfNeeded } from '../../utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('Reset Password API Route', () => {
|
||||
newPassword: 'newSecurePassword123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/reset-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -52,7 +52,7 @@ describe('Reset Password API Route', () => {
|
||||
newPassword: 'newSecurePassword123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/reset-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -91,7 +91,7 @@ describe('Reset Password API Route', () => {
|
||||
newPassword: 'newSecurePassword123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/reset-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -111,7 +111,7 @@ describe('Reset Password API Route', () => {
|
||||
newPassword: '',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/reset-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -140,7 +140,7 @@ describe('Reset Password API Route', () => {
|
||||
newPassword: 'newSecurePassword123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/reset-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -149,7 +149,7 @@ describe('Reset Password API Route', () => {
|
||||
expect(data.message).toBe(errorMessage)
|
||||
|
||||
const logger = await import('@/lib/logs/console/logger')
|
||||
const mockLogger = logger.createLogger('PasswordReset')
|
||||
const mockLogger = logger.createLogger('PasswordResetAPI')
|
||||
expect(mockLogger.error).toHaveBeenCalledWith('Error during password reset:', {
|
||||
error: expect.any(Error),
|
||||
})
|
||||
@@ -171,7 +171,7 @@ describe('Reset Password API Route', () => {
|
||||
newPassword: 'newSecurePassword123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/auth/reset-password/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -182,7 +182,7 @@ describe('Reset Password API Route', () => {
|
||||
)
|
||||
|
||||
const logger = await import('@/lib/logs/console/logger')
|
||||
const mockLogger = logger.createLogger('PasswordReset')
|
||||
const mockLogger = logger.createLogger('PasswordResetAPI')
|
||||
expect(mockLogger.error).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import { createLogger } from '@/lib/logs/console/logger'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('PasswordReset')
|
||||
const logger = createLogger('PasswordResetAPI')
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
|
||||
@@ -5,10 +5,10 @@ import { renderOTPEmail } from '@/components/emails/render-email'
|
||||
import { sendEmail } from '@/lib/email/mailer'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { getRedisClient, markMessageAsProcessed, releaseLock } from '@/lib/redis'
|
||||
import { addCorsHeaders, setChatAuthCookie } from '@/app/api/chat/utils'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { chat } from '@/db/schema'
|
||||
import { addCorsHeaders, setChatAuthCookie } from '../../utils'
|
||||
|
||||
const logger = createLogger('ChatOtpAPI')
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
|
||||
vi.doMock('../utils', () => ({
|
||||
vi.doMock('@/app/api/chat/utils', () => ({
|
||||
addCorsHeaders: mockAddCorsHeaders,
|
||||
validateChatAuth: mockValidateChatAuth,
|
||||
setChatAuthCookie: mockSetChatAuthCookie,
|
||||
@@ -138,7 +138,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('GET')
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await GET(req, { params })
|
||||
|
||||
@@ -169,7 +169,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('GET')
|
||||
const params = Promise.resolve({ subdomain: 'nonexistent' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await GET(req, { params })
|
||||
|
||||
@@ -203,7 +203,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('GET')
|
||||
const params = Promise.resolve({ subdomain: 'inactive-chat' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await GET(req, { params })
|
||||
|
||||
@@ -224,7 +224,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('GET')
|
||||
const params = Promise.resolve({ subdomain: 'password-protected-chat' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await GET(req, { params })
|
||||
|
||||
@@ -245,7 +245,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('POST', { password: 'test-password' })
|
||||
const params = Promise.resolve({ subdomain: 'password-protected-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -261,7 +261,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('POST', {})
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -282,7 +282,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('POST', { input: 'Hello' })
|
||||
const params = Promise.resolve({ subdomain: 'protected-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -345,7 +345,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('POST', { input: 'Hello' })
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -360,7 +360,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('POST', { input: 'Hello world', conversationId: 'conv-123' })
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -377,7 +377,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('POST', { input: 'Hello world' })
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -407,7 +407,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('POST', { input: 'Trigger error' })
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -426,12 +426,13 @@ describe('Chat Subdomain API Route', () => {
|
||||
// Create a request with invalid JSON
|
||||
const req = {
|
||||
method: 'POST',
|
||||
headers: new Headers(),
|
||||
json: vi.fn().mockRejectedValue(new Error('Invalid JSON')),
|
||||
} as any
|
||||
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -449,7 +450,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
await POST(req, { params })
|
||||
|
||||
@@ -464,7 +465,7 @@ describe('Chat Subdomain API Route', () => {
|
||||
const req = createMockRequest('POST', { input: 'Hello world' })
|
||||
const params = Promise.resolve({ subdomain: 'test-chat' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/[subdomain]/route')
|
||||
|
||||
await POST(req, { params })
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { eq } from 'drizzle-orm'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { chat, workflow } from '@/db/schema'
|
||||
import {
|
||||
addCorsHeaders,
|
||||
executeWorkflowForChat,
|
||||
setChatAuthCookie,
|
||||
validateAuthToken,
|
||||
validateChatAuth,
|
||||
} from '../utils'
|
||||
} from '@/app/api/chat/utils'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { chat, workflow } from '@/db/schema'
|
||||
|
||||
const logger = createLogger('ChatSubdomainAPI')
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('Chat Edit API Route', () => {
|
||||
}))
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/edit/chat-123')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await GET(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -111,7 +111,7 @@ describe('Chat Edit API Route', () => {
|
||||
mockCheckChatAccess.mockResolvedValue({ hasAccess: false })
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/edit/chat-123')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await GET(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
@@ -138,7 +138,7 @@ describe('Chat Edit API Route', () => {
|
||||
mockCheckChatAccess.mockResolvedValue({ hasAccess: true, chat: mockChat })
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/edit/chat-123')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await GET(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -164,7 +164,7 @@ describe('Chat Edit API Route', () => {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ title: 'Updated Chat' }),
|
||||
})
|
||||
const { PATCH } = await import('./route')
|
||||
const { PATCH } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await PATCH(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -184,7 +184,7 @@ describe('Chat Edit API Route', () => {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ title: 'Updated Chat' }),
|
||||
})
|
||||
const { PATCH } = await import('./route')
|
||||
const { PATCH } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await PATCH(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
@@ -212,7 +212,7 @@ describe('Chat Edit API Route', () => {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ title: 'Updated Chat', description: 'Updated description' }),
|
||||
})
|
||||
const { PATCH } = await import('./route')
|
||||
const { PATCH } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await PATCH(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -245,7 +245,7 @@ describe('Chat Edit API Route', () => {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ subdomain: 'new-subdomain' }),
|
||||
})
|
||||
const { PATCH } = await import('./route')
|
||||
const { PATCH } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await PATCH(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
@@ -273,7 +273,7 @@ describe('Chat Edit API Route', () => {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ authType: 'password' }), // No password provided
|
||||
})
|
||||
const { PATCH } = await import('./route')
|
||||
const { PATCH } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await PATCH(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
@@ -304,7 +304,7 @@ describe('Chat Edit API Route', () => {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ title: 'Admin Updated Chat' }),
|
||||
})
|
||||
const { PATCH } = await import('./route')
|
||||
const { PATCH } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await PATCH(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -321,7 +321,7 @@ describe('Chat Edit API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/edit/chat-123', {
|
||||
method: 'DELETE',
|
||||
})
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await DELETE(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -340,7 +340,7 @@ describe('Chat Edit API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/edit/chat-123', {
|
||||
method: 'DELETE',
|
||||
})
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await DELETE(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
@@ -361,7 +361,7 @@ describe('Chat Edit API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/edit/chat-123', {
|
||||
method: 'DELETE',
|
||||
})
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await DELETE(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -385,7 +385,7 @@ describe('Chat Edit API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/edit/chat-123', {
|
||||
method: 'DELETE',
|
||||
})
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/chat/edit/[id]/route')
|
||||
const response = await DELETE(req, { params: Promise.resolve({ id: 'chat-123' }) })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
|
||||
@@ -89,7 +89,7 @@ describe('Chat API Route', () => {
|
||||
}))
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/chat')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/route')
|
||||
const response = await GET(req)
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -107,7 +107,7 @@ describe('Chat API Route', () => {
|
||||
mockWhere.mockResolvedValue(mockDeployments)
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/chat')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/route')
|
||||
const response = await GET(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -125,7 +125,7 @@ describe('Chat API Route', () => {
|
||||
mockWhere.mockRejectedValue(new Error('Database error'))
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/chat')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/route')
|
||||
const response = await GET(req)
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
@@ -143,7 +143,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({}),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -163,7 +163,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(invalidData),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
@@ -192,7 +192,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(validData),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
@@ -223,7 +223,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(validData),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
@@ -268,7 +268,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(validData),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -310,7 +310,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(validData),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -343,7 +343,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(validData),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
@@ -378,7 +378,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(validData),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
@@ -412,7 +412,7 @@ describe('Chat API Route', () => {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(validData),
|
||||
})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/chat/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
|
||||
@@ -93,7 +93,7 @@ describe('Subdomain Validation API Route', () => {
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/subdomains/validate?subdomain=test')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/subdomains/validate/route')
|
||||
|
||||
const response = await GET(req)
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('Subdomain Validation API Route', () => {
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/chat/subdomains/validate')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/subdomains/validate/route')
|
||||
|
||||
const response = await GET(req)
|
||||
|
||||
@@ -129,7 +129,7 @@ describe('Subdomain Validation API Route', () => {
|
||||
'http://localhost:3000/api/chat/subdomains/validate?subdomain=Invalid_Subdomain!'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/subdomains/validate/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -156,7 +156,7 @@ describe('Subdomain Validation API Route', () => {
|
||||
'http://localhost:3000/api/chat/subdomains/validate?subdomain=available-subdomain'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/subdomains/validate/route')
|
||||
|
||||
const response = await GET(req)
|
||||
|
||||
@@ -178,7 +178,7 @@ describe('Subdomain Validation API Route', () => {
|
||||
'http://localhost:3000/api/chat/subdomains/validate?subdomain=telemetry'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/subdomains/validate/route')
|
||||
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -205,7 +205,7 @@ describe('Subdomain Validation API Route', () => {
|
||||
'http://localhost:3000/api/chat/subdomains/validate?subdomain=used-subdomain'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/subdomains/validate/route')
|
||||
|
||||
const response = await GET(req)
|
||||
|
||||
@@ -229,7 +229,7 @@ describe('Subdomain Validation API Route', () => {
|
||||
'http://localhost:3000/api/chat/subdomains/validate?subdomain=error-subdomain'
|
||||
)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/chat/subdomains/validate/route')
|
||||
|
||||
const response = await GET(req)
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('Chat API Utils', () => {
|
||||
|
||||
describe('Auth token utils', () => {
|
||||
it.concurrent('should encrypt and validate auth tokens', async () => {
|
||||
const { encryptAuthToken, validateAuthToken } = await import('./utils')
|
||||
const { encryptAuthToken, validateAuthToken } = await import('@/app/api/chat/utils')
|
||||
|
||||
const subdomainId = 'test-subdomain-id'
|
||||
const type = 'password'
|
||||
@@ -83,7 +83,7 @@ describe('Chat API Utils', () => {
|
||||
})
|
||||
|
||||
it.concurrent('should reject expired tokens', async () => {
|
||||
const { validateAuthToken } = await import('./utils')
|
||||
const { validateAuthToken } = await import('@/app/api/chat/utils')
|
||||
|
||||
const subdomainId = 'test-subdomain-id'
|
||||
// Create an expired token by directly constructing it with an old timestamp
|
||||
@@ -98,7 +98,7 @@ describe('Chat API Utils', () => {
|
||||
|
||||
describe('Cookie handling', () => {
|
||||
it.concurrent('should set auth cookie correctly', async () => {
|
||||
const { setChatAuthCookie } = await import('./utils')
|
||||
const { setChatAuthCookie } = await import('@/app/api/chat/utils')
|
||||
|
||||
const mockSet = vi.fn()
|
||||
const mockResponse = {
|
||||
@@ -127,7 +127,7 @@ describe('Chat API Utils', () => {
|
||||
|
||||
describe('CORS handling', () => {
|
||||
it.concurrent('should add CORS headers for localhost in development', async () => {
|
||||
const { addCorsHeaders } = await import('./utils')
|
||||
const { addCorsHeaders } = await import('@/app/api/chat/utils')
|
||||
|
||||
const mockRequest = {
|
||||
headers: {
|
||||
@@ -162,7 +162,7 @@ describe('Chat API Utils', () => {
|
||||
})
|
||||
|
||||
it.concurrent('should handle OPTIONS request', async () => {
|
||||
const { OPTIONS } = await import('./utils')
|
||||
const { OPTIONS } = await import('@/app/api/chat/utils')
|
||||
|
||||
const mockRequest = {
|
||||
headers: {
|
||||
@@ -178,7 +178,7 @@ describe('Chat API Utils', () => {
|
||||
|
||||
describe('Chat auth validation', () => {
|
||||
beforeEach(() => {
|
||||
vi.doMock('./utils', async (importOriginal) => {
|
||||
vi.doMock('@/app/api/chat/utils', async (importOriginal) => {
|
||||
const original = (await importOriginal()) as any
|
||||
return {
|
||||
...original,
|
||||
@@ -200,7 +200,7 @@ describe('Chat API Utils', () => {
|
||||
})
|
||||
|
||||
it.concurrent('should allow access to public chats', async () => {
|
||||
const utils = await import('./utils')
|
||||
const utils = await import('@/app/api/chat/utils')
|
||||
const { validateChatAuth } = utils
|
||||
|
||||
const deployment = {
|
||||
@@ -220,7 +220,7 @@ describe('Chat API Utils', () => {
|
||||
})
|
||||
|
||||
it.concurrent('should request password auth for GET requests', async () => {
|
||||
const { validateChatAuth } = await import('./utils')
|
||||
const { validateChatAuth } = await import('@/app/api/chat/utils')
|
||||
|
||||
const deployment = {
|
||||
id: 'chat-id',
|
||||
@@ -241,7 +241,7 @@ describe('Chat API Utils', () => {
|
||||
})
|
||||
|
||||
it('should validate password for POST requests', async () => {
|
||||
const { validateChatAuth } = await import('./utils')
|
||||
const { validateChatAuth } = await import('@/app/api/chat/utils')
|
||||
const { decryptSecret } = await import('@/lib/utils')
|
||||
|
||||
const deployment = {
|
||||
@@ -268,7 +268,7 @@ describe('Chat API Utils', () => {
|
||||
})
|
||||
|
||||
it.concurrent('should reject incorrect password', async () => {
|
||||
const { validateChatAuth } = await import('./utils')
|
||||
const { validateChatAuth } = await import('@/app/api/chat/utils')
|
||||
|
||||
const deployment = {
|
||||
id: 'chat-id',
|
||||
@@ -294,7 +294,7 @@ describe('Chat API Utils', () => {
|
||||
})
|
||||
|
||||
it.concurrent('should request email auth for email-protected chats', async () => {
|
||||
const { validateChatAuth } = await import('./utils')
|
||||
const { validateChatAuth } = await import('@/app/api/chat/utils')
|
||||
|
||||
const deployment = {
|
||||
id: 'chat-id',
|
||||
@@ -316,7 +316,7 @@ describe('Chat API Utils', () => {
|
||||
})
|
||||
|
||||
it.concurrent('should check allowed emails for email auth', async () => {
|
||||
const { validateChatAuth } = await import('./utils')
|
||||
const { validateChatAuth } = await import('@/app/api/chat/utils')
|
||||
|
||||
const deployment = {
|
||||
id: 'chat-id',
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('Codegen API Route', () => {
|
||||
generationType: 'json-schema',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -136,7 +136,7 @@ describe('Codegen API Route', () => {
|
||||
generationType: 'javascript-function-body',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -188,7 +188,7 @@ describe('Codegen API Route', () => {
|
||||
generationType: 'custom-tool-schema',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -217,7 +217,7 @@ describe('Codegen API Route', () => {
|
||||
context: 'existing function code here',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
|
||||
@@ -260,7 +260,7 @@ describe('Codegen API Route', () => {
|
||||
],
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
|
||||
@@ -287,7 +287,7 @@ describe('Codegen API Route', () => {
|
||||
generationType: 'json-schema',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -302,7 +302,7 @@ describe('Codegen API Route', () => {
|
||||
prompt: '',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -319,7 +319,7 @@ describe('Codegen API Route', () => {
|
||||
generationType: 'invalid-type',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -348,7 +348,7 @@ describe('Codegen API Route', () => {
|
||||
generationType: 'javascript-function-body',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -377,7 +377,7 @@ describe('Codegen API Route', () => {
|
||||
generationType: 'json-schema',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/codegen/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('File Delete API Route', () => {
|
||||
filePath: '/api/files/serve/test-file.txt',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/delete/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -42,7 +42,7 @@ describe('File Delete API Route', () => {
|
||||
filePath: '/api/files/serve/nonexistent.txt',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/delete/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -74,7 +74,7 @@ describe('File Delete API Route', () => {
|
||||
filePath: '/api/files/serve/s3/1234567890-test-file.txt',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/delete/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -109,7 +109,7 @@ describe('File Delete API Route', () => {
|
||||
filePath: '/api/files/serve/blob/1234567890-test-document.pdf',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/delete/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -127,7 +127,7 @@ describe('File Delete API Route', () => {
|
||||
|
||||
const req = createMockRequest('POST', {})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/delete/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -138,7 +138,7 @@ describe('File Delete API Route', () => {
|
||||
})
|
||||
|
||||
it('should handle CORS preflight requests', async () => {
|
||||
const { OPTIONS } = await import('./route')
|
||||
const { OPTIONS } = await import('@/app/api/files/delete/route')
|
||||
|
||||
const response = await OPTIONS()
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { NextRequest } from 'next/server'
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createMockRequest, setupFileApiMocks } from '@/app/api/__test-utils__/utils'
|
||||
import { POST } from './route'
|
||||
import { POST } from '@/app/api/files/parse/route'
|
||||
|
||||
const mockJoin = vi.fn((...args: string[]): string => {
|
||||
if (args[0] === '/test/uploads') {
|
||||
@@ -53,7 +53,7 @@ describe('File Parse API Route', () => {
|
||||
setupFileApiMocks()
|
||||
|
||||
const req = createMockRequest('POST', {})
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/parse/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -72,7 +72,7 @@ describe('File Parse API Route', () => {
|
||||
filePath: '/api/files/serve/test-file.txt',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/parse/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('File Parse API Route', () => {
|
||||
filePath: '/api/files/serve/s3/test-file.pdf',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/parse/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -120,7 +120,7 @@ describe('File Parse API Route', () => {
|
||||
filePath: ['/api/files/serve/file1.txt', '/api/files/serve/file2.txt'],
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/parse/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -157,7 +157,7 @@ describe('File Parse API Route', () => {
|
||||
}),
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/parse/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -184,7 +184,7 @@ describe('File Parse API Route', () => {
|
||||
filePath: '/api/files/serve/nonexistent.txt',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/parse/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 's3',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -51,7 +51,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 's3',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -75,7 +75,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 's3',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -99,7 +99,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 's3',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -124,7 +124,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 's3',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const largeFileSize = 150 * 1024 * 1024 // 150MB (exceeds 100MB limit)
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
@@ -150,7 +150,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 's3',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -182,7 +182,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 's3',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest(
|
||||
'http://localhost:3000/api/files/presigned?type=knowledge-base',
|
||||
@@ -210,7 +210,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 'blob',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -250,7 +250,7 @@ describe('/api/files/presigned', () => {
|
||||
isUsingCloudStorage: vi.fn().mockReturnValue(true),
|
||||
}))
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -293,7 +293,7 @@ describe('/api/files/presigned', () => {
|
||||
getSignedUrl: vi.fn().mockRejectedValue(new Error('S3 service unavailable')),
|
||||
}))
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -339,7 +339,7 @@ describe('/api/files/presigned', () => {
|
||||
sanitizeFilenameForMetadata: vi.fn((filename) => filename),
|
||||
}))
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -364,7 +364,7 @@ describe('/api/files/presigned', () => {
|
||||
storageProvider: 's3',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const request = new NextRequest('http://localhost:3000/api/files/presigned', {
|
||||
method: 'POST',
|
||||
@@ -382,7 +382,7 @@ describe('/api/files/presigned', () => {
|
||||
|
||||
describe('OPTIONS', () => {
|
||||
it('should handle CORS preflight requests', async () => {
|
||||
const { OPTIONS } = await import('./route')
|
||||
const { OPTIONS } = await import('@/app/api/files/presigned/route')
|
||||
|
||||
const response = await OPTIONS()
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ describe('File Serve API Route', () => {
|
||||
it('should serve local file successfully', async () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/files/serve/test-file.txt')
|
||||
const params = { path: ['test-file.txt'] }
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/files/serve/[...path]/route')
|
||||
|
||||
const response = await GET(req, { params: Promise.resolve(params) })
|
||||
|
||||
@@ -107,7 +107,7 @@ describe('File Serve API Route', () => {
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/files/serve/nested/path/file.txt')
|
||||
const params = { path: ['nested', 'path', 'file.txt'] }
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/files/serve/[...path]/route')
|
||||
|
||||
const response = await GET(req, { params: Promise.resolve(params) })
|
||||
|
||||
@@ -163,7 +163,7 @@ describe('File Serve API Route', () => {
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/files/serve/s3/1234567890-image.png')
|
||||
const params = { path: ['s3', '1234567890-image.png'] }
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/files/serve/[...path]/route')
|
||||
|
||||
const response = await GET(req, { params: Promise.resolve(params) })
|
||||
|
||||
@@ -208,7 +208,7 @@ describe('File Serve API Route', () => {
|
||||
|
||||
const req = new NextRequest('http://localhost:3000/api/files/serve/nonexistent.txt')
|
||||
const params = { path: ['nonexistent.txt'] }
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/files/serve/[...path]/route')
|
||||
|
||||
const response = await GET(req, { params: Promise.resolve(params) })
|
||||
|
||||
@@ -249,7 +249,7 @@ describe('File Serve API Route', () => {
|
||||
|
||||
const req = new NextRequest(`http://localhost:3000/api/files/serve/file.${test.ext}`)
|
||||
const params = { path: [`file.${test.ext}`] }
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/files/serve/[...path]/route')
|
||||
|
||||
const response = await GET(req, { params: Promise.resolve(params) })
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ describe('File Upload API Route', () => {
|
||||
body: formData,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/upload/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -77,7 +77,7 @@ describe('File Upload API Route', () => {
|
||||
body: formData,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/upload/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -108,7 +108,7 @@ describe('File Upload API Route', () => {
|
||||
body: formData,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/upload/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -128,7 +128,7 @@ describe('File Upload API Route', () => {
|
||||
body: formData,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/upload/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -157,7 +157,7 @@ describe('File Upload API Route', () => {
|
||||
body: formData,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/files/upload/route')
|
||||
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -168,7 +168,7 @@ describe('File Upload API Route', () => {
|
||||
})
|
||||
|
||||
it('should handle CORS preflight requests', async () => {
|
||||
const { OPTIONS } = await import('./route')
|
||||
const { OPTIONS } = await import('@/app/api/files/upload/route')
|
||||
|
||||
const response = await OPTIONS()
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ import { v4 as uuidv4 } from 'uuid'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { isUsingCloudStorage, uploadFile } from '@/lib/uploads'
|
||||
import { UPLOAD_DIR } from '@/lib/uploads/setup'
|
||||
// Import to ensure the uploads directory is created
|
||||
import '@/lib/uploads/setup.server'
|
||||
|
||||
import { createErrorResponse, createOptionsResponse, InvalidRequestError } from '../utils'
|
||||
import {
|
||||
createErrorResponse,
|
||||
createOptionsResponse,
|
||||
InvalidRequestError,
|
||||
} from '@/app/api/files/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -160,7 +160,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -178,7 +178,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -200,7 +200,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -222,7 +222,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -244,7 +244,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -266,7 +266,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -300,7 +300,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
await PUT(req, { params })
|
||||
|
||||
@@ -321,7 +321,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -347,7 +347,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -372,7 +372,7 @@ describe('Individual Folder API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -404,7 +404,7 @@ describe('Individual Folder API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'folder-3' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
@@ -430,7 +430,7 @@ describe('Individual Folder API Route', () => {
|
||||
const req = createMockRequest('DELETE')
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
@@ -450,7 +450,7 @@ describe('Individual Folder API Route', () => {
|
||||
const req = createMockRequest('DELETE')
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
@@ -470,7 +470,7 @@ describe('Individual Folder API Route', () => {
|
||||
const req = createMockRequest('DELETE')
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
@@ -490,7 +490,7 @@ describe('Individual Folder API Route', () => {
|
||||
const req = createMockRequest('DELETE')
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
@@ -512,7 +512,7 @@ describe('Individual Folder API Route', () => {
|
||||
const req = createMockRequest('DELETE')
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
@@ -533,7 +533,7 @@ describe('Individual Folder API Route', () => {
|
||||
const req = createMockRequest('DELETE')
|
||||
const params = Promise.resolve({ id: 'folder-1' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/folders/[id]/route')
|
||||
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ describe('Folders API Route', () => {
|
||||
value: 'http://localhost:3000/api/folders?workspaceId=workspace-123',
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/folders/route')
|
||||
const response = await GET(mockRequest)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -124,7 +124,7 @@ describe('Folders API Route', () => {
|
||||
value: 'http://localhost:3000/api/folders?workspaceId=workspace-123',
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/folders/route')
|
||||
const response = await GET(mockRequest)
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -141,7 +141,7 @@ describe('Folders API Route', () => {
|
||||
value: 'http://localhost:3000/api/folders',
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/folders/route')
|
||||
const response = await GET(mockRequest)
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
@@ -159,7 +159,7 @@ describe('Folders API Route', () => {
|
||||
value: 'http://localhost:3000/api/folders?workspaceId=workspace-123',
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/folders/route')
|
||||
const response = await GET(mockRequest)
|
||||
|
||||
expect(response.status).toBe(403)
|
||||
@@ -177,7 +177,7 @@ describe('Folders API Route', () => {
|
||||
value: 'http://localhost:3000/api/folders?workspaceId=workspace-123',
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/folders/route')
|
||||
const response = await GET(mockRequest)
|
||||
|
||||
expect(response.status).toBe(200) // Should work for read permissions
|
||||
@@ -198,7 +198,7 @@ describe('Folders API Route', () => {
|
||||
value: 'http://localhost:3000/api/folders?workspaceId=workspace-123',
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/folders/route')
|
||||
const response = await GET(mockRequest)
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
@@ -241,7 +241,7 @@ describe('Folders API Route', () => {
|
||||
color: '#6B7280',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -283,7 +283,7 @@ describe('Folders API Route', () => {
|
||||
workspaceId: 'workspace-123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -310,7 +310,7 @@ describe('Folders API Route', () => {
|
||||
parentId: 'folder-1',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -329,7 +329,7 @@ describe('Folders API Route', () => {
|
||||
workspaceId: 'workspace-123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -347,7 +347,7 @@ describe('Folders API Route', () => {
|
||||
workspaceId: 'workspace-123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(403)
|
||||
@@ -385,7 +385,7 @@ describe('Folders API Route', () => {
|
||||
workspaceId: 'workspace-123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -423,7 +423,7 @@ describe('Folders API Route', () => {
|
||||
workspaceId: 'workspace-123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -445,7 +445,7 @@ describe('Folders API Route', () => {
|
||||
|
||||
const req = createMockRequest('POST', body)
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
@@ -468,7 +468,7 @@ describe('Folders API Route', () => {
|
||||
workspaceId: 'workspace-123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
@@ -513,7 +513,7 @@ describe('Folders API Route', () => {
|
||||
workspaceId: 'workspace-123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
await POST(req)
|
||||
|
||||
expect(capturedValues).not.toBeNull()
|
||||
@@ -553,7 +553,7 @@ describe('Folders API Route', () => {
|
||||
workspaceId: 'workspace-123',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/folders/route')
|
||||
await POST(req)
|
||||
|
||||
expect(capturedValues).not.toBeNull()
|
||||
|
||||
@@ -65,7 +65,7 @@ describe('Function Execute API Route', () => {
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -80,7 +80,7 @@ describe('Function Execute API Route', () => {
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('Function Execute API Route', () => {
|
||||
code: 'return "test"',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -116,7 +116,7 @@ describe('Function Execute API Route', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -131,7 +131,7 @@ describe('Function Execute API Route', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -149,7 +149,7 @@ describe('Function Execute API Route', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -165,7 +165,7 @@ describe('Function Execute API Route', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -199,7 +199,7 @@ describe('Function Execute API Route', () => {
|
||||
params: gmailData,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -221,7 +221,7 @@ describe('Function Execute API Route', () => {
|
||||
params: complexEmailData,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -234,7 +234,7 @@ describe('Function Execute API Route', () => {
|
||||
code: 'return "freestyle test"',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
await POST(req)
|
||||
|
||||
expect(mockFreestyleExecuteScript).toHaveBeenCalled()
|
||||
@@ -250,7 +250,7 @@ describe('Function Execute API Route', () => {
|
||||
code: 'return "fallback test"',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(mockFreestyleExecuteScript).toHaveBeenCalled()
|
||||
@@ -271,7 +271,7 @@ describe('Function Execute API Route', () => {
|
||||
code: 'return undefinedVariable',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
@@ -293,7 +293,7 @@ describe('Function Execute API Route', () => {
|
||||
code: 'return "vm test"',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
await POST(req)
|
||||
|
||||
expect(mockFreestyleExecuteScript).not.toHaveBeenCalled()
|
||||
@@ -319,7 +319,7 @@ describe('Function Execute API Route', () => {
|
||||
code: 'return invalidCode(',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
@@ -339,7 +339,7 @@ describe('Function Execute API Route', () => {
|
||||
isCustomTool: true,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -355,7 +355,7 @@ describe('Function Execute API Route', () => {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
@@ -367,7 +367,7 @@ describe('Function Execute API Route', () => {
|
||||
timeout: 10000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
await POST(req)
|
||||
|
||||
expect(mockLogger.info).toHaveBeenCalledWith(
|
||||
@@ -384,7 +384,7 @@ describe('Function Execute API Route', () => {
|
||||
params: {},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -417,7 +417,7 @@ SyntaxError: Invalid or unexpected token
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -460,7 +460,7 @@ SyntaxError: Invalid or unexpected token
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -501,7 +501,7 @@ SyntaxError: Invalid or unexpected token
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -531,7 +531,7 @@ SyntaxError: Invalid or unexpected token
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -567,7 +567,7 @@ SyntaxError: Invalid or unexpected token
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -598,7 +598,7 @@ SyntaxError: Invalid or unexpected token
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -620,7 +620,7 @@ SyntaxError: Invalid or unexpected token
|
||||
},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -644,7 +644,7 @@ SyntaxError: Invalid or unexpected token
|
||||
},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -705,7 +705,7 @@ describe('Function Execute API - Template Variable Edge Cases', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -730,7 +730,7 @@ describe('Function Execute API - Template Variable Edge Cases', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -752,7 +752,7 @@ describe('Function Execute API - Template Variable Edge Cases', () => {
|
||||
params: {},
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/function/execute/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import { db } from '@/db'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
import { createErrorResponse } from '@/app/api/workflows/utils'
|
||||
import { apiKey as apiKeyTable } from '@/db/schema'
|
||||
import { createErrorResponse } from '../../workflows/utils'
|
||||
|
||||
const logger = createLogger('TaskStatusAPI')
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ import { createLogger } from '@/lib/logs/console/logger'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
import { checkChunkAccess } from '@/app/api/knowledge/utils'
|
||||
import { db } from '@/db'
|
||||
import { document, embedding } from '@/db/schema'
|
||||
import { checkChunkAccess } from '../../../../../utils'
|
||||
|
||||
const logger = createLogger('ChunkByIdAPI')
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validChunkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -213,7 +213,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', workflowData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -226,7 +226,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
mockGetUserId.mockResolvedValue(null)
|
||||
|
||||
const req = createMockRequest('POST', validChunkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -243,7 +243,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
mockGetUserId.mockResolvedValue(null)
|
||||
|
||||
const req = createMockRequest('POST', workflowData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -262,7 +262,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validChunkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -281,7 +281,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validChunkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -303,7 +303,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
} as any)
|
||||
|
||||
const req = createMockRequest('POST', validChunkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -326,7 +326,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
}
|
||||
|
||||
const req = createMockRequest('POST', invalidData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -367,7 +367,7 @@ describe('Knowledge Document Chunks API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validChunkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/[documentId]/chunks/route')
|
||||
await POST(req, { params: mockParams })
|
||||
|
||||
expect(mockTx.values).toHaveBeenCalled()
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
|
||||
mockKnowledgeSchemas()
|
||||
|
||||
vi.mock('../../../utils', () => ({
|
||||
vi.mock('@/app/api/knowledge/utils', () => ({
|
||||
checkKnowledgeBaseAccess: vi.fn(),
|
||||
checkKnowledgeBaseWriteAccess: vi.fn(),
|
||||
checkDocumentAccess: vi.fn(),
|
||||
@@ -98,7 +98,7 @@ describe('Document By ID API Route', () => {
|
||||
const mockParams = Promise.resolve({ id: 'kb-123', documentId: 'doc-123' })
|
||||
|
||||
it('should retrieve document successfully for authenticated user', async () => {
|
||||
const { checkDocumentAccess } = await import('../../../utils')
|
||||
const { checkDocumentAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentAccess).mockResolvedValue({
|
||||
@@ -108,7 +108,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -123,7 +123,7 @@ describe('Document By ID API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -132,7 +132,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should return not found for non-existent document', async () => {
|
||||
const { checkDocumentAccess } = await import('../../../utils')
|
||||
const { checkDocumentAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentAccess).mockResolvedValue({
|
||||
@@ -142,7 +142,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -151,7 +151,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should return unauthorized for document without access', async () => {
|
||||
const { checkDocumentAccess } = await import('../../../utils')
|
||||
const { checkDocumentAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentAccess).mockResolvedValue({
|
||||
@@ -160,7 +160,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -169,13 +169,13 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should handle database errors', async () => {
|
||||
const { checkDocumentAccess } = await import('../../../utils')
|
||||
const { checkDocumentAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentAccess).mockRejectedValue(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -194,7 +194,7 @@ describe('Document By ID API Route', () => {
|
||||
}
|
||||
|
||||
it('should update document successfully', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -223,7 +223,7 @@ describe('Document By ID API Route', () => {
|
||||
mockDbChain.select.mockReturnValue(selectChain)
|
||||
|
||||
const req = createMockRequest('PUT', validUpdateData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -236,7 +236,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should validate update data', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -252,7 +252,7 @@ describe('Document By ID API Route', () => {
|
||||
}
|
||||
|
||||
const req = createMockRequest('PUT', invalidData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -266,7 +266,7 @@ describe('Document By ID API Route', () => {
|
||||
const mockParams = Promise.resolve({ id: 'kb-123', documentId: 'doc-123' })
|
||||
|
||||
it('should mark document as failed due to timeout successfully', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
const processingDocument = {
|
||||
...mockDocument,
|
||||
@@ -303,7 +303,7 @@ describe('Document By ID API Route', () => {
|
||||
mockDbChain.select.mockReturnValue(selectChain)
|
||||
|
||||
const req = createMockRequest('PUT', { markFailedDueToTimeout: true })
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -320,7 +320,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should reject marking failed for non-processing document', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -330,7 +330,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('PUT', { markFailedDueToTimeout: true })
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -339,7 +339,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should reject marking failed for recently started processing', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
const recentProcessingDocument = {
|
||||
...mockDocument,
|
||||
@@ -355,7 +355,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('PUT', { markFailedDueToTimeout: true })
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -368,7 +368,9 @@ describe('Document By ID API Route', () => {
|
||||
const mockParams = Promise.resolve({ id: 'kb-123', documentId: 'doc-123' })
|
||||
|
||||
it('should retry processing successfully', async () => {
|
||||
const { checkDocumentWriteAccess, processDocumentAsync } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess, processDocumentAsync } = await import(
|
||||
'@/app/api/knowledge/utils'
|
||||
)
|
||||
|
||||
const failedDocument = {
|
||||
...mockDocument,
|
||||
@@ -401,7 +403,7 @@ describe('Document By ID API Route', () => {
|
||||
vi.mocked(processDocumentAsync).mockResolvedValue(undefined)
|
||||
|
||||
const req = createMockRequest('PUT', { retryProcessing: true })
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -414,7 +416,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should reject retry for non-failed document', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -424,7 +426,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('PUT', { retryProcessing: true })
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -441,7 +443,7 @@ describe('Document By ID API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('PUT', validUpdateData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -450,7 +452,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should return not found for non-existent document', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -460,7 +462,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('PUT', validUpdateData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -469,7 +471,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should handle database errors during update', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -480,7 +482,7 @@ describe('Document By ID API Route', () => {
|
||||
mockDbChain.set.mockRejectedValue(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('PUT', validUpdateData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -493,7 +495,7 @@ describe('Document By ID API Route', () => {
|
||||
const mockParams = Promise.resolve({ id: 'kb-123', documentId: 'doc-123' })
|
||||
|
||||
it('should delete document successfully', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -508,7 +510,7 @@ describe('Document By ID API Route', () => {
|
||||
mockDbChain.where.mockResolvedValue(undefined) // Update operation resolves
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -527,7 +529,7 @@ describe('Document By ID API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -536,7 +538,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should return not found for non-existent document', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -546,7 +548,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -555,7 +557,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should return unauthorized for document without access', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -564,7 +566,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -573,7 +575,7 @@ describe('Document By ID API Route', () => {
|
||||
})
|
||||
|
||||
it('should handle database errors during deletion', async () => {
|
||||
const { checkDocumentWriteAccess } = await import('../../../utils')
|
||||
const { checkDocumentWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkDocumentWriteAccess).mockResolvedValue({
|
||||
@@ -584,7 +586,7 @@ describe('Document By ID API Route', () => {
|
||||
mockDbChain.set.mockRejectedValue(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/documents/[documentId]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
|
||||
@@ -6,9 +6,13 @@ import { createLogger } from '@/lib/logs/console/logger'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
import {
|
||||
checkDocumentAccess,
|
||||
checkDocumentWriteAccess,
|
||||
processDocumentAsync,
|
||||
} from '@/app/api/knowledge/utils'
|
||||
import { db } from '@/db'
|
||||
import { document, embedding } from '@/db/schema'
|
||||
import { checkDocumentAccess, checkDocumentWriteAccess, processDocumentAsync } from '../../../utils'
|
||||
|
||||
const logger = createLogger('DocumentByIdAPI')
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
|
||||
mockKnowledgeSchemas()
|
||||
|
||||
vi.mock('../../utils', () => ({
|
||||
vi.mock('@/app/api/knowledge/utils', () => ({
|
||||
checkKnowledgeBaseAccess: vi.fn(),
|
||||
checkKnowledgeBaseWriteAccess: vi.fn(),
|
||||
checkDocumentAccess: vi.fn(),
|
||||
@@ -95,10 +95,13 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
const mockParams = Promise.resolve({ id: 'kb-123' })
|
||||
|
||||
it('should retrieve documents successfully for authenticated user', async () => {
|
||||
const { checkKnowledgeBaseAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
|
||||
// Mock the count query (first query)
|
||||
mockDbChain.where.mockResolvedValueOnce([{ count: 1 }])
|
||||
@@ -107,7 +110,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
mockDbChain.offset.mockResolvedValue([mockDocument])
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -120,10 +123,13 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should filter disabled documents by default', async () => {
|
||||
const { checkKnowledgeBaseAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
|
||||
// Mock the count query (first query)
|
||||
mockDbChain.where.mockResolvedValueOnce([{ count: 1 }])
|
||||
@@ -132,7 +138,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
mockDbChain.offset.mockResolvedValue([mockDocument])
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -140,10 +146,13 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should include disabled documents when requested', async () => {
|
||||
const { checkKnowledgeBaseAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
|
||||
// Mock the count query (first query)
|
||||
mockDbChain.where.mockResolvedValueOnce([{ count: 1 }])
|
||||
@@ -154,7 +163,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
const url = 'http://localhost:3000/api/knowledge/kb-123/documents?includeDisabled=true'
|
||||
const req = new Request(url, { method: 'GET' }) as any
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -164,7 +173,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -173,13 +182,16 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should return not found for non-existent knowledge base', async () => {
|
||||
const { checkKnowledgeBaseAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({ hasAccess: false, notFound: true })
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({
|
||||
hasAccess: false,
|
||||
notFound: true,
|
||||
})
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -188,13 +200,13 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should return unauthorized for knowledge base without access', async () => {
|
||||
const { checkKnowledgeBaseAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({ hasAccess: false })
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -203,14 +215,17 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should handle database errors', async () => {
|
||||
const { checkKnowledgeBaseAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
mockDbChain.orderBy.mockRejectedValue(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -229,14 +244,17 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
}
|
||||
|
||||
it('should create single document successfully', async () => {
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
mockDbChain.values.mockResolvedValue(undefined)
|
||||
|
||||
const req = createMockRequest('POST', validDocumentData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -248,10 +266,13 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should validate single document data', async () => {
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
|
||||
const invalidData = {
|
||||
filename: '', // Invalid: empty filename
|
||||
@@ -261,7 +282,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
}
|
||||
|
||||
const req = createMockRequest('POST', invalidData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -299,10 +320,15 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
}
|
||||
|
||||
it('should create bulk documents successfully', async () => {
|
||||
const { checkKnowledgeBaseWriteAccess, processDocumentAsync } = await import('../../utils')
|
||||
const { checkKnowledgeBaseWriteAccess, processDocumentAsync } = await import(
|
||||
'@/app/api/knowledge/utils'
|
||||
)
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
|
||||
// Mock transaction to return the created documents
|
||||
mockDbChain.transaction.mockImplementation(async (callback) => {
|
||||
@@ -317,7 +343,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
vi.mocked(processDocumentAsync).mockResolvedValue(undefined)
|
||||
|
||||
const req = createMockRequest('POST', validBulkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -330,10 +356,13 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should validate bulk document data', async () => {
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
|
||||
const invalidBulkData = {
|
||||
bulk: true,
|
||||
@@ -355,7 +384,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
}
|
||||
|
||||
const req = createMockRequest('POST', invalidBulkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -365,10 +394,15 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should handle processing errors gracefully', async () => {
|
||||
const { checkKnowledgeBaseWriteAccess, processDocumentAsync } = await import('../../utils')
|
||||
const { checkKnowledgeBaseWriteAccess, processDocumentAsync } = await import(
|
||||
'@/app/api/knowledge/utils'
|
||||
)
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
|
||||
// Mock transaction to succeed but processing to fail
|
||||
mockDbChain.transaction.mockImplementation(async (callback) => {
|
||||
@@ -384,7 +418,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
vi.mocked(processDocumentAsync).mockResolvedValue(undefined)
|
||||
|
||||
const req = createMockRequest('POST', validBulkData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -408,7 +442,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('POST', validDocumentData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -417,7 +451,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should return not found for non-existent knowledge base', async () => {
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({
|
||||
@@ -426,7 +460,7 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validDocumentData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -435,13 +469,13 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should return unauthorized for knowledge base without access', async () => {
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({ hasAccess: false })
|
||||
|
||||
const req = createMockRequest('POST', validDocumentData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -450,14 +484,17 @@ describe('Knowledge Base Documents API Route', () => {
|
||||
})
|
||||
|
||||
it('should handle database errors during creation', async () => {
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('../../utils')
|
||||
const { checkKnowledgeBaseWriteAccess } = await import('@/app/api/knowledge/utils')
|
||||
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({ hasAccess: true })
|
||||
vi.mocked(checkKnowledgeBaseWriteAccess).mockResolvedValue({
|
||||
hasAccess: true,
|
||||
knowledgeBase: { id: 'kb-123', userId: 'user-123' },
|
||||
})
|
||||
mockDbChain.values.mockRejectedValue(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('POST', validDocumentData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/[id]/documents/route')
|
||||
const response = await POST(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ import { z } from 'zod'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { getUserId } from '@/app/api/auth/oauth/utils'
|
||||
import { db } from '@/db'
|
||||
import { document } from '@/db/schema'
|
||||
import {
|
||||
checkKnowledgeBaseAccess,
|
||||
checkKnowledgeBaseWriteAccess,
|
||||
processDocumentAsync,
|
||||
} from '../../utils'
|
||||
} from '@/app/api/knowledge/utils'
|
||||
import { db } from '@/db'
|
||||
import { document } from '@/db/schema'
|
||||
|
||||
const logger = createLogger('DocumentsAPI')
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.limit.mockResolvedValueOnce([mockKnowledgeBase])
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -108,7 +108,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.limit.mockResolvedValueOnce([])
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -122,7 +122,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.limit.mockResolvedValueOnce([{ id: 'kb-123', userId: 'different-user' }])
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -135,7 +135,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.limit.mockRejectedValueOnce(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await GET(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -165,7 +165,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.limit.mockResolvedValueOnce([{ ...mockKnowledgeBase, ...validUpdateData }])
|
||||
|
||||
const req = createMockRequest('PUT', validUpdateData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -179,7 +179,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('PUT', validUpdateData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -196,7 +196,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.limit.mockResolvedValueOnce([])
|
||||
|
||||
const req = createMockRequest('PUT', validUpdateData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -217,7 +217,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
}
|
||||
|
||||
const req = createMockRequest('PUT', invalidData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -234,7 +234,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.where.mockRejectedValueOnce(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('PUT', validUpdateData)
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await PUT(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -257,7 +257,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.where.mockResolvedValueOnce(undefined)
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -271,7 +271,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -288,7 +288,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.limit.mockResolvedValueOnce([])
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -305,7 +305,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.limit.mockResolvedValueOnce([{ id: 'kb-123', userId: 'different-user' }])
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -321,7 +321,7 @@ describe('Knowledge Base By ID API Route', () => {
|
||||
mockDbChain.where.mockRejectedValueOnce(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('DELETE')
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/knowledge/[id]/route')
|
||||
const response = await DELETE(req, { params: mockParams })
|
||||
const data = await response.json()
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('Knowledge Base API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/route')
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('Knowledge Base API Route', () => {
|
||||
mockDbChain.orderBy.mockRejectedValue(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/knowledge/route')
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('Knowledge Base API Route', () => {
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
|
||||
const req = createMockRequest('POST', validKnowledgeBaseData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -112,7 +112,7 @@ describe('Knowledge Base API Route', () => {
|
||||
mockAuth$.mockUnauthenticated()
|
||||
|
||||
const req = createMockRequest('POST', validKnowledgeBaseData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -124,7 +124,7 @@ describe('Knowledge Base API Route', () => {
|
||||
mockAuth$.mockAuthenticatedUser()
|
||||
|
||||
const req = createMockRequest('POST', { description: 'Missing name' })
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -146,7 +146,7 @@ describe('Knowledge Base API Route', () => {
|
||||
}
|
||||
|
||||
const req = createMockRequest('POST', invalidData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -159,7 +159,7 @@ describe('Knowledge Base API Route', () => {
|
||||
|
||||
const minimalData = { name: 'Test KB' }
|
||||
const req = createMockRequest('POST', minimalData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -178,7 +178,7 @@ describe('Knowledge Base API Route', () => {
|
||||
mockDbChain.values.mockRejectedValue(new Error('Database error'))
|
||||
|
||||
const req = createMockRequest('POST', validKnowledgeBaseData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -200,7 +200,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', multiKbData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -234,7 +234,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', workflowData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -247,7 +247,7 @@ describe('Knowledge Search API Route', () => {
|
||||
mockGetUserId.mockResolvedValue(null)
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -264,7 +264,7 @@ describe('Knowledge Search API Route', () => {
|
||||
mockGetUserId.mockResolvedValue(null)
|
||||
|
||||
const req = createMockRequest('POST', workflowData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -282,7 +282,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -304,7 +304,7 @@ describe('Knowledge Search API Route', () => {
|
||||
.mockResolvedValueOnce({ hasAccess: false, notFound: true })
|
||||
|
||||
const req = createMockRequest('POST', multiKbData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -320,7 +320,7 @@ describe('Knowledge Search API Route', () => {
|
||||
}
|
||||
|
||||
const req = createMockRequest('POST', invalidData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -354,7 +354,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', dataWithoutTopK)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -374,7 +374,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -393,7 +393,7 @@ describe('Knowledge Search API Route', () => {
|
||||
mockDbChain.limit.mockResolvedValueOnce(mockKnowledgeBases)
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -415,7 +415,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -436,7 +436,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -465,7 +465,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
@@ -513,7 +513,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', validSearchData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
await POST(req)
|
||||
|
||||
// Verify token estimation was called with correct parameters
|
||||
@@ -570,7 +570,7 @@ describe('Knowledge Search API Route', () => {
|
||||
})
|
||||
|
||||
const req = createMockRequest('POST', longQueryData)
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/knowledge/search/route')
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ import {
|
||||
checkKnowledgeBaseAccess,
|
||||
generateEmbeddings,
|
||||
processDocumentAsync,
|
||||
} from './utils'
|
||||
} from '@/app/api/knowledge/utils'
|
||||
|
||||
describe('Knowledge Utils', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { subscription, user, workflow, workflowExecutionLogs } from '@/db/schema
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('LogsCleanup')
|
||||
const logger = createLogger('LogsCleanupAPI')
|
||||
|
||||
const BATCH_SIZE = 2000
|
||||
const S3_CONFIG = {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { db } from '@/db'
|
||||
import { invitation, member, permissions, workspaceInvitation } from '@/db/schema'
|
||||
|
||||
const logger = createLogger('OrganizationInvitationAcceptance')
|
||||
const logger = createLogger('OrganizationInvitationAcceptanceAPI')
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('Schedule Status API Route', () => {
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/[id]/status/route')
|
||||
|
||||
const res = await GET(req, { params: Promise.resolve({ id: 'schedule-id' }) })
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('Schedule Status API Route', () => {
|
||||
}))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/[id]/status/route')
|
||||
const res = await GET(req, { params: Promise.resolve({ id: 'schedule-id' }) })
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
@@ -85,7 +85,7 @@ describe('Schedule Status API Route', () => {
|
||||
}))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/[id]/status/route')
|
||||
const res = await GET(req, { params: Promise.resolve({ id: 'missing-id' }) })
|
||||
|
||||
expect(res.status).toBe(404)
|
||||
@@ -101,7 +101,7 @@ describe('Schedule Status API Route', () => {
|
||||
}))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/[id]/status/route')
|
||||
const res = await GET(req, { params: Promise.resolve({ id: 'schedule-id' }) })
|
||||
|
||||
expect(res.status).toBe(404)
|
||||
@@ -117,7 +117,7 @@ describe('Schedule Status API Route', () => {
|
||||
}))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/[id]/status/route')
|
||||
const res = await GET(req, { params: Promise.resolve({ id: 'schedule-id' }) })
|
||||
|
||||
expect(res.status).toBe(403)
|
||||
@@ -133,7 +133,7 @@ describe('Schedule Status API Route', () => {
|
||||
}))
|
||||
|
||||
const req = createMockRequest('GET')
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/[id]/status/route')
|
||||
const res = await GET(req, { params: Promise.resolve({ id: 'schedule-id' }) })
|
||||
|
||||
expect(res.status).toBe(401)
|
||||
|
||||
@@ -121,7 +121,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
||||
})),
|
||||
}))
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/execute/route')
|
||||
const response = await GET()
|
||||
expect(response).toBeDefined()
|
||||
|
||||
@@ -137,7 +137,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
||||
})),
|
||||
}))
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/execute/route')
|
||||
const response = await GET()
|
||||
|
||||
expect(response).toBeDefined()
|
||||
@@ -166,7 +166,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
||||
return { db: mockDb }
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/execute/route')
|
||||
const response = await GET()
|
||||
expect(response.status).toBe(200)
|
||||
const data = await response.json()
|
||||
@@ -194,7 +194,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
||||
return { db: mockDb }
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/execute/route')
|
||||
const response = await GET()
|
||||
expect(response.status).toBe(500)
|
||||
const data = await response.json()
|
||||
@@ -226,7 +226,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
||||
],
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/execute/route')
|
||||
const response = await GET()
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -256,7 +256,7 @@ describe('Scheduled Workflow Execution API Route', () => {
|
||||
],
|
||||
})
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/schedules/execute/route')
|
||||
const response = await GET()
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
|
||||
@@ -156,7 +156,7 @@ describe('Schedule Configuration API Route', () => {
|
||||
})
|
||||
|
||||
// Import the route handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/schedules/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -251,7 +251,7 @@ describe('Schedule Configuration API Route', () => {
|
||||
}))
|
||||
|
||||
// Import the route handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/schedules/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -328,7 +328,7 @@ describe('Schedule Configuration API Route', () => {
|
||||
})
|
||||
|
||||
// Import the route handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/schedules/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -370,7 +370,7 @@ describe('Schedule Configuration API Route', () => {
|
||||
})
|
||||
|
||||
// Import the route handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/schedules/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -397,7 +397,7 @@ describe('Schedule Configuration API Route', () => {
|
||||
})
|
||||
|
||||
// Import the route handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/schedules/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -420,7 +420,7 @@ describe('Schedule Configuration API Route', () => {
|
||||
})
|
||||
|
||||
// Import the route handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/schedules/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextResponse } from 'next/server'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { getConfluenceCloudId } from '@/tools/confluence/utils'
|
||||
|
||||
const logger = createLogger('ConfluencePages')
|
||||
const logger = createLogger('ConfluencePagesAPI')
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ describe('Custom Tools API Routes', () => {
|
||||
mockWhere.mockReturnValueOnce(Promise.resolve(sampleTools))
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await GET(req)
|
||||
@@ -190,7 +190,7 @@ describe('Custom Tools API Routes', () => {
|
||||
}))
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await GET(req)
|
||||
@@ -206,7 +206,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/tools/custom?workflowId=workflow-123')
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const _response = await GET(req)
|
||||
@@ -247,7 +247,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = createMockRequest('POST', { tools: [newTool] })
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -289,7 +289,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = createMockRequest('POST', { tools: [updateTool] })
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -315,7 +315,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = createMockRequest('POST', { tools: [] })
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -337,7 +337,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = createMockRequest('POST', { tools: [invalidTool] })
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req)
|
||||
@@ -362,7 +362,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/tools/custom?id=tool-1')
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await DELETE(req)
|
||||
@@ -382,7 +382,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = createMockRequest('DELETE')
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await DELETE(req)
|
||||
@@ -401,7 +401,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/tools/custom?id=non-existent')
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await DELETE(req)
|
||||
@@ -421,7 +421,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/tools/custom?id=tool-1')
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await DELETE(req)
|
||||
@@ -442,7 +442,7 @@ describe('Custom Tools API Routes', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/tools/custom?id=tool-1')
|
||||
|
||||
// Import handler after mocks are set up
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/tools/custom/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await DELETE(req)
|
||||
|
||||
@@ -7,7 +7,7 @@ import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('LinearProjects')
|
||||
const logger = createLogger('LinearProjectsAPI')
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('LinearTeams')
|
||||
const logger = createLogger('LinearTeamsAPI')
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('teams-chats')
|
||||
const logger = createLogger('TeamsChatsAPI')
|
||||
|
||||
// Helper function to get chat members and create a meaningful name
|
||||
const getChatDisplayName = async (
|
||||
|
||||
@@ -5,7 +5,7 @@ import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('teams-teams')
|
||||
const logger = createLogger('TeamsTeamsAPI')
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { z } from 'zod'
|
||||
import { env } from '@/lib/env'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { ensureZodObject, normalizeUrl } from '../utils'
|
||||
import { ensureZodObject, normalizeUrl } from '@/app/api/tools/stagehand/utils'
|
||||
|
||||
const logger = createLogger('StagehandAgentAPI')
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { z } from 'zod'
|
||||
import { env } from '@/lib/env'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { ensureZodObject, normalizeUrl } from '../utils'
|
||||
import { ensureZodObject, normalizeUrl } from '@/app/api/tools/stagehand/utils'
|
||||
|
||||
const logger = createLogger('StagehandExtractAPI')
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('Subscription Transfer API Routes', () => {
|
||||
organizationId: 'org-456',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/users/me/subscription/[id]/transfer/route')
|
||||
|
||||
const response = await POST(req, { params: Promise.resolve({ id: 'sub-123' }) })
|
||||
|
||||
@@ -120,7 +120,7 @@ describe('Subscription Transfer API Routes', () => {
|
||||
organizationId: 'org-456',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/users/me/subscription/[id]/transfer/route')
|
||||
|
||||
const response = await POST(req, { params: Promise.resolve({ id: 'sub-123' }) })
|
||||
const data = await response.json()
|
||||
@@ -149,7 +149,7 @@ describe('Subscription Transfer API Routes', () => {
|
||||
organizationId: 'org-456',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/users/me/subscription/[id]/transfer/route')
|
||||
|
||||
const response = await POST(req, { params: Promise.resolve({ id: 'sub-123' }) })
|
||||
const data = await response.json()
|
||||
@@ -174,7 +174,7 @@ describe('Subscription Transfer API Routes', () => {
|
||||
organizationId: 'org-456',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/users/me/subscription/[id]/transfer/route')
|
||||
|
||||
const response = await POST(req, { params: Promise.resolve({ id: 'sub-123' }) })
|
||||
const data = await response.json()
|
||||
@@ -214,7 +214,7 @@ describe('Subscription Transfer API Routes', () => {
|
||||
organizationId: 'org-456',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/users/me/subscription/[id]/transfer/route')
|
||||
|
||||
const response = await POST(req, { params: Promise.resolve({ id: 'sub-123' }) })
|
||||
const data = await response.json()
|
||||
@@ -227,7 +227,7 @@ describe('Subscription Transfer API Routes', () => {
|
||||
it('should reject invalid request parameters', async () => {
|
||||
const req = createMockRequest('POST', {})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/users/me/subscription/[id]/transfer/route')
|
||||
|
||||
const response = await POST(req, { params: Promise.resolve({ id: 'sub-123' }) })
|
||||
const data = await response.json()
|
||||
@@ -246,7 +246,7 @@ describe('Subscription Transfer API Routes', () => {
|
||||
organizationId: 'org-456',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/users/me/subscription/[id]/transfer/route')
|
||||
|
||||
const response = await POST(req, { params: Promise.resolve({ id: 'sub-123' }) })
|
||||
const data = await response.json()
|
||||
@@ -265,7 +265,7 @@ describe('Subscription Transfer API Routes', () => {
|
||||
organizationId: 'org-456',
|
||||
})
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/users/me/subscription/[id]/transfer/route')
|
||||
|
||||
const response = await POST(req, { params: Promise.resolve({ id: 'sub-123' }) })
|
||||
const data = await response.json()
|
||||
|
||||
@@ -5,10 +5,10 @@ import { createLogger } from '@/lib/logs/console/logger'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
import { createErrorResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { apiKey as apiKeyTable, subscription } from '@/db/schema'
|
||||
import { RateLimiter } from '@/services/queue'
|
||||
import { createErrorResponse } from '../../workflows/utils'
|
||||
|
||||
const logger = createLogger('RateLimitAPI')
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { env } from '@/lib/env'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { getOAuthToken } from '@/app/api/auth/oauth/utils'
|
||||
import { db } from '@/db'
|
||||
import { webhook, workflow } from '@/db/schema'
|
||||
import { getOAuthToken } from '../auth/oauth/utils'
|
||||
|
||||
const logger = createLogger('WebhooksAPI')
|
||||
|
||||
|
||||
@@ -63,11 +63,11 @@ vi.mock('@/lib/webhooks/utils', () => ({
|
||||
processWebhook: processWebhookMock,
|
||||
}))
|
||||
|
||||
vi.mock('./utils', () => ({
|
||||
vi.mock('@/app/api/webhooks/utils', () => ({
|
||||
generateRequestHash: generateRequestHashMock,
|
||||
}))
|
||||
|
||||
vi.mock('../../utils', () => ({
|
||||
vi.mock('@/app/api/webhooks/utils', () => ({
|
||||
validateSlackSignature: validateSlackSignatureMock,
|
||||
}))
|
||||
|
||||
@@ -230,7 +230,7 @@ describe('Webhook Trigger API Route', () => {
|
||||
const params = Promise.resolve({ path: 'whatsapp' })
|
||||
|
||||
// Import the handler after mocks are set up
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/webhooks/trigger/[path]/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await GET(req, { params })
|
||||
@@ -271,7 +271,7 @@ describe('Webhook Trigger API Route', () => {
|
||||
const params = Promise.resolve({ path: 'non-existent-path' })
|
||||
|
||||
// Import the handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/webhooks/trigger/[path]/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req, { params })
|
||||
@@ -328,7 +328,7 @@ describe('Webhook Trigger API Route', () => {
|
||||
const params = Promise.resolve({ path: 'test-path' })
|
||||
|
||||
// Import the handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/webhooks/trigger/[path]/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req, { params })
|
||||
@@ -398,7 +398,7 @@ describe('Webhook Trigger API Route', () => {
|
||||
const params = Promise.resolve({ path: 'test-path' })
|
||||
|
||||
// Import the handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/webhooks/trigger/[path]/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req, { params })
|
||||
@@ -484,7 +484,7 @@ describe('Webhook Trigger API Route', () => {
|
||||
const params = Promise.resolve({ path: 'airtable-path' })
|
||||
|
||||
// Import the handler after mocks are set up
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/webhooks/trigger/[path]/route')
|
||||
|
||||
// Call the handler
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.doMock('../../middleware', () => ({
|
||||
vi.doMock('@/app/api/workflows/middleware', () => ({
|
||||
validateWorkflowAccess: vi.fn().mockResolvedValue({
|
||||
workflow: {
|
||||
id: 'workflow-id',
|
||||
@@ -82,7 +82,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.doMock('../../utils', () => ({
|
||||
vi.doMock('@/app/api/workflows/utils', () => ({
|
||||
createSuccessResponse: vi.fn().mockImplementation((data) => {
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: 200,
|
||||
@@ -203,7 +203,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/deploy/route')
|
||||
|
||||
const response = await GET(req, { params })
|
||||
|
||||
@@ -281,7 +281,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/deploy/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -359,7 +359,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/deploy/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -391,7 +391,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/workflows/[id]/deploy/route')
|
||||
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
@@ -410,7 +410,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
* Test error handling
|
||||
*/
|
||||
it('should handle errors when workflow is not found', async () => {
|
||||
vi.doMock('../../middleware', () => ({
|
||||
vi.doMock('@/app/api/workflows/middleware', () => ({
|
||||
validateWorkflowAccess: vi.fn().mockResolvedValue({
|
||||
error: {
|
||||
message: 'Workflow not found',
|
||||
@@ -423,7 +423,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'invalid-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/deploy/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -438,7 +438,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
* Test unauthorized access
|
||||
*/
|
||||
it('should handle unauthorized access to workflow', async () => {
|
||||
vi.doMock('../../middleware', () => ({
|
||||
vi.doMock('@/app/api/workflows/middleware', () => ({
|
||||
validateWorkflowAccess: vi.fn().mockResolvedValue({
|
||||
error: {
|
||||
message: 'Unauthorized access',
|
||||
@@ -451,7 +451,7 @@ describe('Workflow Deployment API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/deploy/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ import type { NextRequest } from 'next/server'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { generateApiKey } from '@/lib/utils'
|
||||
import { validateWorkflowAccess } from '@/app/api/workflows/middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { apiKey, workflow, workflowBlocks, workflowEdges, workflowSubflows } from '@/db/schema'
|
||||
import { validateWorkflowAccess } from '../../middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '../../utils'
|
||||
|
||||
const logger = createLogger('WorkflowDeployAPI')
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { eq } from 'drizzle-orm'
|
||||
import type { NextRequest, NextResponse } from 'next/server'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { validateWorkflowAccess } from '@/app/api/workflows/middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { workflow } from '@/db/schema'
|
||||
import { validateWorkflowAccess } from '../../middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '../../utils'
|
||||
|
||||
const logger = createLogger('WorkflowDeployedStateAPI')
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ describe('Workflow Execution API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/execute/route')
|
||||
|
||||
const response = await GET(req, { params })
|
||||
|
||||
@@ -297,7 +297,7 @@ describe('Workflow Execution API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/execute/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -351,7 +351,7 @@ describe('Workflow Execution API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/execute/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -379,7 +379,7 @@ describe('Workflow Execution API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/execute/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -414,7 +414,7 @@ describe('Workflow Execution API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/execute/route')
|
||||
|
||||
const response = await POST(req, { params })
|
||||
|
||||
@@ -442,7 +442,7 @@ describe('Workflow Execution API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'invalid-workflow-id' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/execute/route')
|
||||
|
||||
const response = await GET(req, { params })
|
||||
|
||||
@@ -483,7 +483,7 @@ describe('Workflow Execution API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-id' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/execute/route')
|
||||
|
||||
const response = await GET(req, { params })
|
||||
|
||||
@@ -575,7 +575,7 @@ describe('Workflow Execution API Route', () => {
|
||||
|
||||
const params = Promise.resolve({ id: 'workflow-with-vars-id' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/execute/route')
|
||||
|
||||
await POST(req, { params })
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
updateWorkflowRunCounts,
|
||||
workflowHasResponseBlock,
|
||||
} from '@/lib/workflows/utils'
|
||||
import { validateWorkflowAccess } from '@/app/api/workflows/middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { environment as environmentTable, subscription, userStats } from '@/db/schema'
|
||||
import { Executor } from '@/executor'
|
||||
@@ -26,8 +28,6 @@ import {
|
||||
type TriggerType,
|
||||
} from '@/services/queue'
|
||||
import { mergeSubblockState } from '@/stores/workflows/server-utils'
|
||||
import { validateWorkflowAccess } from '../../middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '../../utils'
|
||||
|
||||
const logger = createLogger('WorkflowExecuteAPI')
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ import type { NextRequest } from 'next/server'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { LoggingSession } from '@/lib/logs/execution/logging-session'
|
||||
import { buildTraceSpans } from '@/lib/logs/execution/trace-spans/trace-spans'
|
||||
import { validateWorkflowAccess } from '../../middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '../../utils'
|
||||
import { validateWorkflowAccess } from '@/app/api/workflows/middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
|
||||
const logger = createLogger('WorkflowLogAPI')
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ import type { NextRequest } from 'next/server'
|
||||
import { env } from '@/lib/env'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { saveWorkflowToNormalizedTables } from '@/lib/workflows/db-helpers'
|
||||
import { validateWorkflowAccess } from '@/app/api/workflows/middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { workflow } from '@/db/schema'
|
||||
import type { WorkflowState } from '@/stores/workflows/workflow/types'
|
||||
import { validateWorkflowAccess } from '../../middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '../../utils'
|
||||
|
||||
const logger = createLogger('RevertToDeployedAPI')
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ describe('Workflow By ID API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -75,7 +75,7 @@ describe('Workflow By ID API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/nonexistent')
|
||||
const params = Promise.resolve({ id: 'nonexistent' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
@@ -113,7 +113,7 @@ describe('Workflow By ID API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -156,7 +156,7 @@ describe('Workflow By ID API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -199,7 +199,7 @@ describe('Workflow By ID API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(403)
|
||||
@@ -249,7 +249,7 @@ describe('Workflow By ID API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -298,7 +298,7 @@ describe('Workflow By ID API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -349,7 +349,7 @@ describe('Workflow By ID API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -393,7 +393,7 @@ describe('Workflow By ID API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { DELETE } = await import('./route')
|
||||
const { DELETE } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await DELETE(req, { params })
|
||||
|
||||
expect(response.status).toBe(403)
|
||||
@@ -444,7 +444,7 @@ describe('Workflow By ID API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -498,7 +498,7 @@ describe('Workflow By ID API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -545,7 +545,7 @@ describe('Workflow By ID API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
expect(response.status).toBe(403)
|
||||
@@ -588,7 +588,7 @@ describe('Workflow By ID API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { PUT } = await import('./route')
|
||||
const { PUT } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await PUT(req, { params })
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
@@ -620,7 +620,7 @@ describe('Workflow By ID API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
|
||||
@@ -2,10 +2,10 @@ import { eq } from 'drizzle-orm'
|
||||
import type { NextRequest } from 'next/server'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { hasWorkflowChanged } from '@/lib/workflows/utils'
|
||||
import { validateWorkflowAccess } from '@/app/api/workflows/middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
import { db } from '@/db'
|
||||
import { workflowBlocks, workflowEdges, workflowSubflows } from '@/db/schema'
|
||||
import { validateWorkflowAccess } from '../../middleware'
|
||||
import { createErrorResponse, createSuccessResponse } from '../../utils'
|
||||
|
||||
const logger = createLogger('WorkflowStatusAPI')
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('Workflow Variables API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123/variables')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -54,7 +54,7 @@ describe('Workflow Variables API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/nonexistent/variables')
|
||||
const params = Promise.resolve({ id: 'nonexistent' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
@@ -80,7 +80,7 @@ describe('Workflow Variables API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123/variables')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -110,7 +110,7 @@ describe('Workflow Variables API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123/variables')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -146,7 +146,7 @@ describe('Workflow Variables API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123/variables')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -172,7 +172,7 @@ describe('Workflow Variables API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123/variables')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -196,7 +196,7 @@ describe('Workflow Variables API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123/variables')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -230,7 +230,7 @@ describe('Workflow Variables API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await POST(req, { params })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
@@ -265,7 +265,7 @@ describe('Workflow Variables API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await POST(req, { params })
|
||||
|
||||
expect(response.status).toBe(401)
|
||||
@@ -295,7 +295,7 @@ describe('Workflow Variables API Route', () => {
|
||||
})
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await POST(req, { params })
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
@@ -314,7 +314,7 @@ describe('Workflow Variables API Route', () => {
|
||||
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123/variables')
|
||||
const params = Promise.resolve({ id: 'workflow-123' })
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
|
||||
const response = await GET(req, { params })
|
||||
|
||||
expect(response.status).toBe(500)
|
||||
|
||||
@@ -2,9 +2,9 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { hasWorkspaceAdminAccess } from '@/lib/permissions/utils'
|
||||
import { DELETE } from '@/app/api/workspaces/invitations/[id]/route'
|
||||
import { db } from '@/db'
|
||||
import { workspaceInvitation } from '@/db/schema'
|
||||
import { DELETE } from './route'
|
||||
|
||||
vi.mock('@/lib/auth', () => ({
|
||||
getSession: vi.fn(),
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
it('should return 401 when user is not authenticated', async () => {
|
||||
mockGetSession.mockResolvedValue(null)
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('GET')
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -123,7 +123,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
mockGetSession.mockResolvedValue({ user: { id: 'user-123' } })
|
||||
mockDbResults = [[], []] // No workspaces, no invitations
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('GET')
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -141,7 +141,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
]
|
||||
mockDbResults = [mockWorkspaces, mockInvitations]
|
||||
|
||||
const { GET } = await import('./route')
|
||||
const { GET } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('GET')
|
||||
const response = await GET(req)
|
||||
const data = await response.json()
|
||||
@@ -155,7 +155,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
it('should return 401 when user is not authenticated', async () => {
|
||||
mockGetSession.mockResolvedValue(null)
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', {
|
||||
workspaceId: 'workspace-1',
|
||||
email: 'test@example.com',
|
||||
@@ -170,7 +170,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
it('should return 400 when workspaceId is missing', async () => {
|
||||
mockGetSession.mockResolvedValue({ user: { id: 'user-123' } })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', { email: 'test@example.com' })
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -182,7 +182,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
it('should return 400 when email is missing', async () => {
|
||||
mockGetSession.mockResolvedValue({ user: { id: 'user-123' } })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', { workspaceId: 'workspace-1' })
|
||||
const response = await POST(req)
|
||||
const data = await response.json()
|
||||
@@ -194,7 +194,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
it('should return 400 when permission type is invalid', async () => {
|
||||
mockGetSession.mockResolvedValue({ user: { id: 'user-123' } })
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', {
|
||||
workspaceId: 'workspace-1',
|
||||
email: 'test@example.com',
|
||||
@@ -213,7 +213,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
mockGetSession.mockResolvedValue({ user: { id: 'user-123' } })
|
||||
mockDbResults = [[]] // No admin permissions found
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', {
|
||||
workspaceId: 'workspace-1',
|
||||
email: 'test@example.com',
|
||||
@@ -232,7 +232,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
[], // Workspace not found
|
||||
]
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', {
|
||||
workspaceId: 'workspace-1',
|
||||
email: 'test@example.com',
|
||||
@@ -253,7 +253,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
[{ permissionType: 'read' }], // User already has access
|
||||
]
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', {
|
||||
workspaceId: 'workspace-1',
|
||||
email: 'test@example.com',
|
||||
@@ -277,7 +277,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
[mockInvitation], // Invitation exists
|
||||
]
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', {
|
||||
workspaceId: 'workspace-1',
|
||||
email: 'test@example.com',
|
||||
@@ -303,7 +303,7 @@ describe('Workspace Invitations API Route', () => {
|
||||
[], // No existing invitation
|
||||
]
|
||||
|
||||
const { POST } = await import('./route')
|
||||
const { POST } = await import('@/app/api/workspaces/invitations/route')
|
||||
const req = createMockRequest('POST', {
|
||||
workspaceId: 'workspace-1',
|
||||
email: 'test@example.com',
|
||||
|
||||
@@ -5,17 +5,18 @@ import { v4 as uuidv4 } from 'uuid'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { noop } from '@/lib/utils'
|
||||
import { getFormattedGitHubStars } from '@/app/(landing)/actions/github'
|
||||
import EmailAuth from './components/auth/email/email-auth'
|
||||
import PasswordAuth from './components/auth/password/password-auth'
|
||||
import { ChatErrorState } from './components/error-state/error-state'
|
||||
import { ChatHeader } from './components/header/header'
|
||||
import { ChatInput } from './components/input/input'
|
||||
import { ChatLoadingState } from './components/loading-state/loading-state'
|
||||
import type { ChatMessage } from './components/message/message'
|
||||
import { ChatMessageContainer } from './components/message-container/message-container'
|
||||
import { VoiceInterface } from './components/voice-interface/voice-interface'
|
||||
import { useAudioStreaming } from './hooks/use-audio-streaming'
|
||||
import { useChatStreaming } from './hooks/use-chat-streaming'
|
||||
import {
|
||||
ChatErrorState,
|
||||
ChatHeader,
|
||||
ChatInput,
|
||||
ChatLoadingState,
|
||||
type ChatMessage,
|
||||
ChatMessageContainer,
|
||||
EmailAuth,
|
||||
PasswordAuth,
|
||||
VoiceInterface,
|
||||
} from '@/app/chat/[subdomain]/components'
|
||||
import { useAudioStreaming, useChatStreaming } from '@/app/chat/[subdomain]/hooks'
|
||||
|
||||
const logger = createLogger('ChatClient')
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { ChatHeader } from '../header/header'
|
||||
import { ChatHeader } from '../'
|
||||
|
||||
interface ChatErrorStateProps {
|
||||
error: string
|
||||
|
||||
9
apps/sim/app/chat/[subdomain]/components/index.ts
Normal file
9
apps/sim/app/chat/[subdomain]/components/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export { default as EmailAuth } from './auth/email/email-auth'
|
||||
export { default as PasswordAuth } from './auth/password/password-auth'
|
||||
export { ChatErrorState } from './error-state/error-state'
|
||||
export { ChatHeader } from './header/header'
|
||||
export { ChatInput } from './input/input'
|
||||
export { ChatLoadingState } from './loading-state/loading-state'
|
||||
export type { ChatMessage } from './message/message'
|
||||
export { ChatMessageContainer } from './message-container/message-container'
|
||||
export { VoiceInterface } from './voice-interface/voice-interface'
|
||||
@@ -5,7 +5,7 @@ import { useEffect, useRef, useState } from 'react'
|
||||
import { motion } from 'framer-motion'
|
||||
import { Send, Square } from 'lucide-react'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { VoiceInput } from './voice-input'
|
||||
import { VoiceInput } from '@/app/chat/[subdomain]/components/input/voice-input'
|
||||
|
||||
const PLACEHOLDER_MOBILE = 'Enter a message'
|
||||
const PLACEHOLDER_DESKTOP = 'Enter a message or click the mic to speak'
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
import { memo, type RefObject } from 'react'
|
||||
import { ArrowDown } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { type ChatMessage, ClientChatMessage } from '../message/message'
|
||||
import {
|
||||
type ChatMessage,
|
||||
ClientChatMessage,
|
||||
} from '@/app/chat/[subdomain]/components/message/message'
|
||||
|
||||
interface ChatMessageContainerProps {
|
||||
messages: ChatMessage[]
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Button } from '@/components/ui/button'
|
||||
import { ToolCallCompletion, ToolCallExecution } from '@/components/ui/tool-call'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { parseMessageContent, stripToolCallIndicators } from '@/lib/tool-call-parser'
|
||||
import MarkdownRenderer from './components/markdown-renderer'
|
||||
import MarkdownRenderer from '@/app/chat/[subdomain]/components/message/components/markdown-renderer'
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Mic, MicOff, Phone } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { ParticlesVisualization } from './components/particles'
|
||||
import { ParticlesVisualization } from '@/app/chat/[subdomain]/components/voice-interface/components/particles'
|
||||
|
||||
const logger = createLogger('VoiceInterface')
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user