refactor testing
Some checks failed
ci/woodpecker/pr/pr Pipeline failed

This commit is contained in:
Madison Grubb
2026-02-17 11:05:57 -05:00
parent b0e8dd7ad9
commit 1a566e2d80
57 changed files with 1127 additions and 1760 deletions

View File

@@ -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)
})
})