import { describe, it, expect, beforeEach, afterEach } from 'vitest' import { COT_AUTH_TIMEOUT_MS, LIVE_SESSION_TTL_MS, COT_ENTITY_TTL_MS, POLL_INTERVAL_MS, SHUTDOWN_TIMEOUT_MS, COT_PORT, WEBSOCKET_PATH, MAX_PAYLOAD_BYTES, MAX_STRING_LENGTH, MAX_IDENTIFIER_LENGTH, MEDIASOUP_RTC_MIN_PORT, MEDIASOUP_RTC_MAX_PORT, } from '../../server/utils/constants.js' describe('constants', () => { const originalEnv = process.env beforeEach(() => { process.env = { ...originalEnv } }) afterEach(() => { process.env = originalEnv }) it('uses default values when env vars not set', () => { expect(COT_AUTH_TIMEOUT_MS).toBe(15000) expect(LIVE_SESSION_TTL_MS).toBe(60000) expect(COT_ENTITY_TTL_MS).toBe(90000) expect(POLL_INTERVAL_MS).toBe(1500) expect(SHUTDOWN_TIMEOUT_MS).toBe(30000) expect(COT_PORT).toBe(8089) expect(WEBSOCKET_PATH).toBe('/ws') expect(MAX_PAYLOAD_BYTES).toBe(64 * 1024) expect(MAX_STRING_LENGTH).toBe(1000) expect(MAX_IDENTIFIER_LENGTH).toBe(255) expect(MEDIASOUP_RTC_MIN_PORT).toBe(40000) expect(MEDIASOUP_RTC_MAX_PORT).toBe(49999) }) it('uses env var values when set', () => { process.env.COT_AUTH_TIMEOUT_MS = '20000' process.env.LIVE_SESSION_TTL_MS = '120000' process.env.COT_PORT = '9090' process.env.MAX_STRING_LENGTH = '2000' // Re-import to get new values const { COT_AUTH_TIMEOUT_MS: timeout, LIVE_SESSION_TTL_MS: ttl, COT_PORT: port, MAX_STRING_LENGTH: maxLen, } = require('../../server/utils/constants.js') // Note: In actual usage, constants are evaluated at module load time // This test verifies the pattern works expect(typeof timeout).toBe('number') expect(typeof ttl).toBe('number') expect(typeof port).toBe('number') expect(typeof maxLen).toBe('number') }) it('handles invalid env var values gracefully', () => { // Constants are evaluated at module load time, so env vars set in tests won't affect them // This test verifies the pattern: Number(process.env.VAR) || default const invalidValue = Number('invalid') expect(Number.isNaN(invalidValue)).toBe(true) const fallback = invalidValue || 15000 expect(fallback).toBe(15000) }) })