taler-typescript-core

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

commit 55ea189dec5044a3dfa6b521056fff165b7510a0
parent 04709bcc4951f3cd98371c738dc0afd25ee67caf
Author: Sebastian <sebasjm@gmail.com>
Date:   Thu,  3 Apr 2025 13:34:51 -0300

test for #9694

Diffstat:
Mpackages/taler-harness/src/harness/harness.ts | 12++++++++++--
Mpackages/taler-harness/src/integrationtests/test-kyc.ts | 21+++++++++++++++++++++
Mpackages/taler-util/src/promises.ts | 2++
3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts @@ -2366,8 +2366,6 @@ export class WalletClient { }, }); this.remoteWallet = w; - - this.waiter.waitForNotificationCond; } get client() { @@ -2382,6 +2380,16 @@ export class WalletClient { ): Promise<T> { return this.waiter.waitForNotificationCond(cond); } + + async waitForNotificationCondOrTimeout<T>( + cond: (n: WalletNotification) => T | undefined | false, + timeout: number, + ): Promise<T | undefined> { + return Promise.race([ + waitMs(timeout).then((d) => undefined), + this.waiter.waitForNotificationCond(cond), + ]); + } } export class WalletCli { diff --git a/packages/taler-harness/src/integrationtests/test-kyc.ts b/packages/taler-harness/src/integrationtests/test-kyc.ts @@ -302,6 +302,27 @@ export async function runKycTest(t: GlobalTestState) { const accessToken = txState.kycAccessToken; t.assertTrue(!!accessToken); + /** + * TODO: we should check this in another way that doesn't make the test + * to normally take 3 seconds on happy path + */ + const unexpectedNotification = + await walletClient.waitForNotificationCondOrTimeout((x) => { + if ( + x.type === NotificationType.TransactionStateTransition && + x.transactionId === withdrawalTxId && + x.newTxState.major === TransactionMajorState.Pending && + x.newTxState.minor === TransactionMinorState.WithdrawCoins + ) { + return x; + } + return false; + }, 3000); + + if (unexpectedNotification) { + throw Error(`unexpected notification ${j2s(unexpectedNotification)}`); + } + const infoResp = await harnessHttpLib.fetch( new URL(`kyc-info/${txState.kycAccessToken}`, exchange.baseUrl).href, ); diff --git a/packages/taler-util/src/promises.ts b/packages/taler-util/src/promises.ts @@ -27,6 +27,8 @@ export interface OpenedPromise<T> { } /** + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers + * * Get an unresolved promise together with its extracted resolve / reject * function. *