diff options
author | Sebastian <sebasjm@gmail.com> | 2022-04-12 00:41:16 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-04-12 00:41:16 -0300 |
commit | afecab8000fa59475fe02a402176789e360651ba (patch) | |
tree | 44491f686d50b03f448c942ac63dcc310c29be43 /packages/taler-wallet-webextension/src/cta/Withdraw.test.ts | |
parent | d34eeb5c8c90c7143922b303cf3a7dbc2357246c (diff) |
accept tos test case
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw.test.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Withdraw.test.ts | 155 |
1 files changed, 154 insertions, 1 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts index e26e86445..2a297c4bb 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts @@ -19,7 +19,8 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { ExchangeListItem } from "@gnu-taler/taler-util"; +import { Amounts, ExchangeListItem, GetExchangeTosResult } from "@gnu-taler/taler-util"; +import { ExchangeWithdrawDetails } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; import { mountHook } from "../test-utils.js"; import { useComponentState } from "./Withdraw.js"; @@ -93,4 +94,156 @@ describe("Withdraw CTA states", () => { await assertNoPendingUpdate() }); + it("should be able to withdraw if tos are ok", async () => { + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => + useComponentState('taler-withdraw://', { + listExchanges: async () => ({ exchanges }), + getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({ + amount: 'ARS:2', + possibleExchanges: exchanges, + }), + getExchangeWithdrawalInfo: async (): Promise<ExchangeWithdrawDetails> => ({ + withdrawalAmountRaw: 'ARS:5', + withdrawalAmountEffective: 'ARS:5', + } as any), + getExchangeTos: async (): Promise<GetExchangeTosResult> => ({ + contentType: 'text', + content: 'just accept', + acceptedEtag: 'v1', + currentEtag: 'v1' + }) + } as any), + ); + + { + const { status, hook } = getLastResultOrThrow() + expect(status).equals('loading-uri') + expect(hook).undefined; + } + + await waitNextUpdate() + + { + const { status, hook } = getLastResultOrThrow() + + expect(status).equals('loading-info') + + expect(hook).undefined; + } + + await waitNextUpdate() + + { + const state = getLastResultOrThrow() + expect(state.status).equals("success") + if (state.status !== "success") return; + + expect(state.exchange.isDirty).false + expect(state.exchange.value).equal("http://exchange.demo.taler.net") + expect(state.exchange.list).deep.equal({ + "http://exchange.demo.taler.net": "http://exchange.demo.taler.net" + }) + expect(state.showExchangeSelection).false + + expect(state.toBeReceived).deep.equal(Amounts.parseOrThrow("ARS:2")) + expect(state.withdrawalFee).deep.equal(Amounts.parseOrThrow("ARS:0")) + expect(state.chosenAmount).deep.equal(Amounts.parseOrThrow("ARS:2")) + + expect(state.doWithdrawal.disabled).false + expect(state.mustAcceptFirst).false + + } + + await assertNoPendingUpdate() + }); + + it("should be accept the tos before withdraw", async () => { + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => + useComponentState('taler-withdraw://', { + listExchanges: async () => ({ exchanges }), + getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({ + amount: 'ARS:2', + possibleExchanges: exchanges, + }), + getExchangeWithdrawalInfo: async (): Promise<ExchangeWithdrawDetails> => ({ + withdrawalAmountRaw: 'ARS:5', + withdrawalAmountEffective: 'ARS:5', + } as any), + getExchangeTos: async (): Promise<GetExchangeTosResult> => ({ + contentType: 'text', + content: 'just accept', + acceptedEtag: 'v1', + currentEtag: 'v2' + }), + setExchangeTosAccepted: async () => ({}) + } as any), + ); + + { + const { status, hook } = getLastResultOrThrow() + expect(status).equals('loading-uri') + expect(hook).undefined; + } + + await waitNextUpdate() + + { + const { status, hook } = getLastResultOrThrow() + + expect(status).equals('loading-info') + + expect(hook).undefined; + } + + await waitNextUpdate() + + { + const state = getLastResultOrThrow() + expect(state.status).equals("success") + if (state.status !== "success") return; + + expect(state.exchange.isDirty).false + expect(state.exchange.value).equal("http://exchange.demo.taler.net") + expect(state.exchange.list).deep.equal({ + "http://exchange.demo.taler.net": "http://exchange.demo.taler.net" + }) + expect(state.showExchangeSelection).false + + expect(state.toBeReceived).deep.equal(Amounts.parseOrThrow("ARS:2")) + expect(state.withdrawalFee).deep.equal(Amounts.parseOrThrow("ARS:0")) + expect(state.chosenAmount).deep.equal(Amounts.parseOrThrow("ARS:2")) + + expect(state.doWithdrawal.disabled).true + expect(state.mustAcceptFirst).true + + // accept TOS + state.tosProps?.onAccept(true) + } + + await waitNextUpdate() + + { + const state = getLastResultOrThrow() + expect(state.status).equals("success") + if (state.status !== "success") return; + + expect(state.exchange.isDirty).false + expect(state.exchange.value).equal("http://exchange.demo.taler.net") + expect(state.exchange.list).deep.equal({ + "http://exchange.demo.taler.net": "http://exchange.demo.taler.net" + }) + expect(state.showExchangeSelection).false + + expect(state.toBeReceived).deep.equal(Amounts.parseOrThrow("ARS:2")) + expect(state.withdrawalFee).deep.equal(Amounts.parseOrThrow("ARS:0")) + expect(state.chosenAmount).deep.equal(Amounts.parseOrThrow("ARS:2")) + + expect(state.doWithdrawal.disabled).false + expect(state.mustAcceptFirst).true + + } + + await assertNoPendingUpdate() + }); + });
\ No newline at end of file |