38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { AppConfig } from "../src/config/AppConfig";
|
|
|
|
describe("AppConfig", () => {
|
|
it("loads required fields with defaults", () => {
|
|
const config = AppConfig.fromEnv({
|
|
ACI_EMAIL: "grower@example.com",
|
|
ACI_PASSWORD: "super-secret"
|
|
});
|
|
|
|
expect(config.aciHost).toBe("http://www.acinfinityserver.com");
|
|
expect(config.pollIntervalSeconds).toBe(30);
|
|
expect(config.listenPort).toBe(9108);
|
|
expect(config.requestTimeoutMs).toBe(10000);
|
|
expect(config.logLevel).toBe("info");
|
|
});
|
|
|
|
it("throws when required values are missing", () => {
|
|
expect(() => AppConfig.fromEnv({})).toThrow("ACI_EMAIL is required");
|
|
expect(() =>
|
|
AppConfig.fromEnv({
|
|
ACI_EMAIL: "x",
|
|
ACI_PASSWORD: "",
|
|
POLL_INTERVAL_SECONDS: "30"
|
|
})
|
|
).toThrow("ACI_PASSWORD is required");
|
|
});
|
|
|
|
it("validates numeric ranges", () => {
|
|
expect(() =>
|
|
AppConfig.fromEnv({
|
|
ACI_EMAIL: "x",
|
|
ACI_PASSWORD: "y",
|
|
POLL_INTERVAL_SECONDS: "4"
|
|
})
|
|
).toThrow("POLL_INTERVAL_SECONDS must be between 5 and 600");
|
|
});
|
|
});
|