taler-typescript-core

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

commit 02645c38b2eb81bbf43013c377d44a09717f4279
parent c2b25ddb63ba2f8ea55da868b611c036d9ecba9d
Author: Florian Dold <dold@taler.net>
Date:   Mon, 20 Jul 2026 20:43:16 +0200

util: test URL canonicalization and error stringification

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

diff --git a/packages/taler-util/src/helpers.test.ts b/packages/taler-util/src/helpers.test.ts @@ -43,3 +43,29 @@ test("URL canonicalization", (t) => { helpers.canonicalizeBaseUrl("http://alice.example.com/exchange?foo=bar"), ); }); + +test("canonicalizeBaseUrl adds a scheme when there is none", (t) => { + // The guard tested for the letters "http" rather than for a scheme, so any + // host starting with those letters was passed to new URL() unprefixed. + assert.strictEqual( + helpers.canonicalizeBaseUrl("exchange.example.com"), + "https://exchange.example.com/", + ); + assert.strictEqual(helpers.canonicalizeBaseUrl("httpbin.org"), "https://httpbin.org/"); + assert.strictEqual( + helpers.canonicalizeBaseUrl("http-foo.example.com"), + "https://http-foo.example.com/", + ); + assert.strictEqual( + helpers.canonicalizeBaseUrl("https://exchange.example.com/"), + "https://exchange.example.com/", + ); +}); + +test("stringifyError does not throw", (t) => { + // This runs inside error reporting, so a throw here turns a diagnostic into + // a secondary crash. + assert.doesNotThrow(() => helpers.stringifyError(Object.create(null))); + assert.doesNotThrow(() => helpers.stringifyError(undefined)); + assert.doesNotThrow(() => helpers.stringifyError(new Error("boom"))); +});