taler-typescript-core

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

commit 1c55dd0696445b26d3fb5908284a576de5c37390
parent 4a9cb7196f9bb85bc8e2b3e46f3db57ed5b103db
Author: Florian Dold <dold@taler.net>
Date:   Wed, 22 Jul 2026 00:29:14 +0200

wallet: test the paivana template amount override

Check that a non-editable amount from the URI replaces the amount of the
simple choices in the same currency, and leaves choices in another
currency or with inputs untouched.

Diffstat:
Apackages/taler-wallet-core/src/pay-template.test.ts | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 86 insertions(+), 0 deletions(-)

diff --git a/packages/taler-wallet-core/src/pay-template.test.ts b/packages/taler-wallet-core/src/pay-template.test.ts @@ -0,0 +1,86 @@ +/* + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import { + AmountString, + HostPortPath, + TalerPayTemplateUri, + TalerUriAction, + TemplateContractDetails, + TemplateContractDetailsDefaults, + TemplateType, +} from "@gnu-taler/taler-util"; +import assert from "node:assert"; +import { test } from "node:test"; +import { applyTemplateUriOverrides } from "./pay-template.js"; + +function paivanaUri(amount: AmountString): TalerPayTemplateUri { + return { + type: TalerUriAction.PayTemplate, + merchantBaseUrl: "https://merchant.example.com/" as HostPortPath, + templateId: "tmpl", + editableAmount: false, + amount, + }; +} + +test("a fixed paivana amount overrides same-currency simple choices", (t) => { + const templateContract: TemplateContractDetails = { + template_type: TemplateType.PAIVANA, + choices: [ + { amount: "KUDOS:5" as AmountString }, + { amount: "KUDOS:20" as AmountString }, + ], + }; + const editableDefaults: TemplateContractDetailsDefaults = {}; + + applyTemplateUriOverrides( + paivanaUri("KUDOS:7" as AmountString), + templateContract, + editableDefaults, + ); + + assert.strictEqual(templateContract.template_type, TemplateType.PAIVANA); + assert.deepStrictEqual( + (templateContract as any).choices.map((c: any) => c.amount), + ["KUDOS:7", "KUDOS:7"], + ); +}); + +test("a fixed paivana amount leaves other currencies and complex choices alone", (t) => { + const templateContract: TemplateContractDetails = { + template_type: TemplateType.PAIVANA, + choices: [ + { amount: "EUR:5" as AmountString }, + { + amount: "KUDOS:5" as AmountString, + inputs: [{ type: "token", token_family_slug: "sub" } as any], + }, + ], + }; + const editableDefaults: TemplateContractDetailsDefaults = {}; + + applyTemplateUriOverrides( + paivanaUri("KUDOS:7" as AmountString), + templateContract, + editableDefaults, + ); + + assert.deepStrictEqual( + (templateContract as any).choices.map((c: any) => c.amount), + ["EUR:5", "KUDOS:5"], + ); +});