taler-typescript-core

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

commit 829904a236b17f717b1f8a7ef06d5c0916d2970f
parent 973f5819a02dd9b86831542f358bb4aef887a67f
Author: Florian Dold <florian@dold.me>
Date:   Fri, 19 Jun 2026 16:29:50 +0200

tests for templates

Diffstat:
Apackages/taler-harness/src/integrationtests/test-merchant-templates.ts | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-harness/src/integrationtests/test-payment-template.ts | 37+++++++++++++++++++++++++++++++++++++
Mpackages/taler-harness/src/integrationtests/testrunner.ts | 2++
3 files changed, 156 insertions(+), 0 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-merchant-templates.ts b/packages/taler-harness/src/integrationtests/test-merchant-templates.ts @@ -0,0 +1,117 @@ +/* + This file is part of GNU Taler + (C) 2021 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/> + */ + +/** + * Imports. + */ +import { + AmountString, + TalerMerchantInstanceHttpClient, + TemplateType, + codecForMerchantContractTerms, + createEddsaKeyPair, + encodeCrock, + j2s, + succeedOrThrow, +} from "@gnu-taler/taler-util"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; + +export async function runMerchantTemplatesTest(t: GlobalTestState) { + // Set up test environment + + const { + bankClient, + walletClient, + exchange, + merchant, + merchantAdminAccessToken, + } = await createSimpleTestkudosEnvironmentV3(t); + + const client = new TalerMerchantInstanceHttpClient( + merchant.makeInstanceBaseUrl(), + ); + + succeedOrThrow( + await client.addTemplate(merchantAdminAccessToken, { + template_id: "p1", + template_contract: { + template_type: TemplateType.PAIVANA, + choices: [ + { + amount: "TESTKUDOS:1" as AmountString, + }, + ], + }, + template_description: "Foo", + }), + ); + + const templateInfo = succeedOrThrow(await client.useTemplateGetInfo("p1")); + console.log(j2s(templateInfo)); + + { + const templateResp = succeedOrThrow( + await client.useTemplateCreateOrder("p1", { + summary: "foo", + template_type: TemplateType.PAIVANA, + paivana_id: "4321-6hvIP7UnmNDVjp5Intuf9jFK7MzW0ycEyxf5Mszl3xs=", + website: "foo", + }), + ); + console.log(j2s(templateResp)); + const noncePair = createEddsaKeyPair(); + const orderResp = succeedOrThrow( + await client.claimOrder({ + orderId: templateResp.order_id, + body: { + nonce: encodeCrock(noncePair.eddsaPub), + token: templateResp.token, + }, + }), + ); + console.log(j2s(orderResp)); + } + + { + const templateResp = succeedOrThrow( + await client.useTemplateCreateOrder("p1", { + summary: "foo", + template_type: TemplateType.PAIVANA, + paivana_id: "4321-6hvIP7UnmNDVjp5Intuf9jFK7MzW0ycEyxf5Mszl3xs=", + website: "foo", + amount: "TESTKUDOS:42", + }), + ); + console.log(j2s(templateResp)); + const noncePair = createEddsaKeyPair(); + const orderResp = succeedOrThrow( + await client.claimOrder({ + orderId: templateResp.order_id, + body: { + nonce: encodeCrock(noncePair.eddsaPub), + token: templateResp.token, + }, + }), + ); + console.log(j2s(orderResp)); + const ct = codecForMerchantContractTerms().decode(orderResp.contract_terms); + t.assertDeepEqual(ct.version, 1); + t.assertAmountEquals(ct.choices[0].amount, "TESTKUDOS:42"); + } +} + +runMerchantTemplatesTest.suites = ["merchant"]; diff --git a/packages/taler-harness/src/integrationtests/test-payment-template.ts b/packages/taler-harness/src/integrationtests/test-payment-template.ts @@ -24,6 +24,7 @@ import { PreparePayResultType, TalerMerchantInstanceHttpClient, TemplateType, + j2s, succeedOrThrow, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -133,6 +134,42 @@ export async function runPaymentTemplateTest(t: GlobalTestState) { ); t.assertTrue(orderStatus.order_status === "paid"); + + // Now test overrides from URIs. + { + const talerPayTemplateUriAmt = `taler+http://pay-template/localhost:${merchant.port}/template1?amount=TESTKUDOS:5`; + + const checkPayTemplateResult = await walletClient.call( + WalletApiOperation.CheckPayForTemplate, + { + talerPayTemplateUri: talerPayTemplateUriAmt, + }, + ); + + console.log(j2s(checkPayTemplateResult)); + + const tc = checkPayTemplateResult.templateDetails.template_contract; + + t.assertDeepEqual(tc.template_type, TemplateType.FIXED_ORDER); + t.assertTrue(!!tc.amount); + // Amount is taken from the template! + t.assertAmountEquals(tc.amount, "TESTKUDOS:5"); + + const preparePayResult = await walletClient.call( + WalletApiOperation.PreparePayForTemplate, + { + talerPayTemplateUri: talerPayTemplateUriAmt, + }, + ); + + t.assertDeepEqual( + preparePayResult.status, + PreparePayResultType.PaymentPossible, + ); + + t.assertAmountEquals(preparePayResult.contractTerms.amount, "TESTKUDOS:5"); + } + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); } diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts @@ -126,6 +126,7 @@ import { runMerchantSelfProvisionActivationTest } from "./test-merchant-self-pro import { runMerchantSelfProvisionForgotPasswordTest } from "./test-merchant-self-provision-forgot-password.js"; import { runMerchantSelfProvisionInactiveAccountPermissionsTest } from "./test-merchant-self-provision-inactive-account-permissions.js"; import { runMerchantSpecPublicOrdersTest } from "./test-merchant-spec-public-orders.js"; +import { runMerchantTemplatesTest } from "./test-merchant-templates.js"; import { runMerchantTokenfamiliesTest } from "./test-merchant-tokenfamilies.js"; import { runMerchantWireTest } from "./test-merchant-wire.js"; import { runMultiExchangeTest } from "./test-multiexchange.js"; @@ -444,6 +445,7 @@ const allTests: TestMainFunction[] = [ runMerchantRefundFeesTest, runMerchantTokenfamiliesTest, runBalanceProspectiveTest, + runMerchantTemplatesTest, ]; export interface TestRunSpec {