fix broken integration tests due to merchant API changes

This commit is contained in:
Florian Dold 2020-11-03 15:56:02 +01:00
parent e259d109ef
commit ca343e4e00
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
8 changed files with 64 additions and 29 deletions

View File

@ -107,6 +107,12 @@ export const codecForCheckPaymentUnpaidResponse = (): Codec<
.property("already_paid_order_id", codecOptional(codecForString())) .property("already_paid_order_id", codecOptional(codecForString()))
.build("CheckPaymentPaidResponse"); .build("CheckPaymentPaidResponse");
export const codecForCheckPaymentClaimedResponse = (): Codec<CheckPaymentClaimedResponse> =>
buildCodecForObject<CheckPaymentClaimedResponse>()
.property("order_status", codecForConstString("claimed"))
.property("contract_terms", codecForContractTerms())
.build("CheckPaymentClaimedResponse");
export const codecForMerchantOrderPrivateStatusResponse = (): Codec< export const codecForMerchantOrderPrivateStatusResponse = (): Codec<
MerchantOrderPrivateStatusResponse MerchantOrderPrivateStatusResponse
> => > =>
@ -114,11 +120,20 @@ export const codecForMerchantOrderPrivateStatusResponse = (): Codec<
.discriminateOn("order_status") .discriminateOn("order_status")
.alternative("paid", codecForCheckPaymentPaidResponse()) .alternative("paid", codecForCheckPaymentPaidResponse())
.alternative("unpaid", codecForCheckPaymentUnpaidResponse()) .alternative("unpaid", codecForCheckPaymentUnpaidResponse())
.alternative("claimed", codecForCheckPaymentClaimedResponse())
.build("MerchantOrderPrivateStatusResponse"); .build("MerchantOrderPrivateStatusResponse");
export type MerchantOrderPrivateStatusResponse = export type MerchantOrderPrivateStatusResponse =
| CheckPaymentPaidResponse | CheckPaymentPaidResponse
| CheckPaymentUnpaidResponse; | CheckPaymentUnpaidResponse
| CheckPaymentClaimedResponse;
export interface CheckPaymentClaimedResponse {
// Wallet claimed the order, but didn't pay yet.
order_status: "claimed";
contract_terms: ContractTerms;
}
export interface CheckPaymentPaidResponse { export interface CheckPaymentPaidResponse {
// did the customer pay for this contract // did the customer pay for this contract
@ -164,6 +179,7 @@ export interface CheckPaymentPaidResponse {
order_status_url: string; order_status_url: string;
} }
export interface CheckPaymentUnpaidResponse { export interface CheckPaymentUnpaidResponse {
order_status: "unpaid"; order_status: "unpaid";

View File

@ -24,11 +24,13 @@ import {
WalletCli, WalletCli,
} from "./harness"; } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
import { PreparePayResultType, TalerErrorCode } from "taler-wallet-core";
import { URL } from "url" import { URL } from "url"
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for the merchant's order lifecycle.
*
* FIXME: Is this test still necessary? We initially wrote if to confirm/document
* assumptions about how the merchant should work.
*/ */
runTest(async (t: GlobalTestState) => { runTest(async (t: GlobalTestState) => {
// Set up test environment // Set up test environment
@ -55,6 +57,7 @@ runTest(async (t: GlobalTestState) => {
let orderStatusBefore = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatusBefore = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
t.assertTrue(orderStatusBefore.order_status === "unpaid");
let statusUrlBefore = new URL(orderStatusBefore.order_status_url); let statusUrlBefore = new URL(orderStatusBefore.order_status_url);
// Make wallet claim the unpaid order. // Make wallet claim the unpaid order.
@ -68,17 +71,7 @@ runTest(async (t: GlobalTestState) => {
let orderStatusAfter = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatusAfter = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
let statusUrlAfter = new URL(orderStatusAfter.order_status_url) t.assertTrue(orderStatusAfter.order_status === "claimed");
let tokenBefore = statusUrlBefore.searchParams.get("token")
let tokenAfter = statusUrlAfter.searchParams.get("token")
let hashContractAfter = statusUrlAfter.searchParams.get("h_contract")
// after claiming the contract, we either want its hash in the
// status url, or at least see again its token in the status url.
t.assertTrue(
(hashContractAfter !== null) || (tokenBefore === tokenAfter)
)
await t.shutdown(); await t.shutdown();
}); });

View File

@ -32,7 +32,7 @@ import {
withdrawViaBank, withdrawViaBank,
SimpleTestEnvironment, SimpleTestEnvironment,
} from "./helpers"; } from "./helpers";
import { PreparePayResultType, URL } from "taler-wallet-core"; import { durationFromSpec, PreparePayResultType, URL } from "taler-wallet-core";
import axios from "axios"; import axios from "axios";
async function testRefundApiWithFulfillmentUrl( async function testRefundApiWithFulfillmentUrl(
@ -53,6 +53,7 @@ async function testRefundApiWithFulfillmentUrl(
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
fulfillment_url: "https://example.com/fulfillment", fulfillment_url: "https://example.com/fulfillment",
}, },
refund_delay: durationFromSpec({ minutes: 5 }),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
@ -162,6 +163,7 @@ async function testRefundApiWithFulfillmentMessage(
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
fulfillment_message: "Thank you for buying foobar", fulfillment_message: "Thank you for buying foobar",
}, },
refund_delay: durationFromSpec({ minutes: 5 }),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {

View File

@ -19,7 +19,6 @@
*/ */
import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness"; import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness";
import { import {
createSimpleTestkudosEnvironment,
withdrawViaBank, withdrawViaBank,
createFaultInjectedMerchantTestkudosEnvironment, createFaultInjectedMerchantTestkudosEnvironment,
} from "./helpers"; } from "./helpers";
@ -33,7 +32,12 @@ import axios from "axios";
import { FaultInjectionRequestContext } from "./faultInjection"; import { FaultInjectionRequestContext } from "./faultInjection";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for the wallets repurchase detection mechanism
* based on the fulfillment URL.
*
* FIXME: This test is now almost the same as test-paywall-flow,
* since we can't initiate payment via a "claimed" private order status
* response.
*/ */
runTest(async (t: GlobalTestState) => { runTest(async (t: GlobalTestState) => {
// Set up test environment // Set up test environment
@ -146,10 +150,10 @@ runTest(async (t: GlobalTestState) => {
sessionId: "mysession-two", sessionId: "mysession-two",
}); });
// Should be unpaid because of a new session ID console.log("order status under mysession-two:", JSON.stringify(orderStatus, undefined, 2));
t.assertTrue(orderStatus.order_status === "unpaid");
publicOrderStatusUrl = orderStatus.order_status_url; // Should be claimed (not paid!) because of a new session ID
t.assertTrue(orderStatus.order_status === "claimed");
let numPayRequested = 0; let numPayRequested = 0;
let numPaidRequested = 0; let numPaidRequested = 0;
@ -165,11 +169,27 @@ runTest(async (t: GlobalTestState) => {
}, },
}); });
let orderRespTwo = await MerchantPrivateApi.createOrder(merchant, "default", {
order: {
summary: "Buy me!",
amount: "TESTKUDOS:5",
fulfillment_url: "https://example.com/article42",
},
});
let orderStatusTwo = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
orderId: orderRespTwo.order_id,
sessionId: "mysession-two",
});
t.assertTrue(orderStatusTwo.order_status === "unpaid");
// Pay with new taler://pay URI, which should // Pay with new taler://pay URI, which should
// have the new session ID! // have the new session ID!
// Wallet should now automatically re-play payment. // Wallet should now automatically re-play payment.
preparePayResp = await wallet.preparePay({ preparePayResp = await wallet.preparePay({
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatusTwo.taler_pay_uri,
}); });
t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed); t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed);

