gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: generate refund in integratio


From: gnunet
Subject: [taler-wallet-core] branch master updated: generate refund in integration test
Date: Sat, 18 Jan 2020 20:55:40 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new fcb05653 generate refund in integration test
fcb05653 is described below

commit fcb0565323d3134ec2dc376700ef85a2c7b7becd
Author: Florian Dold <address@hidden>
AuthorDate: Sat Jan 18 20:55:34 2020 +0100

    generate refund in integration test
---
 src/headless/integrationtest.ts | 153 +++++++++++++++++++++++++++++++---------
 src/headless/merchant.ts        |   2 +-
 2 files changed, 122 insertions(+), 33 deletions(-)

diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts
index 05aa760b..b00fa5cc 100644
--- a/src/headless/integrationtest.ts
+++ b/src/headless/integrationtest.ts
@@ -22,30 +22,93 @@ import { getDefaultNodeWallet, withdrawTestBalance } from 
"./helpers";
 import { MerchantBackendConnection } from "./merchant";
 import { Logger } from "../util/logging";
 import { NodeHttpLib } from "./NodeHttpLib";
+import * as Amounts from "../util/amounts";
+import { Wallet } from "../wallet";
 
 const logger = new Logger("integrationtest.ts");
 
-export async function runIntegrationTest(args: {
+export interface IntegrationTestArgs {
   exchangeBaseUrl: string;
   bankBaseUrl: string;
   merchantBaseUrl: string;
   merchantApiKey: string;
   amountToWithdraw: string;
   amountToSpend: string;
-}) {
+}
+
+async function makePayment(
+  wallet: Wallet,
+  merchant: MerchantBackendConnection,
+  amount: string,
+  summary: string,
+): Promise<{ orderId: string }> {
+  let orderResp = await merchant.createOrder(
+    amount,
+    summary,
+    "taler://fulfillment-success/thx",
+  );
+
+  console.log("created order with orderId", orderResp.orderId);
+
+  let paymentStatus = await merchant.checkPayment(orderResp.orderId);
+
+  console.log("payment status", paymentStatus);
+
+  const talerPayUri = paymentStatus.taler_pay_uri;
+  if (!talerPayUri) {
+    throw Error("no taler://pay/ URI in payment response");
+  }
+
+  let preparePayResult = await wallet.preparePayForUri(talerPayUri);
+
+  console.log("prepare pay result", preparePayResult);
+
+  if (preparePayResult.status != "payment-possible") {
+    throw Error("payment not possible");
+  }
+
+  let confirmPayResult = await wallet.confirmPay(
+    preparePayResult.proposalId,
+    undefined,
+  );
+
+  console.log("confirmPayResult", confirmPayResult);
+
+  paymentStatus = await merchant.checkPayment(orderResp.orderId);
+
+  console.log("payment status after wallet payment:", paymentStatus);
+
+  if (!paymentStatus.paid) {
+    throw Error("payment did not succeed");
+  }
+
+  return {
+    orderId: orderResp.orderId,
+  };
+}
+
+export async function runIntegrationTest(args: IntegrationTestArgs) {
   logger.info("running test with arguments", args);
 
+  const parsedSpendAmount = Amounts.parseOrThrow(args.amountToSpend);
+  const currency = parsedSpendAmount.currency;
+
   const myHttpLib = new NodeHttpLib();
   myHttpLib.setThrottling(false);
 
   const myWallet = await getDefaultNodeWallet({ httpLib: myHttpLib });
 
-  myWallet.runRetryLoop().catch((e) => {
+  myWallet.runRetryLoop().catch(e => {
     console.error("exception during retry loop:", e);
   });
 
   logger.info("withdrawing test balance");
-  await withdrawTestBalance(myWallet, args.amountToWithdraw, args.bankBaseUrl, 
args.exchangeBaseUrl);
+  await withdrawTestBalance(
+    myWallet,
+    args.amountToWithdraw,
+    args.bankBaseUrl,
+    args.exchangeBaseUrl,
+  );
   logger.info("done withdrawing test balance");
 
   const balance = await myWallet.getBalances();
@@ -57,42 +120,68 @@ export async function runIntegrationTest(args: {
     args.merchantApiKey,
   );
 
-  const orderResp = await myMerchant.createOrder(
-    args.amountToSpend,
-    "hello world",
-    "https://example.com/";,
-  );
-
-  console.log("created order with orderId", orderResp.orderId);
-
-  const paymentStatus = await myMerchant.checkPayment(orderResp.orderId);
-
-  console.log("payment status", paymentStatus);
-
-  const talerPayUri = paymentStatus.taler_pay_uri;
-  if (!talerPayUri) {
-    throw Error("no taler://pay/ URI in payment response");
-  }
+  await makePayment(myWallet, myMerchant, args.amountToSpend, "hello world");
 
-  const preparePayResult = await myWallet.preparePayForUri(talerPayUri);
+  // Wait until the refresh is done
+  await myWallet.runUntilDone();
 
-  console.log("prepare pay result", preparePayResult);
+  console.log("withdrawing test balance for refund");
+  const withdrawAmountTwo: Amounts.AmountJson = {
+    currency,
+    value: 18,
+    fraction: 0,
+  };
+  const spendAmountTwo: Amounts.AmountJson = {
+    currency,
+    value: 7,
+    fraction: 0,
+  };
+
+  const refundAmount: Amounts.AmountJson = {
+    currency,
+    value: 6,
+    fraction: 0,
+  };
+
+  const spendAmountThree: Amounts.AmountJson = {
+    currency,
+    value: 3,
+    fraction: 0,
+  };
+  await withdrawTestBalance(
+    myWallet,
+    Amounts.toString(withdrawAmountTwo),
+    args.bankBaseUrl,
+    args.exchangeBaseUrl,
+  );
 
-  if (preparePayResult.status != "payment-possible") {
-    throw Error("payment not possible");
-  }
+  // Wait until the withdraw is done
+  await myWallet.runUntilDone();
 
-  const confirmPayResult = await 
myWallet.confirmPay(preparePayResult.proposalId, undefined);
+  let { orderId: refundOrderId } = await makePayment(
+    myWallet,
+    myMerchant,
+    Amounts.toString(spendAmountTwo),
+    "order that will be refunded",
+  );
 
-  console.log("confirmPayResult", confirmPayResult);
+  const refundUri = await myMerchant.refund(
+    refundOrderId,
+    "test refund",
+    Amounts.toString(refundAmount),
+  );
 
-  const paymentStatus2 = await myMerchant.checkPayment(orderResp.orderId);
+  await myWallet.applyRefund(refundUri);
 
-  console.log("payment status after wallet payment:", paymentStatus2);
+  // Wait until the refund is done
+  await myWallet.runUntilDone();
 
-  if (!paymentStatus2.paid) {
-    throw Error("payment did not succeed");
-  }
+  await makePayment(
+    myWallet,
+    myMerchant,
+    Amounts.toString(spendAmountThree),
+    "payment after refund",
+  );
 
   await myWallet.runUntilDone();
 }
diff --git a/src/headless/merchant.ts b/src/headless/merchant.ts
index 1da5d5f0..b30e00d8 100644
--- a/src/headless/merchant.ts
+++ b/src/headless/merchant.ts
@@ -33,7 +33,7 @@ export class MerchantBackendConnection {
     orderId: string,
     reason: string,
     refundAmount: string,
-  ): Promise<void> {
+  ): Promise<string> {
     const reqUrl = new URL("refund", this.merchantBaseUrl);
     const refundReq = {
       order_id: orderId,

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]