267e80e2ec
- Refactor server initialization to separate concerns and improve error handling. - Implement centralized environment validation using Zod. - Introduce database, Redis, and queue lifecycle management. - Add health check endpoints for liveness and readiness. - Enhance error handling middleware for better response structure. - Implement rate limiting for API endpoints. - Add request ID middleware for traceability. - Create Sequelize CLI configuration and baseline migration for schema management. - Establish CI workflow with Gitea for testing and syntax checks. - Document foundational changes and migration strategy in PHASE_0_FOUNDATION_STABILIZATION.md. - Add Docker Compose configuration for local development and testing. - Implement unit and integration tests for critical functionality.
22 lines
927 B
JavaScript
22 lines
927 B
JavaScript
const { validateEnvironment, getOptionalFeatureStatus } = require("../../app/config/env.config");
|
|
|
|
const valid = {
|
|
NODE_ENV: "test", PORT: "3070", DB_HOST: "localhost", DB_PORT: "3306", DB_NAME: "test",
|
|
DB_USER: "test", DB_PASSWORD: "", JWT_SECRET: "a".repeat(32), REFRESH_TOKEN_SECRET: "b".repeat(32),
|
|
REDIS_HOST: "localhost", REDIS_PORT: "6379", FRONTEND_URL: "http://localhost:3000",
|
|
};
|
|
|
|
describe("environment validation", () => {
|
|
test("accepts the critical API configuration", () => {
|
|
expect(validateEnvironment(valid)).toMatchObject({ PORT: 3070, DB_NAME: "test", RUN_CRON: false });
|
|
});
|
|
|
|
test("fails safely and names invalid variables without values", () => {
|
|
expect(() => validateEnvironment({ ...valid, JWT_SECRET: "short" })).toThrow("JWT_SECRET");
|
|
});
|
|
|
|
test("keeps mail and S3 optional", () => {
|
|
expect(getOptionalFeatureStatus(valid)).toMatchObject({ mail: false, s3: false });
|
|
});
|
|
});
|