Files
TeleUploader/test/env.test.ts
T

70 lines
2.8 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from 'bun:test';
import { config } from '../src/env';
2026-05-18 06:58:55 +07:00
describe('Environment Variables Validation', () => {
it('config should have all required fields', () => {
expect(config).toHaveProperty('botTokens');
expect(config).toHaveProperty('storageChatId');
expect(config).toHaveProperty('baseUrl');
expect(config).toHaveProperty('databaseUrl');
expect(config).toHaveProperty('port');
expect(config).toHaveProperty('nodeEnv');
expect(config).toHaveProperty('logLevel');
expect(config).toHaveProperty('rateLimitWindowMs');
expect(config).toHaveProperty('rateLimitMaxRequests');
expect(config).toHaveProperty('adminApiToken');
expect(config).toHaveProperty('sessionCookieName');
expect(config).toHaveProperty('sessionMaxAgeMs');
2026-05-18 06:58:55 +07:00
});
it('config.botTokens should return array from BOT_TOKENS env', () => {
expect(Array.isArray(config.botTokens)).toBe(true);
expect(config.botTokens.length).toBeGreaterThanOrEqual(3);
2026-05-18 06:58:55 +07:00
});
it('config.storageChatId should be parsed as integer from STORAGE_CHANNEL_ID', () => {
expect(typeof config.storageChatId).toBe('number');
expect(config.storageChatId).toBe(parseInt(process.env.STORAGE_CHANNEL_ID || '0', 10));
2026-05-18 06:58:55 +07:00
});
it('config.port should default to 3000 when not specified', () => {
expect(typeof config.port).toBe('number');
2026-05-18 06:58:55 +07:00
});
it("nodeEnv should be 'test' or 'development'", () => {
expect(['test', 'development']).toContain(config.nodeEnv);
2026-05-18 06:58:55 +07:00
});
it("logLevel should default to 'info'", () => {
expect(config.logLevel).toBe('info');
2026-05-18 06:58:55 +07:00
});
it('rateLimitWindowMs should default to 60000 when not specified', () => {
2026-05-18 06:58:55 +07:00
expect(config.rateLimitWindowMs).toBe(60000);
});
it('rateLimitMaxRequests should default to 150 when not specified', () => {
expect(config.rateLimitMaxRequests).toBe(150);
2026-05-18 06:58:55 +07:00
});
it('auth config should be disabled by default with a 24 hour session', () => {
expect(config.adminApiToken).toBe(process.env.ADMIN_API_TOKEN || '');
expect(config.sessionCookieName).toBe(process.env.SESSION_COOKIE_NAME || 'tu_session');
expect(config.sessionMaxAgeMs).toBe(86400 * 1000);
});
it('botTokens should be populated in test environment', () => {
expect(Array.isArray(config.botTokens)).toBe(true);
// With mock tokens from setup-env.ts there should be at least 3 tokens
expect(config.botTokens.length).toBeGreaterThanOrEqual(3);
});
it('S3 validation should not throw — env already loaded without error at import time', () => {
// config was imported at the top of this file; if S3 validation had failed,
// this test file would never have loaded. The fact that we're here means
// validation passed.
expect(config.s3AccessKey).toBeDefined();
expect(config.s3SecretKey).toBeDefined();
});
2026-05-18 06:58:55 +07:00
});