commit 6c81a0791cf3f2e068cf53e52f7dd88c21d8ee0f
parent 208fcb920418497497870c4971fedbe38d880cc9
Author: Iván Ávalos <avalos@disroot.org>
Date: Mon, 30 Jun 2025 19:08:42 +0200
harness: improvements wallet-tokens test
Diffstat:
1 file changed, 41 insertions(+), 14 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts b/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts
@@ -169,6 +169,8 @@ export async function runWalletTokensTest(t: GlobalTestState) {
{
logger.info("Payment with discount token output...");
+ const choiceIndex = 0;
+
const orderResp = succeedOrThrow(
await merchantApi.createOrder(undefined, {
order: orderJsonDiscount,
@@ -197,7 +199,7 @@ export async function runWalletTokensTest(t: GlobalTestState) {
await walletClient.call(WalletApiOperation.ConfirmPay, {
transactionId: preparePayResult.transactionId,
- choiceIndex: 0,
+ choiceIndex,
});
orderStatus = succeedOrThrow(
@@ -209,6 +211,8 @@ export async function runWalletTokensTest(t: GlobalTestState) {
{
logger.info("Payment with discount token input...");
+ const choiceIndex = 1;
+
const orderResp = succeedOrThrow(
await merchantApi.createOrder(undefined, {
order: orderJsonDiscount,
@@ -243,18 +247,24 @@ export async function runWalletTokensTest(t: GlobalTestState) {
t.assertTrue(choicesRes.defaultChoiceIndex === 1);
t.assertTrue(choicesRes.automaticExecution === false);
- t.assertTrue(choicesRes.choices[0].status ===
+ t.assertTrue(choicesRes.choices[choiceIndex].status ===
ChoiceSelectionDetailType.PaymentPossible,
);
- const tokenDetails = choicesRes.choices[1].tokenDetails;
+ const tokenDetails = choicesRes.choices[choiceIndex].tokenDetails;
+ logger.info("tokenDetails:", tokenDetails);
t.assertTrue(tokenDetails?.tokensAvailable === 1);
t.assertTrue(tokenDetails?.tokensRequested === 1);
+ for (const tf in tokenDetails?.perTokenFamily ?? t.fail()) {
+ t.assertTrue(tokenDetails?.perTokenFamily[tf].available === 1);
+ t.assertTrue(tokenDetails?.perTokenFamily[tf].requested === 1);
+ break;
+ }
}
await walletClient.call(WalletApiOperation.ConfirmPay, {
transactionId: preparePayResult.transactionId,
- choiceIndex: 1,
+ choiceIndex,
});
orderStatus = succeedOrThrow(
@@ -264,6 +274,8 @@ export async function runWalletTokensTest(t: GlobalTestState) {
{
logger.info("Payment with discount token input, insufficient tokens...");
+ const choiceIndex = 1;
+
const orderResp = succeedOrThrow(
await merchantApi.createOrder(undefined, {
order: orderJsonDiscount,
@@ -298,20 +310,26 @@ export async function runWalletTokensTest(t: GlobalTestState) {
t.assertTrue(choicesRes.defaultChoiceIndex === 0);
t.assertTrue(choicesRes.automaticExecution === false);
- t.assertTrue(choicesRes.choices[1].status ===
+ t.assertTrue(choicesRes.choices[choiceIndex].status ===
ChoiceSelectionDetailType.InsufficientBalance,
);
- const tokenDetails = choicesRes.choices[1].tokenDetails;
+ const tokenDetails = choicesRes.choices[choiceIndex].tokenDetails;
+ logger.info("tokenDetails:", tokenDetails);
t.assertTrue(tokenDetails?.tokensAvailable === 0);
t.assertTrue(tokenDetails?.tokensRequested === 1);
+ for (const tf in tokenDetails?.perTokenFamily ?? t.fail()) {
+ t.assertTrue(tokenDetails?.perTokenFamily[tf].available === 0);
+ t.assertTrue(tokenDetails?.perTokenFamily[tf].requested === 1);
+ break;
+ }
}
// should fail because we have no tokens left
t.assertThrowsAsync(async () => {
await walletClient.call(WalletApiOperation.ConfirmPay, {
transactionId: preparePayResult.transactionId,
- choiceIndex: 1,
+ choiceIndex,
});
});
@@ -324,6 +342,8 @@ export async function runWalletTokensTest(t: GlobalTestState) {
{
logger.info("Payment with subscription token output...");
+ const choiceIndex = 0;
+
const orderResp = succeedOrThrow(
await merchantApi.createOrder(undefined, {
order: orderJsonSubscription,
@@ -352,7 +372,7 @@ export async function runWalletTokensTest(t: GlobalTestState) {
await walletClient.call(WalletApiOperation.ConfirmPay, {
transactionId: preparePayResult.transactionId,
- choiceIndex: 0,
+ choiceIndex,
});
orderStatus = succeedOrThrow(
@@ -363,7 +383,9 @@ export async function runWalletTokensTest(t: GlobalTestState) {
}
{
- logger.info("Payment with subscription token input...");
+ logger.info("Payment with subscription token input and output...");
+ const choiceIndex = 1;
+
const orderResp = succeedOrThrow(
await merchantApi.createOrder(undefined, {
order: orderJsonSubscription,
@@ -391,26 +413,31 @@ export async function runWalletTokensTest(t: GlobalTestState) {
);
{
- logger.info("Payment with subscription token input and output...");
const choicesRes = await walletClient.call(WalletApiOperation.GetChoicesForPayment, {
transactionId: preparePayResult.transactionId,
});
- t.assertTrue(choicesRes.defaultChoiceIndex === 1);
+ t.assertTrue(choicesRes.defaultChoiceIndex === choiceIndex);
t.assertTrue(choicesRes.automaticExecution === true);
- t.assertTrue(choicesRes.choices[1].status ===
+ t.assertTrue(choicesRes.choices[choiceIndex].status ===
ChoiceSelectionDetailType.PaymentPossible,
);
- const tokenDetails = choicesRes.choices[1].tokenDetails;
+ const tokenDetails = choicesRes.choices[choiceIndex].tokenDetails;
+ logger.info("tokenDetails:", tokenDetails);
t.assertTrue(tokenDetails?.tokensAvailable === 1);
t.assertTrue(tokenDetails?.tokensRequested === 1);
+ for (const tf in tokenDetails?.perTokenFamily ?? t.fail()) {
+ t.assertTrue(tokenDetails?.perTokenFamily[tf].available === 1);
+ t.assertTrue(tokenDetails?.perTokenFamily[tf].requested === 1);
+ break;
+ }
}
await walletClient.call(WalletApiOperation.ConfirmPay, {
transactionId: preparePayResult.transactionId,
- choiceIndex: 1,
+ choiceIndex,
});
orderStatus = succeedOrThrow(