taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 3dafaa168c235cb4595e7b253860d334ef087b95
parent 5bbe5b792e28954a76dae0aa38f16bf9da948e03
Author: Florian Dold <dold@taler.net>
Date:   Tue, 21 Jul 2026 20:03:44 +0200

util: test config source lookup, number range and section names

Diffstat:
Mpackages/taler-util/src/talerconfig.test.ts | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/packages/taler-util/src/talerconfig.test.ts b/packages/taler-util/src/talerconfig.test.ts @@ -394,3 +394,32 @@ test("write-back preserves the spelling of section and option names", (t) => { "[exchange]\nbase_url = https://real/\n\n", ); }); + +test("an unknown config source name is rejected", (t) => { + // "in" walks the prototype chain, so names inherited from Object.prototype + // reached the lookup instead of the intended error. + assert.throws( + () => Configuration.load(undefined, "toString"), + /invalid config source/, + ); + assert.throws( + () => Configuration.load(undefined, "constructor"), + /invalid config source/, + ); +}); + +test("getNumber rejects values it cannot represent", (t) => { + // The C parses with a range-checked strtoll; silently returning a rounded + // value is worse than refusing it. + const config = new Configuration(); + config.setString("s", "ok", "42"); + config.setString("s", "huge", "9007199254740993"); + assert.strictEqual(config.getNumber("s", "ok").required(), 42); + assert.throws(() => config.getNumber("s", "huge").required()); +}); + +test("getSectionNames reports the names as written", (t) => { + const config = new Configuration(); + config.loadFromString("[exchange]\nBASE_URL = x\n"); + assert.deepStrictEqual(config.getSectionNames(), ["exchange"]); +});