aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-06-03 10:13:56 +0200
committerFlorian Dold <florian@dold.me>2024-06-03 10:13:56 +0200
commitfda35976e44b8dad3249124cd3a8cd8e0f723020 (patch)
tree7b43f290cbd8c904d4dbddff474e790f9689279c /packages
parentcf6fcbffdabe8e8ab08a5d1161ba766a9d18d9fd (diff)
downloadwallet-core-fda35976e44b8dad3249124cd3a8cd8e0f723020.tar.xz
harness: test transitioning back to done state from auto-refund
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-harness/src/integrationtests/test-refund-auto.ts166
1 files changed, 119 insertions, 47 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-refund-auto.ts b/packages/taler-harness/src/integrationtests/test-refund-auto.ts
index 5fcfa066a..6e02071af 100644
--- a/packages/taler-harness/src/integrationtests/test-refund-auto.ts
+++ b/packages/taler-harness/src/integrationtests/test-refund-auto.ts
@@ -17,7 +17,12 @@
/**
* Imports.
*/
-import { Duration, MerchantApiClient } from "@gnu-taler/taler-util";
+import {
+ Duration,
+ MerchantApiClient,
+ TransactionMajorState,
+ TransactionMinorState,
+} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState } from "../harness/harness.js";
import {
@@ -47,67 +52,134 @@ export async function runRefundAutoTest(t: GlobalTestState) {
await wres.withdrawalFinishedCond;
- // Set up order.
- const orderResp = await merchantClient.createOrder({
- order: {
- summary: "Buy me!",
- amount: "TESTKUDOS:5",
- fulfillment_url: "taler://fulfillment-success/thx",
- auto_refund: {
- d_us: 3000 * 1000,
+ // Test case where the auto-refund happens
+ {
+ // Set up order.
+ const orderResp = await merchantClient.createOrder({
+ order: {
+ summary: "Buy me!",
+ amount: "TESTKUDOS:5",
+ fulfillment_url: "taler://fulfillment-success/thx",
+ auto_refund: {
+ d_us: 3000 * 1000,
+ },
},
- },
- refund_delay: Duration.toTalerProtocolDuration(
- Duration.fromSpec({ minutes: 5 }),
- ),
- });
+ refund_delay: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({ minutes: 5 }),
+ ),
+ });
- let orderStatus = await merchantClient.queryPrivateOrderStatus({
- orderId: orderResp.order_id,
- });
+ let orderStatus = await merchantClient.queryPrivateOrderStatus({
+ orderId: orderResp.order_id,
+ });
- t.assertTrue(orderStatus.order_status === "unpaid");
+ t.assertTrue(orderStatus.order_status === "unpaid");
- // Make wallet pay for the order
+ // Make wallet pay for the order
- const r1 = await walletClient.call(WalletApiOperation.PreparePayForUri, {
- talerPayUri: orderStatus.taler_pay_uri,
- });
+ const r1 = await walletClient.call(WalletApiOperation.PreparePayForUri, {
+ talerPayUri: orderStatus.taler_pay_uri,
+ });
- await walletClient.call(WalletApiOperation.ConfirmPay, {
- transactionId: r1.transactionId,
- });
+ await walletClient.call(WalletApiOperation.ConfirmPay, {
+ transactionId: r1.transactionId,
+ });
- // Check if payment was successful.
+ // Check if payment was successful.
- orderStatus = await merchantClient.queryPrivateOrderStatus({
- orderId: orderResp.order_id,
- });
+ orderStatus = await merchantClient.queryPrivateOrderStatus({
+ orderId: orderResp.order_id,
+ });
- t.assertTrue(orderStatus.order_status === "paid");
+ t.assertTrue(orderStatus.order_status === "paid");
- const ref = await merchantClient.giveRefund({
- amount: "TESTKUDOS:5",
- instance: "default",
- justification: "foo",
- orderId: orderResp.order_id,
- });
+ const ref = await merchantClient.giveRefund({
+ amount: "TESTKUDOS:5",
+ instance: "default",
+ justification: "foo",
+ orderId: orderResp.order_id,
+ });
+
+ console.log(ref);
+
+ // The wallet should now automatically pick up the refund.
+ await walletClient.call(
+ WalletApiOperation.TestingWaitTransactionsFinal,
+ {},
+ );
+
+ const transactions = await walletClient.call(
+ WalletApiOperation.GetTransactions,
+ {
+ sort: "stable-ascending",
+ },
+ );
+ console.log(JSON.stringify(transactions, undefined, 2));
+
+ const transactionTypes = transactions.transactions.map((x) => x.type);
+ t.assertDeepEqual(transactionTypes, ["withdrawal", "payment", "refund"]);
+ }
+
+ // Now test the case where the auto-refund just expires
+
+ {
+ // Set up order.
+ const orderResp = await merchantClient.createOrder({
+ order: {
+ summary: "Buy me!",
+ amount: "TESTKUDOS:5",
+ fulfillment_url: "taler://fulfillment-success/thx",
+ auto_refund: {
+ d_us: 3000 * 1000,
+ },
+ },
+ refund_delay: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({ minutes: 5 }),
+ ),
+ });
+
+ let orderStatus = await merchantClient.queryPrivateOrderStatus({
+ orderId: orderResp.order_id,
+ });
+
+ t.assertTrue(orderStatus.order_status === "unpaid");
- console.log(ref);
+ // Make wallet pay for the order
- // The wallet should now automatically pick up the refund.
- await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
+ const r1 = await walletClient.call(WalletApiOperation.PreparePayForUri, {
+ talerPayUri: orderStatus.taler_pay_uri,
+ });
- const transactions = await walletClient.call(
- WalletApiOperation.GetTransactions,
- {},
- );
- console.log(JSON.stringify(transactions, undefined, 2));
+ await walletClient.call(WalletApiOperation.ConfirmPay, {
+ transactionId: r1.transactionId,
+ });
- const transactionTypes = transactions.transactions.map((x) => x.type);
- t.assertDeepEqual(transactionTypes, ["withdrawal", "payment", "refund"]);
+ // Check if payment was successful.
- await t.shutdown();
+ orderStatus = await merchantClient.queryPrivateOrderStatus({
+ orderId: orderResp.order_id,
+ });
+
+ t.assertTrue(orderStatus.order_status === "paid");
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: r1.transactionId,
+ txState: {
+ major: TransactionMajorState.Pending,
+ minor: TransactionMinorState.AutoRefund,
+ },
+ });
+ // Only time-travel the wallet
+ await walletClient.call(WalletApiOperation.TestingSetTimetravel, {
+ offsetMs: 5000,
+ });
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: r1.transactionId,
+ txState: {
+ major: TransactionMajorState.Done,
+ },
+ });
+ }
}
runRefundAutoTest.suites = ["wallet"];