18 lines
728 B
TypeScript
18 lines
728 B
TypeScript
|
|
import assert from "node:assert/strict";
|
||
|
|
import { test } from "node:test";
|
||
|
|
|
||
|
|
import { readServerEnvironment } from "./env-schema";
|
||
|
|
|
||
|
|
test("el puerto usa un valor local por defecto y acepta los límites válidos", () => {
|
||
|
|
assert.equal(readServerEnvironment({}).PORT, 3001);
|
||
|
|
assert.equal(readServerEnvironment({ PORT: "1" }).PORT, 1);
|
||
|
|
assert.equal(readServerEnvironment({ PORT: "65535" }).PORT, 65535);
|
||
|
|
});
|
||
|
|
test("el arranque rechaza puertos inválidos sin revelar el valor recibido", () => {
|
||
|
|
for (const port of ["", "0", "-1", "65536", "1.5", "secret-value"]) {
|
||
|
|
assert.throws(() => readServerEnvironment({ PORT: port }), {
|
||
|
|
message: "Invalid server configuration: PORT must be between 1 and 65535",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|