Files
gold_land_server/test/production-config.test.ts
T

68 lines
1.4 KiB
TypeScript
Raw Normal View History

import 'reflect-metadata'
import assert from 'node:assert/strict'
import { validateEnv } from '../src/config/env.validation'
const VALID_PROD_SECRET = 'a'.repeat(48)
assert.throws(
() =>
validateEnv({
NODE_ENV: 'production',
PORT: 3000,
HOST: '0.0.0.0',
CORS_ORIGIN: 'https://app.example.com',
JWT_SECRET: '',
}),
/JWT_SECRET is required/,
)
assert.throws(
() =>
validateEnv({
NODE_ENV: 'production',
PORT: 3000,
HOST: '0.0.0.0',
CORS_ORIGIN: 'https://app.example.com',
JWT_SECRET: 'gold-land-dev-secret-change-in-production',
}),
/placeholder/,
)
assert.throws(
() =>
validateEnv({
NODE_ENV: 'production',
PORT: 3000,
HOST: '0.0.0.0',
CORS_ORIGIN: 'https://app.example.com',
JWT_SECRET: 'short',
}),
/32 characters/,
)
assert.throws(
() =>
validateEnv({
NODE_ENV: 'production',
PORT: 3000,
HOST: '0.0.0.0',
CORS_ORIGIN: 'https://app.example.com',
JWT_SECRET: VALID_PROD_SECRET,
TRUST_PROXY: 'true',
}),
/TRUST_PROXY_CIDRS is required/,
)
const ok = validateEnv({
NODE_ENV: 'production',
PORT: 3000,
HOST: '0.0.0.0',
CORS_ORIGIN: 'https://app.example.com',
JWT_SECRET: VALID_PROD_SECRET,
TRUST_PROXY: 'true',
TRUST_PROXY_CIDRS: '172.20.0.0/16',
})
assert.equal(ok.NODE_ENV, 'production')
console.log('production-config tests passed')