1
7import { describe, expect, it } from "vitest";
8
9import { loadConfig } from "../src/config.js";
10
11const BASE = { JWT_SECRET: "test-secret", INTERNAL_SERVICE_TOKEN: "tok" };
12
13describe("realtime loadConfig — port resolution", () => {
14 it("defaults to 4001 when neither REALTIME_PORT nor PORT is set", () => {
15 const cfg = loadConfig({ ...BASE });
16 expect(cfg.port).toBe(4001);
17 expect(cfg.healthPort).toBe(4002);
18 });
19
20 it("reads REALTIME_PORT and does NOT take the API's PORT (dev-stack collision)", () => {
21 const cfg = loadConfig({ ...BASE, PORT: "4000", REALTIME_PORT: "4001" });
22 expect(cfg.port).toBe(4001);
23 expect(cfg.healthPort).toBe(4002);
24 });
25
26 it("honors an explicit REALTIME_PORT override", () => {
27 const cfg = loadConfig({ ...BASE, PORT: "4000", REALTIME_PORT: "5050" });
28 expect(cfg.port).toBe(5050);
29 });
30
31 it("falls back to PORT only when REALTIME_PORT is unset (standalone run)", () => {
32 const cfg = loadConfig({ ...BASE, PORT: "6000" });
33 expect(cfg.port).toBe(6000);
34 });
35
36 it("throws without JWT_SECRET", () => {
37 expect(() => loadConfig({ ...BASE, JWT_SECRET: "" })).toThrow(/JWT_SECRET/);
38 expect(() => loadConfig({ ...BASE, JWT_SECRET: " " })).toThrow(/JWT_SECRET/);
39 expect(() => loadConfig({} as NodeJS.ProcessEnv)).toThrow(/JWT_SECRET/);
40 });
41});
42