Skip to content

Commit 6cb3e24

Browse files
authored
replace template_spec test with config_variables test (#4034)
After introducing new config loading this PR replaces the obsolete template test with a config test.
1 parent 1dc3032 commit 6cb3e24

File tree

8 files changed

+56
-33
lines changed

8 files changed

+56
-33
lines changed

cspell.config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
"Reis",
249249
"rejas",
250250
"relativehumidity",
251+
"resultstring",
251252
"Resig",
252253
"roboto",
253254
"rohitdharavath",
@@ -288,6 +289,7 @@
288289
"TESTMODE",
289290
"testpass",
290291
"testuser",
292+
"teststring",
291293
"thomasrockhu",
292294
"thumbslider",
293295
"timeformat",

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import stylistic from "@stylistic/eslint-plugin";
99
import vitest from "@vitest/eslint-plugin";
1010

1111
export default defineConfig([
12-
globalIgnores(["config/**", "modules/**/*", "js/positions.js", "tests/configs/port_variable.js"]),
12+
globalIgnores(["config/**", "modules/**/*", "js/positions.js", "tests/configs/config_variables.js"]),
1313
{
1414
files: ["**/*.js"],
1515
languageOptions: {

tests/configs/config_variables.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
MM_LANGUAGE=de
2+
MM_TIME_FORMAT=12
3+
MM_LOG_INFO=INFO
4+
MM_LOG_ERROR=ERROR
5+
SECRET_IP1="127.0.0.1"
6+
SECRET_IP2="::ffff:127.0.0.1"
7+
SECRET_IP3=1

tests/configs/config_variables.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let config = require(`${process.cwd()}/tests/configs/default.js`).configFactory({
2+
language: "${MM_LANGUAGE}",
3+
logLevel: ["${MM_LOG_ERROR}", "LOG", "WARN", "${MM_LOG_INFO}"],
4+
timeFormat: ${MM_TIME_FORMAT},
5+
hideConfigSecrets: true,
6+
ipWhitelist: ["${SECRET_IP2}", "::${SECRET_IP3}", "${SECRET_IP1}"]
7+
});
8+
9+
/*************** DO NOT EDIT THE LINE BELOW ***************/
10+
if (typeof module !== "undefined") {
11+
module.exports = config;
12+
}

tests/configs/port_variable.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/configs/port_variable.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/e2e/config_variables_spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const helpers = require("./helpers/global-setup");
2+
3+
describe("config with variables and secrets", () => {
4+
beforeAll(async () => {
5+
await helpers.startApplication("tests/configs/config_variables.js");
6+
});
7+
8+
afterAll(async () => {
9+
await helpers.stopApplication();
10+
});
11+
12+
it("config.language should be \"de\"", async () => {
13+
expect(config.language).toBe("de");
14+
});
15+
16+
it("config.loglevel should be [\"ERROR\", \"LOG\", \"WARN\", \"INFO\"]", async () => {
17+
expect(config.logLevel).toStrictEqual(["ERROR", "LOG", "WARN", "INFO"]);
18+
});
19+
20+
it("config.ipWhitelist should be [\"::ffff:127.0.0.1\", \"::1\", \"127.0.0.1\"]", async () => {
21+
expect(config.ipWhitelist).toStrictEqual(["::ffff:127.0.0.1", "::1", "127.0.0.1"]);
22+
});
23+
24+
it("config.timeFormat should be 12", async () => {
25+
expect(config.timeFormat).toBe(12); // default is 24
26+
});
27+
28+
it("/config endpoint should show redacted secrets", async () => {
29+
const res = await fetch(`http://localhost:${config.port}/config`);
30+
expect(res.status).toBe(200);
31+
const cfg = await res.json();
32+
expect(cfg.ipWhitelist).toStrictEqual(["**SECRET_IP2**", "::**SECRET_IP3**", "**SECRET_IP1**"]);
33+
});
34+
});

tests/e2e/template_spec.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)