fix broken integration tests due to merchant API changes
This commit is contained in:
parent
e259d109ef
commit
ca343e4e00
@ -107,6 +107,12 @@ export const codecForCheckPaymentUnpaidResponse = (): Codec<
|
||||
.property("already_paid_order_id", codecOptional(codecForString()))
|
||||
.build("CheckPaymentPaidResponse");
|
||||
|
||||
export const codecForCheckPaymentClaimedResponse = (): Codec<CheckPaymentClaimedResponse> =>
|
||||
buildCodecForObject<CheckPaymentClaimedResponse>()
|
||||
.property("order_status", codecForConstString("claimed"))
|
||||
.property("contract_terms", codecForContractTerms())
|
||||
.build("CheckPaymentClaimedResponse");
|
||||
|
||||
export const codecForMerchantOrderPrivateStatusResponse = (): Codec<
|
||||
MerchantOrderPrivateStatusResponse
|
||||
> =>
|
||||
@ -114,11 +120,20 @@ export const codecForMerchantOrderPrivateStatusResponse = (): Codec<
|
||||
.discriminateOn("order_status")
|
||||
.alternative("paid", codecForCheckPaymentPaidResponse())
|
||||
.alternative("unpaid", codecForCheckPaymentUnpaidResponse())
|
||||
.alternative("claimed", codecForCheckPaymentClaimedResponse())
|
||||
.build("MerchantOrderPrivateStatusResponse");
|
||||
|
||||
export type MerchantOrderPrivateStatusResponse =
|
||||
| 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 {
|
||||
// did the customer pay for this contract
|
||||
@ -164,6 +179,7 @@ export interface CheckPaymentPaidResponse {
|
||||
order_status_url: string;
|
||||
}
|
||||
|
||||
|
||||
export interface CheckPaymentUnpaidResponse {
|
||||
order_status: "unpaid";
|
||||
|
||||
|
@ -24,11 +24,13 @@ import {
|
||||
WalletCli,
|
||||
} from "./harness";
|
||||
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
|
||||
import { PreparePayResultType, TalerErrorCode } from "taler-wallet-core";
|
||||
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) => {
|
||||
// Set up test environment
|
||||
@ -55,6 +57,7 @@ runTest(async (t: GlobalTestState) => {
|
||||
let orderStatusBefore = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
orderId: orderResp.order_id,
|
||||
});
|
||||
t.assertTrue(orderStatusBefore.order_status === "unpaid");
|
||||
let statusUrlBefore = new URL(orderStatusBefore.order_status_url);
|
||||
|
||||
// Make wallet claim the unpaid order.
|
||||
@ -68,17 +71,7 @@ runTest(async (t: GlobalTestState) => {
|
||||
let orderStatusAfter = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
orderId: orderResp.order_id,
|
||||
});
|
||||
let statusUrlAfter = new URL(orderStatusAfter.order_status_url)
|
||||
|
||||
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)
|
||||
)
|
||||
t.assertTrue(orderStatusAfter.order_status === "claimed");
|
||||
|
||||
await t.shutdown();
|
||||
});
|
||||
|
@ -32,7 +32,7 @@ import {
|
||||
withdrawViaBank,
|
||||
SimpleTestEnvironment,
|
||||
} from "./helpers";
|
||||
import { PreparePayResultType, URL } from "taler-wallet-core";
|
||||
import { durationFromSpec, PreparePayResultType, URL } from "taler-wallet-core";
|
||||
import axios from "axios";
|
||||
|
||||
async function testRefundApiWithFulfillmentUrl(
|
||||
@ -53,6 +53,7 @@ async function testRefundApiWithFulfillmentUrl(
|
||||
amount: "TESTKUDOS:5",
|
||||
fulfillment_url: "https://example.com/fulfillment",
|
||||
},
|
||||
refund_delay: durationFromSpec({ minutes: 5 }),
|
||||
});
|
||||
|
||||
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
@ -162,6 +163,7 @@ async function testRefundApiWithFulfillmentMessage(
|
||||
amount: "TESTKUDOS:5",
|
||||
fulfillment_message: "Thank you for buying foobar",
|
||||
},
|
||||
refund_delay: durationFromSpec({ minutes: 5 }),
|
||||
});
|
||||
|
||||
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
|
@ -19,7 +19,6 @@
|
||||
*/
|
||||
import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness";
|
||||
import {
|
||||
createSimpleTestkudosEnvironment,
|
||||
withdrawViaBank,
|
||||
createFaultInjectedMerchantTestkudosEnvironment,
|
||||
} from "./helpers";
|
||||
@ -33,7 +32,12 @@ import axios from "axios";
|
||||
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) => {
|
||||
// Set up test environment
|
||||
@ -146,10 +150,10 @@ runTest(async (t: GlobalTestState) => {
|
||||
sessionId: "mysession-two",
|
||||
});
|
||||
|
||||
// Should be unpaid because of a new session ID
|
||||
t.assertTrue(orderStatus.order_status === "unpaid");
|
||||
console.log("order status under mysession-two:", JSON.stringify(orderStatus, undefined, 2));
|
||||
|
||||
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 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
|
||||
// have the new session ID!
|
||||
// Wallet should now automatically re-play payment.
|
||||
preparePayResp = await wallet.preparePay({
|
||||
talerPayUri: orderStatus.taler_pay_uri,
|
||||
talerPayUri: orderStatusTwo.taler_pay_uri,
|
||||
});
|
||||
|
||||
t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed);
|
||||
|
@ -69,6 +69,8 @@ runTest(async (t: GlobalTestState) => {
|
||||
|
||||
t.assertTrue(orderStatus.order_status === "unpaid");
|
||||
|
||||
const talerPayUriOne = orderStatus.taler_pay_uri;
|
||||
|
||||
t.assertTrue(orderStatus.already_paid_order_id === undefined);
|
||||
let publicOrderStatusUrl = orderStatus.order_status_url;
|
||||
|
||||
@ -140,16 +142,14 @@ runTest(async (t: GlobalTestState) => {
|
||||
sessionId: "mysession-two",
|
||||
});
|
||||
|
||||
// Should be unpaid because of a new session ID
|
||||
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");
|
||||
|
||||
// Pay with new taler://pay URI, which should
|
||||
// have the new session ID!
|
||||
// Wallet should now automatically re-play payment.
|
||||
preparePayResp = await wallet.preparePay({
|
||||
talerPayUri: orderStatus.taler_pay_uri,
|
||||
talerPayUri: talerPayUriOne,
|
||||
});
|
||||
|
||||
t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed);
|
||||
@ -208,7 +208,7 @@ runTest(async (t: GlobalTestState) => {
|
||||
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.
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
*/
|
||||
import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness";
|
||||
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.
|
||||
@ -48,6 +48,7 @@ runTest(async (t: GlobalTestState) => {
|
||||
d_ms: 3000,
|
||||
},
|
||||
},
|
||||
refund_delay: durationFromSpec({ minutes: 5}),
|
||||
});
|
||||
|
||||
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
|
@ -24,7 +24,7 @@ import {
|
||||
MerchantPrivateApi,
|
||||
} from "./harness";
|
||||
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.
|
||||
@ -51,6 +51,7 @@ runTest(async (t: GlobalTestState) => {
|
||||
amount: "TESTKUDOS:10",
|
||||
fulfillment_url: "taler://fulfillment-success/thx",
|
||||
},
|
||||
refund_delay: durationFromSpec({ minutes: 5}),
|
||||
});
|
||||
|
||||
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
|
@ -17,6 +17,7 @@
|
||||
/**
|
||||
* Imports.
|
||||
*/
|
||||
import { durationFromSpec } from 'taler-wallet-core';
|
||||
import { runTest, GlobalTestState, MerchantPrivateApi } from "./harness";
|
||||
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
|
||||
|
||||
@ -45,6 +46,7 @@ runTest(async (t: GlobalTestState) => {
|
||||
amount: "TESTKUDOS:5",
|
||||
fulfillment_url: "taler://fulfillment-success/thx",
|
||||
},
|
||||
refund_delay: durationFromSpec({ minutes: 5}),
|
||||
});
|
||||
|
||||
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, {
|
||||
|
Loading…
Reference in New Issue
Block a user