devperf/backend/tests/unit/config.test.ts
zyc 44464dd334 feat: DevPerf Dashboard 研发人效看板 v1.0
- 后端:Bun + Hono + Drizzle ORM + SQLite
- 前端:Vue 3 + Naive UI + ECharts
- 项目管理:创建项目 + 绑定 Git 仓库
- OKR 系统:目标/关键结果 CRUD + 进度追踪
- Git 同步:Gitea API 自动同步 commit/PR + 作者关联
- 数据看板:项目 OKR 进度 + KR 状态分布 + 代码活动
- 权限体系:admin/manager/developer/viewer 四级
- Docker 部署:docker-compose + nginx

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 17:57:14 +08:00

42 lines
1.4 KiB
TypeScript

/**
* Unit tests for backend configuration module.
* Tests environment variable validation using Zod schema.
*/
import { describe, it, expect } from 'bun:test';
describe('Config Module', () => {
it('should export config object with expected keys', async () => {
// We set JWT_SECRET env var to ensure validation passes
process.env.JWT_SECRET = 'test-secret-for-unit-tests-at-least-16-chars';
// Dynamic import to get fresh module
const { config } = await import('../../src/config');
expect(config).toBeDefined();
expect(typeof config.PORT).toBe('number');
expect(typeof config.JWT_SECRET).toBe('string');
expect(config.JWT_SECRET.length).toBeGreaterThanOrEqual(16);
expect(typeof config.DATABASE_PATH).toBe('string');
expect(typeof config.PLANE_BASE_URL).toBe('string');
expect(typeof config.GITEA_BASE_URL).toBe('string');
});
it('should have correct default PORT', async () => {
process.env.JWT_SECRET = 'test-secret-for-unit-tests-at-least-16-chars';
const { config } = await import('../../src/config');
// Default PORT from schema is 3200
expect(config.PORT).toBe(3200);
});
it('should have valid default URLs', async () => {
process.env.JWT_SECRET = 'test-secret-for-unit-tests-at-least-16-chars';
const { config } = await import('../../src/config');
expect(config.PLANE_BASE_URL).toMatch(/^https?:\/\//);
expect(config.GITEA_BASE_URL).toMatch(/^https?:\/\//);
});
});