This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
COT_AUTH_TIMEOUT_MS,
|
||||
LIVE_SESSION_TTL_MS,
|
||||
@@ -15,16 +15,6 @@ import {
|
||||
} 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)
|
||||
@@ -40,34 +30,11 @@ describe('constants', () => {
|
||||
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)
|
||||
expect(invalidValue || 15000).toBe(15000)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user