feat: add Condo owner desk frontend and backend
This commit is contained in:
61
backend/tests/config.test.ts
Normal file
61
backend/tests/config.test.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import {
|
||||
ConfigurationError,
|
||||
loadConfig
|
||||
} from "../src/config.js";
|
||||
|
||||
test("configuration accepts only booking_test and never echoes secrets", () => {
|
||||
const secret = "sensitive-test-value";
|
||||
const config = loadConfig({
|
||||
DB_HOST: "database.example",
|
||||
DB_PORT: "5432",
|
||||
DB_USER: "app_user",
|
||||
DB_PASSWORD: secret,
|
||||
DB_NAME: "booking_test",
|
||||
DB_SSL: "true"
|
||||
});
|
||||
|
||||
assert.equal(config.database.name, "booking_test");
|
||||
assert.equal(config.database.ssl, true);
|
||||
assert.equal(config.apiHost, "127.0.0.1");
|
||||
assert.deepEqual(config.corsOrigins, [
|
||||
"http://127.0.0.1:4173",
|
||||
"http://localhost:4173"
|
||||
]);
|
||||
assert.deepEqual(config.authentication, {
|
||||
username: "wyndhamcondon",
|
||||
password: "wyndhamcondon",
|
||||
sessionTtlMs: 12 * 60 * 60 * 1_000,
|
||||
cookieSecure: false
|
||||
});
|
||||
|
||||
const productionConfig = loadConfig({
|
||||
NODE_ENV: "production",
|
||||
AUTH_USERNAME: "operator",
|
||||
AUTH_PASSWORD: "production-secret",
|
||||
AUTH_SESSION_TTL_HOURS: "24",
|
||||
DB_HOST: "database.example",
|
||||
DB_USER: "app_user",
|
||||
DB_PASSWORD: secret,
|
||||
DB_NAME: "booking_test"
|
||||
});
|
||||
assert.equal(productionConfig.authentication.username, "operator");
|
||||
assert.equal(productionConfig.authentication.sessionTtlMs, 24 * 60 * 60 * 1_000);
|
||||
assert.equal(productionConfig.authentication.cookieSecure, true);
|
||||
|
||||
assert.throws(
|
||||
() => loadConfig({
|
||||
DB_HOST: "database.example",
|
||||
DB_USER: "app_user",
|
||||
DB_PASSWORD: secret,
|
||||
DB_NAME: "another_database"
|
||||
}),
|
||||
error => {
|
||||
assert.ok(error instanceof ConfigurationError);
|
||||
assert.equal(error.message.includes("DB_NAME"), true);
|
||||
assert.equal(error.message.includes(secret), false);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user