Files
Draupnir/test/unit/config/unknownPropertiesTest.ts
Gnuxie 4015543f66 Filesystem config improvements (#604)
* Rename read to configRead as it should have always been.

* Got a way to extract non-default values.

Now let's try unknown configuration values.

* Show unknown property paths with a warning.

Now we just need to make this scrap available in commands.

* Remove the old Mjolnir horrible RUNTIME client.

* Make the path that is used to load the config available.

* Warn when `--draupnir-config` isn't used.

* Introduce configMeta so that we can log meta on process.exit later.

* Only show non-default config values when draupnir is exiting.

to reduce noise.

* Get consistent with logging.

So it turns out that mps4bot-sdk is using a different instance
of the bot-sdk module than Draupnir, i think.

Since we used to tell MPS's logger to use the bot-sdk's `LogService`,
but the `setLogger` that was used was obviously inconsistent with
Draupnir's.

Obviously the bot-sdk should be a peer dependency in the bot-sdk
to prevent this happening in future.
2024-10-09 11:38:24 +01:00

42 lines
1.3 KiB
TypeScript

// SPDX-FileCopyrightText: 2024 Gnuxie <Gnuxie@protonmail.com>
//
// SPDX-License-Identifier: AFL-3.0
import expect from "expect";
import {
getNonDefaultConfigProperties,
getUnknownConfigPropertyPaths,
} from "../../../src/config";
import { IConfig } from "../../../src/config";
describe("Test unknown properties detection", () => {
it("Should detect when there are typos in the config", function () {
const config = {
pantalaimon: {
use: true,
passweird: "my password hehe",
},
};
const unknownProperties = getUnknownConfigPropertyPaths(config);
expect(unknownProperties.length).toBe(1);
expect(unknownProperties[0]).toBe("/pantalaimon/passweird");
});
});
describe("Test non-default values detection", () => {
it("Should detect when there are non-default values in the config", function () {
const config = {
pantalaimon: {
use: true,
password: "my password hehe",
},
};
const differentProperties = getNonDefaultConfigProperties(
config as IConfig
) as unknown as IConfig;
expect(Object.entries(differentProperties).length).toBe(1);
expect(differentProperties.pantalaimon.password).toBe("REDACTED");
expect(differentProperties.pantalaimon.use).toBe(true);
});
});