aboutsummaryrefslogtreecommitdiff
path: root/src/headless/integrationtest.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-01-18 20:55:34 +0100
committerFlorian Dold <florian.dold@gmail.com>2020-01-18 20:55:34 +0100
commitfcb0565323d3134ec2dc376700ef85a2c7b7becd (patch)
treefe74e16ab1ffd0ecb6a2a2dd03a8a26618ad71a7 /src/headless/integrationtest.ts
parent9ad8c69782b69e2565bf6cdcb8cca555fced1292 (diff)
generate refund in integration test
Diffstat (limited to 'src/headless/integrationtest.ts')
-rw-r--r--src/headless/integrationtest.ts153
1 files changed, 121 insertions, 32 deletions
diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts
index 05aa760b0..b00fa5ccb 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();
}