making test pass
This commit is contained in:
parent
e5e469575b
commit
fd3278f4c6
@ -56,11 +56,11 @@ export namespace State {
|
|||||||
error: undefined;
|
error: undefined;
|
||||||
}
|
}
|
||||||
export interface LoadingUriError {
|
export interface LoadingUriError {
|
||||||
status: "loading-error";
|
status: "uri-error";
|
||||||
error: HookError;
|
error: HookError;
|
||||||
}
|
}
|
||||||
export interface LoadingInfoError {
|
export interface LoadingInfoError {
|
||||||
status: "loading-info";
|
status: "amount-error";
|
||||||
error: HookError;
|
error: HookError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ export namespace State {
|
|||||||
|
|
||||||
const viewMapping: StateViewMap<State> = {
|
const viewMapping: StateViewMap<State> = {
|
||||||
loading: Loading,
|
loading: Loading,
|
||||||
"loading-error": LoadingUriView,
|
"uri-error": LoadingUriView,
|
||||||
"loading-info": LoadingInfoView,
|
"amount-error": LoadingInfoView,
|
||||||
"no-exchange": NoExchangesView,
|
"no-exchange": NoExchangesView,
|
||||||
"selecting-exchange": ExchangeSelectionPage,
|
"selecting-exchange": ExchangeSelectionPage,
|
||||||
success: SuccessView,
|
success: SuccessView,
|
||||||
|
@ -43,7 +43,7 @@ export function useComponentStateFromParams(
|
|||||||
|
|
||||||
if (uriInfoHook.hasError) {
|
if (uriInfoHook.hasError) {
|
||||||
return {
|
return {
|
||||||
status: "loading-error",
|
status: "uri-error",
|
||||||
error: uriInfoHook,
|
error: uriInfoHook,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ export function useComponentStateFromURI(
|
|||||||
|
|
||||||
if (uriInfoHook.hasError) {
|
if (uriInfoHook.hasError) {
|
||||||
return {
|
return {
|
||||||
status: "loading-error",
|
status: "uri-error",
|
||||||
error: uriInfoHook,
|
error: uriInfoHook,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -180,6 +180,7 @@ function exchangeSelectionState(
|
|||||||
const tosNeedToBeAccepted =
|
const tosNeedToBeAccepted =
|
||||||
currentExchange.tosStatus == ExchangeTosStatus.New ||
|
currentExchange.tosStatus == ExchangeTosStatus.New ||
|
||||||
currentExchange.tosStatus == ExchangeTosStatus.Changed;
|
currentExchange.tosStatus == ExchangeTosStatus.Changed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* With the exchange and amount, ask the wallet the information
|
* With the exchange and amount, ask the wallet the information
|
||||||
* about the withdrawal
|
* about the withdrawal
|
||||||
@ -232,7 +233,7 @@ function exchangeSelectionState(
|
|||||||
}
|
}
|
||||||
if (amountHook.hasError) {
|
if (amountHook.hasError) {
|
||||||
return {
|
return {
|
||||||
status: "loading-info",
|
status: "amount-error",
|
||||||
error: amountHook,
|
error: amountHook,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -21,23 +21,26 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Amounts,
|
Amounts,
|
||||||
|
ExchangeEntryStatus,
|
||||||
ExchangeFullDetails,
|
ExchangeFullDetails,
|
||||||
|
ExchangeListItem,
|
||||||
|
ExchangesListResponse,
|
||||||
ExchangeTosStatus,
|
ExchangeTosStatus,
|
||||||
GetExchangeTosResult,
|
GetExchangeTosResult,
|
||||||
|
ManualWithdrawalDetails,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { mountHook } from "../../test-utils.js";
|
import { mountHook } from "../../test-utils.js";
|
||||||
import { useComponentStateFromURI } from "./state.js";
|
import { useComponentStateFromURI } from "./state.js";
|
||||||
|
|
||||||
const exchanges: ExchangeFullDetails[] = [
|
const exchanges: ExchangeListItem[] = [
|
||||||
{
|
{
|
||||||
currency: "ARS",
|
currency: "ARS",
|
||||||
exchangeBaseUrl: "http://exchange.demo.taler.net",
|
exchangeBaseUrl: "http://exchange.demo.taler.net",
|
||||||
paytoUris: [],
|
paytoUris: [],
|
||||||
tos: {
|
tosStatus: ExchangeTosStatus.Accepted,
|
||||||
acceptedVersion: "v1",
|
exchangeStatus: ExchangeEntryStatus.Ok,
|
||||||
currentVersion: "v1",
|
permanent: true,
|
||||||
},
|
|
||||||
auditors: [
|
auditors: [
|
||||||
{
|
{
|
||||||
auditor_pub: "pubpubpubpubpub",
|
auditor_pub: "pubpubpubpubpub",
|
||||||
@ -57,7 +60,7 @@ const exchanges: ExchangeFullDetails[] = [
|
|||||||
accounts: [],
|
accounts: [],
|
||||||
feesForType: {},
|
feesForType: {},
|
||||||
},
|
},
|
||||||
} as Partial<ExchangeFullDetails> as ExchangeFullDetails,
|
} as Partial<ExchangeListItem> as ExchangeListItem,
|
||||||
];
|
];
|
||||||
|
|
||||||
describe("Withdraw CTA states", () => {
|
describe("Withdraw CTA states", () => {
|
||||||
@ -76,7 +79,9 @@ describe("Withdraw CTA states", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
listExchanges: async () => ({ exchanges }),
|
listExchanges: async () => ({ exchanges }),
|
||||||
getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({
|
getWithdrawalDetailsForAmount: async ({
|
||||||
|
talerWithdrawUri,
|
||||||
|
}: any) => ({
|
||||||
amount: "ARS:2",
|
amount: "ARS:2",
|
||||||
possibleExchanges: exchanges,
|
possibleExchanges: exchanges,
|
||||||
}),
|
}),
|
||||||
@ -94,7 +99,7 @@ describe("Withdraw CTA states", () => {
|
|||||||
{
|
{
|
||||||
const { status, error } = getLastResultOrThrow();
|
const { status, error } = getLastResultOrThrow();
|
||||||
|
|
||||||
if (status != "loading-error") expect.fail();
|
if (status != "uri-error") expect.fail();
|
||||||
if (!error) expect.fail();
|
if (!error) expect.fail();
|
||||||
if (!error.hasError) expect.fail();
|
if (!error.hasError) expect.fail();
|
||||||
if (error.operational) expect.fail();
|
if (error.operational) expect.fail();
|
||||||
@ -165,6 +170,12 @@ describe("Withdraw CTA states", () => {
|
|||||||
possibleExchanges: exchanges,
|
possibleExchanges: exchanges,
|
||||||
defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl,
|
defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl,
|
||||||
}),
|
}),
|
||||||
|
getWithdrawalDetailsForAmount:
|
||||||
|
async (): Promise<ManualWithdrawalDetails> =>
|
||||||
|
({
|
||||||
|
amountRaw: "ARS:2",
|
||||||
|
amountEffective: "ARS:2",
|
||||||
|
} as any),
|
||||||
getExchangeTos: async (): Promise<GetExchangeTosResult> => ({
|
getExchangeTos: async (): Promise<GetExchangeTosResult> => ({
|
||||||
contentType: "text",
|
contentType: "text",
|
||||||
content: "just accept",
|
content: "just accept",
|
||||||
@ -210,24 +221,18 @@ describe("Withdraw CTA states", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should be accept the tos before withdraw", async () => {
|
it("should be accept the tos before withdraw", async () => {
|
||||||
const listExchangesResponse = {
|
const listExchangesResponse: ExchangesListResponse = {
|
||||||
exchanges: exchanges.map((e) => ({
|
exchanges: exchanges.map((e) => ({
|
||||||
...e,
|
...e,
|
||||||
tos: {
|
tosStatus: ExchangeTosStatus.New,
|
||||||
...e.tos,
|
})),
|
||||||
acceptedVersion: undefined,
|
|
||||||
},
|
|
||||||
})) as ExchangeFullDetails[],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateAcceptedVersionToCurrentVersion(): void {
|
function updateAcceptedVersionToCurrentVersion(): void {
|
||||||
listExchangesResponse.exchanges = listExchangesResponse.exchanges.map(
|
listExchangesResponse.exchanges = listExchangesResponse.exchanges.map(
|
||||||
(e) => ({
|
(e) => ({
|
||||||
...e,
|
...e,
|
||||||
tos: {
|
tosStatus: ExchangeTosStatus.Accepted,
|
||||||
...e.tos,
|
|
||||||
acceptedVersion: e.tos.currentVersion,
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -245,12 +250,18 @@ describe("Withdraw CTA states", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
listExchanges: async () => ({ exchanges }),
|
listExchanges: async () => listExchangesResponse,
|
||||||
getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({
|
getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({
|
||||||
amount: "ARS:2",
|
amount: "ARS:2",
|
||||||
possibleExchanges: exchanges,
|
possibleExchanges: exchanges,
|
||||||
defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl,
|
defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl,
|
||||||
}),
|
}),
|
||||||
|
getWithdrawalDetailsForAmount:
|
||||||
|
async (): Promise<ManualWithdrawalDetails> =>
|
||||||
|
({
|
||||||
|
amountRaw: "ARS:2",
|
||||||
|
amountEffective: "ARS:2",
|
||||||
|
} as any),
|
||||||
getExchangeTos: async (): Promise<GetExchangeTosResult> => ({
|
getExchangeTos: async (): Promise<GetExchangeTosResult> => ({
|
||||||
contentType: "text",
|
contentType: "text",
|
||||||
content: "just accept",
|
content: "just accept",
|
||||||
|
Loading…
Reference in New Issue
Block a user