diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-03-23 17:00:01 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-03-23 17:00:01 +0530 |
commit | eabbbd339bdd2c5b467adb9217ee6c142045f6c5 (patch) | |
tree | edddc9bdb895e7de59b568c9abd6003e8aa1207c /src/headless/integrationtest.ts | |
parent | b6d081b6c7b59e349f2b667ece1b141d52cc4ca2 (diff) | |
download | wallet-core-eabbbd339bdd2c5b467adb9217ee6c142045f6c5.tar.xz |
config files WIP
Diffstat (limited to 'src/headless/integrationtest.ts')
-rw-r--r-- | src/headless/integrationtest.ts | 141 |
1 files changed, 140 insertions, 1 deletions
diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts index 984ef9c39..fbc6223fc 100644 --- a/src/headless/integrationtest.ts +++ b/src/headless/integrationtest.ts @@ -24,6 +24,7 @@ import { Logger } from "../util/logging"; import { NodeHttpLib } from "./NodeHttpLib"; import * as Amounts from "../util/amounts"; import { Wallet } from "../wallet"; +import { Configuration } from "../util/talerconfig"; const logger = new Logger("integrationtest.ts"); @@ -189,5 +190,143 @@ export async function runIntegrationTest(args: IntegrationTestArgs) { const history = await myWallet.getHistory({ verboseDetails: true }); - console.log("history after integration test:", JSON.stringify(history, undefined, 2)); + console.log( + "history after integration test:", + JSON.stringify(history, undefined, 2), + ); +} + +export async function runIntegrationTestBasic(cfg: Configuration) { + const walletDbPath = cfg.getString("integrationtest", "walletdb").required(); + + const bankBaseUrl = cfg + .getString("integrationtest", "bank_base_url") + .required(); + + const exchangeBaseUrl = cfg + .getString("integrationtest", "exchange_base_url") + .required(); + + const merchantBaseUrl = cfg + .getString("integrationtest", "merchant_base_url") + .required(); + + const merchantApiKey = cfg + .getString("integrationtest", "merchant_api_key") + .required(); + + const parsedWithdrawAmount = cfg + .getAmount("integrationtest-basic", "amount_withdraw") + .required(); + + const parsedSpendAmount = cfg + .getAmount("integrationtest-basic", "amount_spend") + .required(); + + const currency = parsedSpendAmount.currency; + + const myHttpLib = new NodeHttpLib(); + myHttpLib.setThrottling(false); + + const myWallet = await getDefaultNodeWallet({ + httpLib: myHttpLib, + persistentStoragePath: walletDbPath, + }); + + myWallet.runRetryLoop().catch(e => { + console.error("exception during retry loop:", e); + }); + + logger.info("withdrawing test balance"); + await withdrawTestBalance( + myWallet, + Amounts.toString(parsedWithdrawAmount), + bankBaseUrl, + exchangeBaseUrl, + ); + logger.info("done withdrawing test balance"); + + const balance = await myWallet.getBalances(); + + console.log(JSON.stringify(balance, null, 2)); + + const myMerchant = new MerchantBackendConnection( + merchantBaseUrl, + merchantApiKey, + ); + + await makePayment(myWallet, myMerchant, Amounts.toString(parsedSpendAmount), "hello world"); + + // Wait until the refresh is done + await myWallet.runUntilDone(); + + 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), + bankBaseUrl, + exchangeBaseUrl, + ); + + // Wait until the withdraw is done + await myWallet.runUntilDone(); + + let { orderId: refundOrderId } = await makePayment( + myWallet, + myMerchant, + Amounts.toString(spendAmountTwo), + "order that will be refunded", + ); + + const refundUri = await myMerchant.refund( + refundOrderId, + "test refund", + Amounts.toString(refundAmount), + ); + + console.log("refund URI", refundUri); + + await myWallet.applyRefund(refundUri); + + // Wait until the refund is done + await myWallet.runUntilDone(); + + await makePayment( + myWallet, + myMerchant, + Amounts.toString(spendAmountThree), + "payment after refund", + ); + + await myWallet.runUntilDone(); + + const history = await myWallet.getHistory({ verboseDetails: true }); + + console.log( + "history after integration test:", + JSON.stringify(history, undefined, 2), + ); } |