taler-typescript-core

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

commit 70bd1230b3d0538f0bdb4965bf2d92730b44a808
parent 15cd09e5ce7293dc5ae370b67426a4b2cc5a219b
Author: Florian Dold <florian@dold.me>
Date:   Tue,  7 Jan 2025 19:31:45 +0100

-missing file

Diffstat:
Apackages/taler-harness/src/integrationtests/test-withdrawal-cashacceptor.ts | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+), 0 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-cashacceptor.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-cashacceptor.ts @@ -0,0 +1,98 @@ +/* + This file is part of GNU Taler + (C) 2020 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 { + j2s, + narrowOpSuccessOrThrow, + TalerCoreBankHttpClient, +} from "@gnu-taler/taler-util"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { + createSimpleTestkudosEnvironmentV3, + registerHarnessBankTestUser, +} from "../harness/environments.js"; +import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; + +/** + * Test a cash-acceptor-style withdrawal where the amount + * is not known upfront but also can't be chosen by the wallet. + */ +export async function runWithdrawalCashacceptorTest(t: GlobalTestState) { + // Set up test environment + + const { walletClient, exchange, bank } = + await createSimpleTestkudosEnvironmentV3(t, undefined, { + forceLibeufin: true, + }); + + const bankClientNg = new TalerCoreBankHttpClient( + bank.corebankApiBaseUrl, + harnessHttpLib, + ); + + const bankUser = await registerHarnessBankTestUser(bankClientNg); + + const withdrawalRes = await bankClientNg.createWithdrawal(bankUser, { + no_amount_to_wallet: true, + }); + + narrowOpSuccessOrThrow("createWithdrawal", withdrawalRes); + + const wop = withdrawalRes.body; + + const r1 = await walletClient.call( + WalletApiOperation.GetWithdrawalDetailsForUri, + { + talerWithdrawUri: wop.taler_withdraw_uri, + }, + ); + + console.log(j2s(r1)); + + t.assertTrue(!r1.amount); + + // Withdraw + + await walletClient.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, { + exchangeBaseUrl: exchange.baseUrl, + talerWithdrawUri: wop.taler_withdraw_uri, + }); + + const txns = await walletClient.call( + WalletApiOperation.GetTransactionsV2, + {}, + ); + console.log(`transactions: ${j2s(txns)}`); + + const bankConfirmResp = await bankClientNg.confirmWithdrawalById( + bankUser, + { + amount: "TESTKUDOS:10", + }, + wop.withdrawal_id, + ); + narrowOpSuccessOrThrow("confirmWithdrawalById", bankConfirmResp); + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); + + const bal = await walletClient.call(WalletApiOperation.GetBalances, {}); + + t.assertAmountEquals(bal.balances[0].available, "TESTKUDOS:9.72"); +} + +runWithdrawalCashacceptorTest.suites = ["wallet"];