View File

@ -69,6 +69,8 @@ runTest(async (t: GlobalTestState) => {
t.assertTrue(orderStatus.order_status === "unpaid"); t.assertTrue(orderStatus.order_status === "unpaid");
const talerPayUriOne = orderStatus.taler_pay_uri;
t.assertTrue(orderStatus.already_paid_order_id === undefined); t.assertTrue(orderStatus.already_paid_order_id === undefined);
let publicOrderStatusUrl = orderStatus.order_status_url; let publicOrderStatusUrl = orderStatus.order_status_url;
@ -140,16 +142,14 @@ runTest(async (t: GlobalTestState) => {
sessionId: "mysession-two", sessionId: "mysession-two",
}); });
// Should be unpaid because of a new session ID // Should be claimed (not paid!) because of a new session ID
t.assertTrue(orderStatus.order_status === "unpaid"); t.assertTrue(orderStatus.order_status === "claimed");
publicOrderStatusUrl = orderStatus.order_status_url;
// Pay with new taler://pay URI, which should // Pay with new taler://pay URI, which should
// have the new session ID! // have the new session ID!
// Wallet should now automatically re-play payment. // Wallet should now automatically re-play payment.
preparePayResp = await wallet.preparePay({ preparePayResp = await wallet.preparePay({
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: talerPayUriOne,
}); });
t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed); t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed);
@ -208,7 +208,7 @@ runTest(async (t: GlobalTestState) => {
sessionId: "mysession-four", sessionId: "mysession-four",
}); });
t.assertTrue(orderStatus.order_status === "unpaid"); t.assertTrue(orderStatus.order_status === "claimed");
// Now check if the public status of the new order is correct. // Now check if the public status of the new order is correct.

View File

@ -19,7 +19,7 @@
*/ */
import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness"; import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
import { CoreApiResponse } from "taler-wallet-core"; import { CoreApiResponse, durationFromSpec } from "taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -48,6 +48,7 @@ runTest(async (t: GlobalTestState) => {
d_ms: 3000, d_ms: 3000,
}, },
}, },
refund_delay: durationFromSpec({ minutes: 5}),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {

View File

@ -24,7 +24,7 @@ import {
MerchantPrivateApi, MerchantPrivateApi,
} from "./harness"; } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
import { TransactionType, Amounts } from "taler-wallet-core"; import { TransactionType, Amounts, durationFromSpec } from "taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -51,6 +51,7 @@ runTest(async (t: GlobalTestState) => {
amount: "TESTKUDOS:10", amount: "TESTKUDOS:10",
fulfillment_url: "taler://fulfillment-success/thx", fulfillment_url: "taler://fulfillment-success/thx",
}, },
refund_delay: durationFromSpec({ minutes: 5}),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {

View File

@ -17,6 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { durationFromSpec } from 'taler-wallet-core';
import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness"; import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
@ -45,6 +46,7 @@ runTest(async (t: GlobalTestState) => {
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
fulfillment_url: "taler://fulfillment-success/thx", fulfillment_url: "taler://fulfillment-success/thx",
}, },
refund_delay: durationFromSpec({ minutes: 5}),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {