From fd3278f4c681fb60c6f791ab6fa066f9a524478a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 17 Oct 2022 10:18:17 -0300 Subject: [PATCH] making test pass --- .../src/cta/Withdraw/index.ts | 8 +-- .../src/cta/Withdraw/state.ts | 7 +-- .../src/cta/Withdraw/test.ts | 49 ++++++++++++------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts index 075b21dc3..a3b3df8b3 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts @@ -56,11 +56,11 @@ export namespace State { error: undefined; } export interface LoadingUriError { - status: "loading-error"; + status: "uri-error"; error: HookError; } export interface LoadingInfoError { - status: "loading-info"; + status: "amount-error"; error: HookError; } @@ -87,8 +87,8 @@ export namespace State { const viewMapping: StateViewMap = { loading: Loading, - "loading-error": LoadingUriView, - "loading-info": LoadingInfoView, + "uri-error": LoadingUriView, + "amount-error": LoadingInfoView, "no-exchange": NoExchangesView, "selecting-exchange": ExchangeSelectionPage, success: SuccessView, diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index f4aea9cd6..c542d8aae 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -43,7 +43,7 @@ export function useComponentStateFromParams( if (uriInfoHook.hasError) { return { - status: "loading-error", + status: "uri-error", error: uriInfoHook, }; } @@ -110,7 +110,7 @@ export function useComponentStateFromURI( if (uriInfoHook.hasError) { return { - status: "loading-error", + status: "uri-error", error: uriInfoHook, }; } @@ -180,6 +180,7 @@ function exchangeSelectionState( const tosNeedToBeAccepted = currentExchange.tosStatus == ExchangeTosStatus.New || currentExchange.tosStatus == ExchangeTosStatus.Changed; + /** * With the exchange and amount, ask the wallet the information * about the withdrawal @@ -232,7 +233,7 @@ function exchangeSelectionState( } if (amountHook.hasError) { return { - status: "loading-info", + status: "amount-error", error: amountHook, }; } diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts index 2b0690800..977faa03a 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts @@ -21,23 +21,26 @@ import { Amounts, + ExchangeEntryStatus, ExchangeFullDetails, + ExchangeListItem, + ExchangesListResponse, ExchangeTosStatus, GetExchangeTosResult, + ManualWithdrawalDetails, } from "@gnu-taler/taler-util"; import { expect } from "chai"; import { mountHook } from "../../test-utils.js"; import { useComponentStateFromURI } from "./state.js"; -const exchanges: ExchangeFullDetails[] = [ +const exchanges: ExchangeListItem[] = [ { currency: "ARS", exchangeBaseUrl: "http://exchange.demo.taler.net", paytoUris: [], - tos: { - acceptedVersion: "v1", - currentVersion: "v1", - }, + tosStatus: ExchangeTosStatus.Accepted, + exchangeStatus: ExchangeEntryStatus.Ok, + permanent: true, auditors: [ { auditor_pub: "pubpubpubpubpub", @@ -57,7 +60,7 @@ const exchanges: ExchangeFullDetails[] = [ accounts: [], feesForType: {}, }, - } as Partial as ExchangeFullDetails, + } as Partial as ExchangeListItem, ]; describe("Withdraw CTA states", () => { @@ -76,7 +79,9 @@ describe("Withdraw CTA states", () => { }, { listExchanges: async () => ({ exchanges }), - getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({ + getWithdrawalDetailsForAmount: async ({ + talerWithdrawUri, + }: any) => ({ amount: "ARS:2", possibleExchanges: exchanges, }), @@ -94,7 +99,7 @@ describe("Withdraw CTA states", () => { { const { status, error } = getLastResultOrThrow(); - if (status != "loading-error") expect.fail(); + if (status != "uri-error") expect.fail(); if (!error) expect.fail(); if (!error.hasError) expect.fail(); if (error.operational) expect.fail(); @@ -165,6 +170,12 @@ describe("Withdraw CTA states", () => { possibleExchanges: exchanges, defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl, }), + getWithdrawalDetailsForAmount: + async (): Promise => + ({ + amountRaw: "ARS:2", + amountEffective: "ARS:2", + } as any), getExchangeTos: async (): Promise => ({ contentType: "text", content: "just accept", @@ -210,24 +221,18 @@ describe("Withdraw CTA states", () => { }); it("should be accept the tos before withdraw", async () => { - const listExchangesResponse = { + const listExchangesResponse: ExchangesListResponse = { exchanges: exchanges.map((e) => ({ ...e, - tos: { - ...e.tos, - acceptedVersion: undefined, - }, - })) as ExchangeFullDetails[], + tosStatus: ExchangeTosStatus.New, + })), }; function updateAcceptedVersionToCurrentVersion(): void { listExchangesResponse.exchanges = listExchangesResponse.exchanges.map( (e) => ({ ...e, - tos: { - ...e.tos, - acceptedVersion: e.tos.currentVersion, - }, + tosStatus: ExchangeTosStatus.Accepted, }), ); } @@ -245,12 +250,18 @@ describe("Withdraw CTA states", () => { }, }, { - listExchanges: async () => ({ exchanges }), + listExchanges: async () => listExchangesResponse, getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({ amount: "ARS:2", possibleExchanges: exchanges, defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl, }), + getWithdrawalDetailsForAmount: + async (): Promise => + ({ + amountRaw: "ARS:2", + amountEffective: "ARS:2", + } as any), getExchangeTos: async (): Promise => ({ contentType: "text", content: "just accept",