diff options
Diffstat (limited to 'packages/taler-harness')
4 files changed, 38 insertions, 40 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index 5c2133064..c08f3fa1d 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -28,6 +28,7 @@ import { AmountJson, Amounts, AmountString, + codecForMerchantReserveCreateConfirmation, Configuration, CoreApiResponse, createEddsaKeyPair, @@ -38,6 +39,7 @@ import { hash, j2s, Logger, + MerchantReserveCreateConfirmation, MerchantTemplateAddDetails, parsePaytoUri, stringToBytes, @@ -81,7 +83,11 @@ import { RemoteWallet, WalletNotificationWaiter, } from "@gnu-taler/taler-wallet-core/remote"; -import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; +import { + createPlatformHttpLib, + readSuccessResponseJsonOrErrorCode, + readSuccessResponseJsonOrThrow, +} from "@gnu-taler/taler-util/http"; const logger = new Logger("harness.ts"); @@ -1568,13 +1574,18 @@ export class MerchantApiClient { async createTippingReserve( req: CreateMerchantTippingReserveRequest, - ): Promise<CreateMerchantTippingReserveConfirmation> { + ): Promise<MerchantReserveCreateConfirmation> { const url = new URL("private/reserves", this.baseUrl); - const resp = await axios.post(url.href, req, { + const resp = await this.http.fetch(url.href, { + method: "POST", + body: req, headers: this.makeAuthHeader(), }); - // FIXME: validate - return resp.data; + const respData = readSuccessResponseJsonOrThrow( + resp, + codecForMerchantReserveCreateConfirmation(), + ); + return respData; } async getPrivateInstanceInfo(): Promise<any> { @@ -1719,21 +1730,6 @@ export namespace MerchantPrivateApi { }; } - export async function createTippingReserve( - merchantService: MerchantServiceInterface, - instance: string, - req: CreateMerchantTippingReserveRequest, - ): Promise<CreateMerchantTippingReserveConfirmation> { - const reqUrl = new URL( - `private/reserves`, - merchantService.makeInstanceBaseUrl(instance), - ); - // FIXME: Don't use axios! - const resp = await axios.post(reqUrl.href, req); - // FIXME: validate - return resp.data; - } - export async function queryTippingReserves( merchantService: MerchantServiceInterface, instance: string, @@ -1773,14 +1769,6 @@ export interface CreateMerchantTippingReserveRequest { wire_method: string; } -export interface CreateMerchantTippingReserveConfirmation { - // Public key identifying the reserve - reserve_pub: string; - - // Wire account of the exchange where to transfer the funds - payto_uri: string; -} - export class MerchantService implements MerchantServiceInterface { static fromExistingConfig(gc: GlobalTestState, name: string) { const cfgFilename = gc.testDir + `/merchant-${name}.conf`; diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index bd58a7fd6..ec99232f5 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -213,7 +213,7 @@ deploymentCli allowHttp: true, }); - const paytoUri = addPaytoQueryParams(tipReserveResp.payto_uri, { + const paytoUri = addPaytoQueryParams(tipReserveResp.accounts[0].payto_uri, { message: `tip-reserve ${tipReserveResp.reserve_pub}`, }); diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts index 38cbd6925..c4db7022d 100644 --- a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts +++ b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts @@ -26,6 +26,7 @@ import { defaultCoinConfig } from "../harness/denomStructures.js"; import { getWireMethodForTest, GlobalTestState, + MerchantApiClient, MerchantPrivateApi, WalletCli, } from "../harness/harness.js"; @@ -55,6 +56,13 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { }, ); + const merchantClient = new MerchantApiClient( + merchant.makeInstanceBaseUrl("default"), + { + method: "external", + }, + ); + const walletTwo = new WalletCli(t, "walletTwo"); const walletThree = new WalletCli(t, "walletThree"); @@ -147,9 +155,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { // Pay with coin from tipping { const mbu = await BankApi.createRandomBankUser(bank); - const tipReserveResp = await MerchantPrivateApi.createTippingReserve( - merchant, - "default", + const tipReserveResp = await merchantClient.createTippingReserve( { exchange_url: exchange.baseUrl, initial_balance: "TESTKUDOS:10", @@ -158,7 +164,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { ); t.assertDeepEqual( - tipReserveResp.payto_uri, + tipReserveResp.accounts[0].payto_uri, exchangeBankAccount.accountPaytoUri, ); diff --git a/packages/taler-harness/src/integrationtests/test-tipping.ts b/packages/taler-harness/src/integrationtests/test-tipping.ts index b124fbf0d..bbf729420 100644 --- a/packages/taler-harness/src/integrationtests/test-tipping.ts +++ b/packages/taler-harness/src/integrationtests/test-tipping.ts @@ -24,6 +24,7 @@ import { } from "@gnu-taler/taler-wallet-core"; import { GlobalTestState, + MerchantApiClient, MerchantPrivateApi, getWireMethodForTest, } from "../harness/harness.js"; @@ -40,20 +41,23 @@ export async function runTippingTest(t: GlobalTestState) { const mbu = await BankApi.createRandomBankUser(bank); - const tipReserveResp = await MerchantPrivateApi.createTippingReserve( - merchant, - "default", + const merchantClient = new MerchantApiClient( + merchant.makeInstanceBaseUrl("default"), { - exchange_url: exchange.baseUrl, - initial_balance: "TESTKUDOS:10", - wire_method: getWireMethodForTest(), + method: "external", }, ); + const tipReserveResp = await merchantClient.createTippingReserve({ + exchange_url: exchange.baseUrl, + initial_balance: "TESTKUDOS:10", + wire_method: getWireMethodForTest(), + }); + console.log("tipReserveResp:", tipReserveResp); t.assertDeepEqual( - tipReserveResp.payto_uri, + tipReserveResp.accounts[0].payto_uri, exchangeBankAccount.accountPaytoUri, ); |