From 5c1ced59006798371f74d5e7039967299563128b Mon Sep 17 00:00:00 2001 From: Max Kowalski Date: Fri, 27 Jun 2025 19:00:22 +0200 Subject: [PATCH] feat: add rawTranscriptContent field to SessionImport model feat: enhance server initialization with environment validation and import processing scheduler test: add Jest setup for unit tests and mock console methods test: implement unit tests for environment management and validation test: create unit tests for transcript fetcher functionality --- .env.example | 4 +- .env.local.example | 5 +- app/dashboard/company/page.tsx | 4 +- app/dashboard/overview/page.tsx | 2 +- app/dashboard/page.tsx | 4 +- app/dashboard/settings.tsx | 2 +- app/dashboard/users.tsx | 6 +- app/dashboard/users/page.tsx | 10 +- app/register/page.tsx | 4 +- jest.config.js | 22 + lib/env.ts | 111 ++ lib/importProcessor.ts | 225 +++ lib/schedulerConfig.ts | 62 +- lib/transcriptFetcher.ts | 151 ++ package.json | 7 + pages/api/admin/refresh-sessions.ts | 13 +- pages/api/admin/trigger-processing.ts | 2 +- pages/api/dashboard/settings.ts | 2 +- pages/api/dashboard/users.ts | 2 +- pnpm-lock.yaml | 2497 ++++++++++++++++++++++++- prisma/schema.prisma | 3 + server.ts | 15 +- tests/setup.ts | 25 + tests/unit/env.test.ts | 174 ++ tests/unit/transcriptFetcher.test.ts | 222 +++ 25 files changed, 3492 insertions(+), 82 deletions(-) create mode 100644 jest.config.js create mode 100644 lib/env.ts create mode 100644 lib/importProcessor.ts create mode 100644 lib/transcriptFetcher.ts create mode 100644 tests/setup.ts create mode 100644 tests/unit/env.test.ts create mode 100644 tests/unit/transcriptFetcher.test.ts diff --git a/.env.example b/.env.example index 3b99ece..39f3891 100644 --- a/.env.example +++ b/.env.example @@ -15,6 +15,8 @@ OPENAI_API_KEY=your_openai_api_key_here # Scheduler Configuration SCHEDULER_ENABLED=false # Enable/disable all schedulers (false for dev, true for production) CSV_IMPORT_INTERVAL=*/15 * * * * # Cron expression for CSV imports (every 15 minutes) -SESSION_PROCESSING_INTERVAL=0 * * * * # Cron expression for session processing (every hour) +IMPORT_PROCESSING_INTERVAL=*/5 * * * * # Cron expression for processing imports to sessions (every 5 minutes) +IMPORT_PROCESSING_BATCH_SIZE=50 # Number of imports to process at once +SESSION_PROCESSING_INTERVAL=0 * * * * # Cron expression for AI session processing (every hour) SESSION_PROCESSING_BATCH_SIZE=0 # 0 = unlimited sessions, >0 = specific limit SESSION_PROCESSING_CONCURRENCY=5 # How many sessions to process in parallel diff --git a/.env.local.example b/.env.local.example index 30fc75c..bc293c2 100644 --- a/.env.local.example +++ b/.env.local.example @@ -11,12 +11,15 @@ OPENAI_API_KEY=your_openai_api_key_here # Scheduler Configuration SCHEDULER_ENABLED=true # Set to false to disable all schedulers during development CSV_IMPORT_INTERVAL=*/15 * * * * # Every 15 minutes (cron format) -SESSION_PROCESSING_INTERVAL=0 * * * * # Every hour (cron format) +IMPORT_PROCESSING_INTERVAL=*/5 * * * * # Every 5 minutes (cron format) - converts imports to sessions +IMPORT_PROCESSING_BATCH_SIZE=50 # Number of imports to process at once +SESSION_PROCESSING_INTERVAL=0 * * * * # Every hour (cron format) - AI processing SESSION_PROCESSING_BATCH_SIZE=0 # 0 = process all sessions, >0 = limit number SESSION_PROCESSING_CONCURRENCY=5 # Number of sessions to process in parallel # Example configurations: # - For development (no schedulers): SCHEDULER_ENABLED=false # - For testing (every 5 minutes): CSV_IMPORT_INTERVAL=*/5 * * * * +# - For faster import processing: IMPORT_PROCESSING_INTERVAL=*/2 * * * * # - For limited processing: SESSION_PROCESSING_BATCH_SIZE=10 # - For high concurrency: SESSION_PROCESSING_CONCURRENCY=10 diff --git a/app/dashboard/company/page.tsx b/app/dashboard/company/page.tsx index fca955e..a119edd 100644 --- a/app/dashboard/company/page.tsx +++ b/app/dashboard/company/page.tsx @@ -77,8 +77,8 @@ export default function CompanySettingsPage() { return
Loading settings...
; } - // Check for admin access - if (session?.user?.role !== "admin") { + // Check for ADMIN access + if (session?.user?.role !== "ADMIN") { return (

Access Denied

diff --git a/app/dashboard/overview/page.tsx b/app/dashboard/overview/page.tsx index cc1f38d..143fab6 100644 --- a/app/dashboard/overview/page.tsx +++ b/app/dashboard/overview/page.tsx @@ -31,7 +31,7 @@ function DashboardContent() { const [selectedStartDate, setSelectedStartDate] = useState(""); const [selectedEndDate, setSelectedEndDate] = useState(""); - const isAuditor = session?.user?.role === "auditor"; + const isAuditor = session?.user?.role === "AUDITOR"; // Function to fetch metrics with optional date range const fetchMetrics = useCallback(async (startDate?: string, endDate?: string) => { diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index 708f9b4..71504ef 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -62,7 +62,7 @@ const DashboardPage: FC = () => {
- {session?.user?.role === "admin" && ( + {session?.user?.role === "ADMIN" && (

Company Settings @@ -79,7 +79,7 @@ const DashboardPage: FC = () => {

)} - {session?.user?.role === "admin" && ( + {session?.user?.role === "ADMIN" && (

User Management diff --git a/app/dashboard/settings.tsx b/app/dashboard/settings.tsx index 472af6b..b15907b 100644 --- a/app/dashboard/settings.tsx +++ b/app/dashboard/settings.tsx @@ -37,7 +37,7 @@ export default function DashboardSettings({ else setMessage("Failed."); } - if (session.user.role !== "admin") return null; + if (session.user.role !== "ADMIN") return null; return (
diff --git a/app/dashboard/users.tsx b/app/dashboard/users.tsx index bea1789..3e1f502 100644 --- a/app/dashboard/users.tsx +++ b/app/dashboard/users.tsx @@ -34,7 +34,7 @@ export default function UserManagement({ session }: UserManagementProps) { else setMsg("Failed."); } - if (session.user.role !== "admin") return null; + if (session.user.role !== "ADMIN") return null; return (
@@ -52,8 +52,8 @@ export default function UserManagement({ session }: UserManagementProps) { onChange={(e) => setRole(e.target.value)} > - - + +
@@ -183,9 +183,9 @@ export default function UserManagementPage() { (""); const [password, setPassword] = useState(""); const [csvUrl, setCsvUrl] = useState(""); - const [role, setRole] = useState("admin"); // Default to admin for company registration + const [role, setRole] = useState("ADMIN"); // Default to ADMIN for company registration const [error, setError] = useState(""); const router = useRouter(); @@ -66,7 +66,7 @@ export default function RegisterPage() { > - +