diff options
author | Sebastian <sebasjm@gmail.com> | 2022-06-06 00:09:25 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-06-06 00:09:25 -0300 |
commit | fb6aff76d2152d95caa2ba6cb0d91cb01e0687fe (patch) | |
tree | 2dc9b0a4935f60ba7229fd81332ec4a41ad4698c /packages/taler-wallet-webextension/src/cta | |
parent | 912813fd09ee2f757e4d6d509a911159b46153a7 (diff) | |
download | wallet-core-fb6aff76d2152d95caa2ba6cb0d91cb01e0687fe.tar.xz |
prettier
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
6 files changed, 656 insertions, 587 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Deposit.test.ts b/packages/taler-wallet-webextension/src/cta/Deposit.test.ts index 16e7961cc..e4c909f9b 100644 --- a/packages/taler-wallet-webextension/src/cta/Deposit.test.ts +++ b/packages/taler-wallet-webextension/src/cta/Deposit.test.ts @@ -26,58 +26,61 @@ import { useComponentState } from "./Deposit.jsx"; describe("Deposit CTA states", () => { it("should tell the user that the URI is missing", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(undefined, undefined, { - prepareRefund: async () => ({}), - applyRefund: async () => ({}), - onUpdateNotification: async () => ({}) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(undefined, undefined, { + prepareRefund: async () => ({}), + applyRefund: async () => ({}), + onUpdateNotification: async () => ({}), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const { status, hook } = getLastResultOrThrow() + const { status, hook } = getLastResultOrThrow(); - expect(status).equals('loading') + expect(status).equals("loading"); if (!hook) expect.fail(); if (!hook.hasError) expect.fail(); if (hook.operational) expect.fail(); expect(hook.message).eq("ERROR_NO-URI-FOR-DEPOSIT"); } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should be ready after loading", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState("payto://refund/asdasdas", "EUR:1", { - prepareDeposit: async () => ({ - effectiveDepositAmount: Amounts.parseOrThrow("EUR:1"), - totalDepositCost: Amounts.parseOrThrow("EUR:1.2") - } as PrepareDepositResponse as any), - createDepositGroup: async () => ({}), - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("payto://refund/asdasdas", "EUR:1", { + prepareDeposit: async () => + ({ + effectiveDepositAmount: Amounts.parseOrThrow("EUR:1"), + totalDepositCost: Amounts.parseOrThrow("EUR:1.2"), + } as PrepareDepositResponse as any), + createDepositGroup: async () => ({}), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== 'ready') expect.fail(); + if (state.status !== "ready") expect.fail(); if (state.hook) expect.fail(); expect(state.confirm.onClick).not.undefined; expect(state.cost).deep.eq(Amounts.parseOrThrow("EUR:1.2")); @@ -85,8 +88,6 @@ describe("Deposit CTA states", () => { expect(state.effective).deep.eq(Amounts.parseOrThrow("EUR:1")); } - await assertNoPendingUpdate() - + await assertNoPendingUpdate(); }); - -});
\ No newline at end of file +}); diff --git a/packages/taler-wallet-webextension/src/cta/Pay.test.ts b/packages/taler-wallet-webextension/src/cta/Pay.test.ts index 7e9d5338f..a45ebd3a2 100644 --- a/packages/taler-wallet-webextension/src/cta/Pay.test.ts +++ b/packages/taler-wallet-webextension/src/cta/Pay.test.ts @@ -19,7 +19,16 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { AmountJson, Amounts, BalancesResponse, ConfirmPayResult, ConfirmPayResultType, NotificationType, PreparePayResult, PreparePayResultType } from "@gnu-taler/taler-util"; +import { + AmountJson, + Amounts, + BalancesResponse, + ConfirmPayResult, + ConfirmPayResultType, + NotificationType, + PreparePayResult, + PreparePayResultType, +} from "@gnu-taler/taler-util"; import { expect } from "chai"; import { mountHook } from "../test-utils.js"; import * as wxApi from "../wxApi.js"; @@ -29,8 +38,8 @@ const nullFunction: any = () => null; type VoidFunction = () => void; type Subs = { - [key in NotificationType]?: VoidFunction -} + [key in NotificationType]?: VoidFunction; +}; export class SubsHandler { private subs: Subs = {}; @@ -39,311 +48,340 @@ export class SubsHandler { this.saveSubscription = this.saveSubscription.bind(this); } - saveSubscription(messageTypes: NotificationType[], callback: VoidFunction): VoidFunction { - messageTypes.forEach(m => { + saveSubscription( + messageTypes: NotificationType[], + callback: VoidFunction, + ): VoidFunction { + messageTypes.forEach((m) => { this.subs[m] = callback; - }) + }); return nullFunction; } notifyEvent(event: NotificationType): void { const cb = this.subs[event]; - if (cb === undefined) expect.fail(`Expected to have a subscription for ${event}`); - cb() + if (cb === undefined) + expect.fail(`Expected to have a subscription for ${event}`); + cb(); } } - describe("Pay CTA states", () => { it("should tell the user that the URI is missing", async () => { - - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(undefined, { - onUpdateNotification: nullFunction, - } as Partial<typeof wxApi> as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(undefined, { + onUpdateNotification: nullFunction, + } as Partial<typeof wxApi> as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const { status, hook } = getLastResultOrThrow() + const { status, hook } = getLastResultOrThrow(); - expect(status).equals('loading') - if (hook === undefined) expect.fail() + expect(status).equals("loading"); + if (hook === undefined) expect.fail(); expect(hook.hasError).true; expect(hook.operational).false; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should response with no balance", async () => { - - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState('taller://pay', { - onUpdateNotification: nullFunction, - preparePay: async () => ({ - amountRaw: 'USD:10', - status: PreparePayResultType.InsufficientBalance, - } as Partial<PreparePayResult>), - getBalance: async () => ({ - balances: [] - } as Partial<BalancesResponse>), - } as Partial<typeof wxApi> as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taller://pay", { + onUpdateNotification: nullFunction, + preparePay: async () => + ({ + amountRaw: "USD:10", + status: PreparePayResultType.InsufficientBalance, + } as Partial<PreparePayResult>), + getBalance: async () => + ({ + balances: [], + } as Partial<BalancesResponse>), + } as Partial<typeof wxApi> as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); expect(r.balance).undefined; - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:10')) + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:10")); expect(r.payHandler.onClick).undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should not be able to pay if there is no enough balance", async () => { - - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState('taller://pay', { - onUpdateNotification: nullFunction, - preparePay: async () => ({ - amountRaw: 'USD:10', - status: PreparePayResultType.InsufficientBalance, - } as Partial<PreparePayResult>), - getBalance: async () => ({ - balances: [{ - available: 'USD:5' - }] - } as Partial<BalancesResponse>), - } as Partial<typeof wxApi> as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taller://pay", { + onUpdateNotification: nullFunction, + preparePay: async () => + ({ + amountRaw: "USD:10", + status: PreparePayResultType.InsufficientBalance, + } as Partial<PreparePayResult>), + getBalance: async () => + ({ + balances: [ + { + available: "USD:5", + }, + ], + } as Partial<BalancesResponse>), + } as Partial<typeof wxApi> as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:5')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:10')) + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:5")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:10")); expect(r.payHandler.onClick).undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should be able to pay (without fee)", async () => { - - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState('taller://pay', { - onUpdateNotification: nullFunction, - preparePay: async () => ({ - amountRaw: 'USD:10', - amountEffective: 'USD:10', - status: PreparePayResultType.PaymentPossible, - } as Partial<PreparePayResult>), - getBalance: async () => ({ - balances: [{ - available: 'USD:15' - }] - } as Partial<BalancesResponse>), - } as Partial<typeof wxApi> as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taller://pay", { + onUpdateNotification: nullFunction, + preparePay: async () => + ({ + amountRaw: "USD:10", + amountEffective: "USD:10", + status: PreparePayResultType.PaymentPossible, + } as Partial<PreparePayResult>), + getBalance: async () => + ({ + balances: [ + { + available: "USD:15", + }, + ], + } as Partial<BalancesResponse>), + } as Partial<typeof wxApi> as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:15')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:10')) - expect(r.totalFees).deep.equal(Amounts.parseOrThrow('USD:0')) + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:10")); + expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:0")); expect(r.payHandler.onClick).not.undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should be able to pay (with fee)", async () => { - - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState('taller://pay', { - onUpdateNotification: nullFunction, - preparePay: async () => ({ - amountRaw: 'USD:9', - amountEffective: 'USD:10', - status: PreparePayResultType.PaymentPossible, - } as Partial<PreparePayResult>), - getBalance: async () => ({ - balances: [{ - available: 'USD:15' - }] - } as Partial<BalancesResponse>), - } as Partial<typeof wxApi> as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taller://pay", { + onUpdateNotification: nullFunction, + preparePay: async () => + ({ + amountRaw: "USD:9", + amountEffective: "USD:10", + status: PreparePayResultType.PaymentPossible, + } as Partial<PreparePayResult>), + getBalance: async () => + ({ + balances: [ + { + available: "USD:15", + }, + ], + } as Partial<BalancesResponse>), + } as Partial<typeof wxApi> as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:15')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:9')) - expect(r.totalFees).deep.equal(Amounts.parseOrThrow('USD:1')) + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); + expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); expect(r.payHandler.onClick).not.undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should get confirmation done after pay successfully", async () => { - - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState('taller://pay', { - onUpdateNotification: nullFunction, - preparePay: async () => ({ - amountRaw: 'USD:9', - amountEffective: 'USD:10', - status: PreparePayResultType.PaymentPossible, - } as Partial<PreparePayResult>), - getBalance: async () => ({ - balances: [{ - available: 'USD:15' - }] - } as Partial<BalancesResponse>), - confirmPay: async () => ({ - type: ConfirmPayResultType.Done, - contractTerms: {} - } as Partial<ConfirmPayResult>), - } as Partial<typeof wxApi> as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taller://pay", { + onUpdateNotification: nullFunction, + preparePay: async () => + ({ + amountRaw: "USD:9", + amountEffective: "USD:10", + status: PreparePayResultType.PaymentPossible, + } as Partial<PreparePayResult>), + getBalance: async () => + ({ + balances: [ + { + available: "USD:15", + }, + ], + } as Partial<BalancesResponse>), + confirmPay: async () => + ({ + type: ConfirmPayResultType.Done, + contractTerms: {}, + } as Partial<ConfirmPayResult>), + } as Partial<typeof wxApi> as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:15')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:9')) - expect(r.totalFees).deep.equal(Amounts.parseOrThrow('USD:1')) + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); + expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); if (r.payHandler.onClick === undefined) expect.fail(); - r.payHandler.onClick() + r.payHandler.onClick(); } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'confirmed') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:15')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:9')) - expect(r.totalFees).deep.equal(Amounts.parseOrThrow('USD:1')) + const r = getLastResultOrThrow(); + if (r.status !== "confirmed") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); + expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); if (r.payResult.type !== ConfirmPayResultType.Done) expect.fail(); expect(r.payResult.contractTerms).not.undefined; expect(r.payHandler.onClick).undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should not stay in ready state after pay with error", async () => { - - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState('taller://pay', { - onUpdateNotification: nullFunction, - preparePay: async () => ({ - amountRaw: 'USD:9', - amountEffective: 'USD:10', - status: PreparePayResultType.PaymentPossible, - } as Partial<PreparePayResult>), - getBalance: async () => ({ - balances: [{ - available: 'USD:15' - }] - } as Partial<BalancesResponse>), - confirmPay: async () => ({ - type: ConfirmPayResultType.Pending, - lastError: { code: 1 }, - } as Partial<ConfirmPayResult>), - } as Partial<typeof wxApi> as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taller://pay", { + onUpdateNotification: nullFunction, + preparePay: async () => + ({ + amountRaw: "USD:9", + amountEffective: "USD:10", + status: PreparePayResultType.PaymentPossible, + } as Partial<PreparePayResult>), + getBalance: async () => + ({ + balances: [ + { + available: "USD:15", + }, + ], + } as Partial<BalancesResponse>), + confirmPay: async () => + ({ + type: ConfirmPayResultType.Pending, + lastError: { code: 1 }, + } as Partial<ConfirmPayResult>), + } as Partial<typeof wxApi> as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:15')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:9')) - expect(r.totalFees).deep.equal(Amounts.parseOrThrow('USD:1')) + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); + expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); if (r.payHandler.onClick === undefined) expect.fail(); - r.payHandler.onClick() + r.payHandler.onClick(); } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:15')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:9')) - expect(r.totalFees).deep.equal(Amounts.parseOrThrow('USD:1')) + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); + expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); expect(r.payHandler.onClick).undefined; if (r.payHandler.error === undefined) expect.fail(); //FIXME: error message here is bad - expect(r.payHandler.error.errorDetail.hint).eq("could not confirm payment") + expect(r.payHandler.error.errorDetail.hint).eq( + "could not confirm payment", + ); expect(r.payHandler.error.errorDetail.payResult).deep.equal({ type: ConfirmPayResultType.Pending, - lastError: { code: 1 } - }) + lastError: { code: 1 }, + }); } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should update balance if a coins is withdraw", async () => { @@ -351,40 +389,45 @@ describe("Pay CTA states", () => { let availableBalance = Amounts.parseOrThrow("USD:10"); function notifyCoinWithdrawn(newAmount: AmountJson): void { - availableBalance = Amounts.add(availableBalance, newAmount).amount - subscriptions.notifyEvent(NotificationType.CoinWithdrawn) + availableBalance = Amounts.add(availableBalance, newAmount).amount; + subscriptions.notifyEvent(NotificationType.CoinWithdrawn); } - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState('taller://pay', { - onUpdateNotification: subscriptions.saveSubscription, - preparePay: async () => ({ - amountRaw: 'USD:9', - amountEffective: 'USD:10', - status: PreparePayResultType.PaymentPossible, - } as Partial<PreparePayResult>), - getBalance: async () => ({ - balances: [{ - available: Amounts.stringify(availableBalance) - }] - } as Partial<BalancesResponse>), - } as Partial<typeof wxApi> as any) - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taller://pay", { + onUpdateNotification: subscriptions.saveSubscription, + preparePay: async () => + ({ + amountRaw: "USD:9", + amountEffective: "USD:10", + status: PreparePayResultType.PaymentPossible, + } as Partial<PreparePayResult>), + getBalance: async () => + ({ + balances: [ + { + available: Amounts.stringify(availableBalance), + }, + ], + } as Partial<BalancesResponse>), + } as Partial<typeof wxApi> as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:10')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:9')) - expect(r.totalFees).deep.equal(Amounts.parseOrThrow('USD:1')) + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:10")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); + expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); expect(r.payHandler.onClick).not.undefined; notifyCoinWithdrawn(Amounts.parseOrThrow("USD:5")); @@ -393,16 +436,14 @@ describe("Pay CTA states", () => { await waitNextUpdate(); { - const r = getLastResultOrThrow() - if (r.status !== 'ready') expect.fail() - expect(r.balance).deep.equal(Amounts.parseOrThrow('USD:15')); - expect(r.amount).deep.equal(Amounts.parseOrThrow('USD:9')) - expect(r.totalFees).deep.equal(Amounts.parseOrThrow('USD:1')) + const r = getLastResultOrThrow(); + if (r.status !== "ready") expect.fail(); + expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); + expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); + expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); expect(r.payHandler.onClick).not.undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); - - -});
\ No newline at end of file +}); diff --git a/packages/taler-wallet-webextension/src/cta/Refund.test.ts b/packages/taler-wallet-webextension/src/cta/Refund.test.ts index 864b4f12c..80ef15c84 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund.test.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund.test.ts @@ -19,7 +19,12 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { AmountJson, Amounts, NotificationType, PrepareRefundResult } from "@gnu-taler/taler-util"; +import { + AmountJson, + Amounts, + NotificationType, + PrepareRefundResult, +} from "@gnu-taler/taler-util"; import { expect } from "chai"; import { mountHook } from "../test-utils.js"; import { SubsHandler } from "./Pay.test.js"; @@ -29,146 +34,151 @@ import { useComponentState } from "./Refund.jsx"; describe("Refund CTA states", () => { it("should tell the user that the URI is missing", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(undefined, { - prepareRefund: async () => ({}), - applyRefund: async () => ({}), - onUpdateNotification: async () => ({}) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(undefined, { + prepareRefund: async () => ({}), + applyRefund: async () => ({}), + onUpdateNotification: async () => ({}), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const { status, hook } = getLastResultOrThrow() + const { status, hook } = getLastResultOrThrow(); - expect(status).equals('loading') + expect(status).equals("loading"); if (!hook) expect.fail(); if (!hook.hasError) expect.fail(); if (hook.operational) expect.fail(); expect(hook.message).eq("ERROR_NO-URI-FOR-REFUND"); } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should be ready after loading", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState("taler://refund/asdasdas", { - prepareRefund: async () => ({ - effectivePaid: 'EUR:2', - awaiting: 'EUR:2', - gone: 'EUR:0', - granted: 'EUR:0', - pending: false, - proposalId: '1', - info: { - contractTermsHash: '123', - merchant: { - name: 'the merchant name' - }, - orderId: 'orderId1', - summary: 'the sumary' - } - } as PrepareRefundResult as any), - applyRefund: async () => ({}), - onUpdateNotification: async () => ({}) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taler://refund/asdasdas", { + prepareRefund: async () => + ({ + effectivePaid: "EUR:2", + awaiting: "EUR:2", + gone: "EUR:0", + granted: "EUR:0", + pending: false, + proposalId: "1", + info: { + contractTermsHash: "123", + merchant: { + name: "the merchant name", + }, + orderId: "orderId1", + summary: "the sumary", + }, + } as PrepareRefundResult as any), + applyRefund: async () => ({}), + onUpdateNotification: async () => ({}), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== 'ready') expect.fail(); + if (state.status !== "ready") expect.fail(); if (state.hook) expect.fail(); expect(state.accept.onClick).not.undefined; expect(state.ignore.onClick).not.undefined; - expect(state.merchantName).eq('the merchant name'); - expect(state.orderId).eq('orderId1'); + expect(state.merchantName).eq("the merchant name"); + expect(state.orderId).eq("orderId1"); expect(state.products).undefined; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should be ignored after clicking the ignore button", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState("taler://refund/asdasdas", { - prepareRefund: async () => ({ - effectivePaid: 'EUR:2', - awaiting: 'EUR:2', - gone: 'EUR:0', - granted: 'EUR:0', - pending: false, - proposalId: '1', - info: { - contractTermsHash: '123', - merchant: { - name: 'the merchant name' - }, - orderId: 'orderId1', - summary: 'the sumary' - } - } as PrepareRefundResult as any), - applyRefund: async () => ({}), - onUpdateNotification: async () => ({}) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taler://refund/asdasdas", { + prepareRefund: async () => + ({ + effectivePaid: "EUR:2", + awaiting: "EUR:2", + gone: "EUR:0", + granted: "EUR:0", + pending: false, + proposalId: "1", + info: { + contractTermsHash: "123", + merchant: { + name: "the merchant name", + }, + orderId: "orderId1", + summary: "the sumary", + }, + } as PrepareRefundResult as any), + applyRefund: async () => ({}), + onUpdateNotification: async () => ({}), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== 'ready') expect.fail(); + if (state.status !== "ready") expect.fail(); if (state.hook) expect.fail(); expect(state.accept.onClick).not.undefined; - expect(state.merchantName).eq('the merchant name'); - expect(state.orderId).eq('orderId1'); + expect(state.merchantName).eq("the merchant name"); + expect(state.orderId).eq("orderId1"); expect(state.products).undefined; if (state.ignore.onClick === undefined) expect.fail(); - state.ignore.onClick() + state.ignore.onClick(); } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== 'ignored') expect.fail(); + if (state.status !== "ignored") expect.fail(); if (state.hook) expect.fail(); - expect(state.merchantName).eq('the merchant name'); + expect(state.merchantName).eq("the merchant name"); } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should be in progress when doing refresh", async () => { - let granted = Amounts.getZero('EUR') - const unit: AmountJson = { currency: 'EUR', value: 1, fraction: 0 } - const refunded: AmountJson = { currency: 'EUR', value: 2, fraction: 0 } - let awaiting: AmountJson = refunded + let granted = Amounts.getZero("EUR"); + const unit: AmountJson = { currency: "EUR", value: 1, fraction: 0 }; + const refunded: AmountJson = { currency: "EUR", value: 2, fraction: 0 }; + let awaiting: AmountJson = refunded; let pending = true; const subscriptions = new SubsHandler(); @@ -177,80 +187,82 @@ describe("Refund CTA states", () => { granted = Amounts.add(granted, unit).amount; pending = granted.value < refunded.value; awaiting = Amounts.sub(refunded, granted).amount; - subscriptions.notifyEvent(NotificationType.RefreshMelted) + subscriptions.notifyEvent(NotificationType.RefreshMelted); } - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState("taler://refund/asdasdas", { - prepareRefund: async () => ({ - awaiting: Amounts.stringify(awaiting), - effectivePaid: 'EUR:2', - gone: 'EUR:0', - granted: Amounts.stringify(granted), - pending, - proposalId: '1', - info: { - contractTermsHash: '123', - merchant: { - name: 'the merchant name' - }, - orderId: 'orderId1', - summary: 'the sumary' - } - } as PrepareRefundResult as any), - applyRefund: async () => ({}), - onUpdateNotification: subscriptions.saveSubscription, - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taler://refund/asdasdas", { + prepareRefund: async () => + ({ + awaiting: Amounts.stringify(awaiting), + effectivePaid: "EUR:2", + gone: "EUR:0", + granted: Amounts.stringify(granted), + pending, + proposalId: "1", + info: { + contractTermsHash: "123", + merchant: { + name: "the merchant name", + }, + orderId: "orderId1", + summary: "the sumary", + }, + } as PrepareRefundResult as any), + applyRefund: async () => ({}), + onUpdateNotification: subscriptions.saveSubscription, + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== 'in-progress') expect.fail('1'); + if (state.status !== "in-progress") expect.fail("1"); if (state.hook) expect.fail(); - expect(state.merchantName).eq('the merchant name'); + expect(state.merchantName).eq("the merchant name"); expect(state.products).undefined; - expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:2")) + expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:2")); // expect(state.progress).closeTo(1 / 3, 0.01) - notifyMelt() + notifyMelt(); } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== 'in-progress') expect.fail('2'); + if (state.status !== "in-progress") expect.fail("2"); if (state.hook) expect.fail(); - expect(state.merchantName).eq('the merchant name'); + expect(state.merchantName).eq("the merchant name"); expect(state.products).undefined; - expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:2")) + expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:2")); // expect(state.progress).closeTo(2 / 3, 0.01) - notifyMelt() + notifyMelt(); } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== 'completed') expect.fail('3'); + if (state.status !== "completed") expect.fail("3"); if (state.hook) expect.fail(); - expect(state.merchantName).eq('the merchant name'); + expect(state.merchantName).eq("the merchant name"); expect(state.products).undefined; - expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:2")) + expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:2")); } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); -});
\ No newline at end of file +}); diff --git a/packages/taler-wallet-webextension/src/cta/Tip.test.ts b/packages/taler-wallet-webextension/src/cta/Tip.test.ts index 0eda9b5be..192173463 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip.test.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip.test.ts @@ -26,64 +26,67 @@ import { useComponentState } from "./Tip.jsx"; describe("Tip CTA states", () => { it("should tell the user that the URI is missing", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(undefined, { - prepareTip: async () => ({}), - acceptTip: async () => ({}) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(undefined, { + prepareTip: async () => ({}), + acceptTip: async () => ({}), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const { status, hook } = getLastResultOrThrow() + const { status, hook } = getLastResultOrThrow(); - expect(status).equals('loading') + expect(status).equals("loading"); if (!hook) expect.fail(); if (!hook.hasError) expect.fail(); if (hook.operational) expect.fail(); expect(hook.message).eq("ERROR_NO-URI-FOR-TIP"); } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should be ready for accepting the tip", async () => { let tipAccepted = false; - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState("taler://tip/asd", { - prepareTip: async () => ({ - accepted: tipAccepted, - exchangeBaseUrl: "exchange url", - merchantBaseUrl: "merchant url", - tipAmountEffective: "EUR:1", - walletTipId: "tip_id", - } as PrepareTipResult as any), - acceptTip: async () => { - tipAccepted = true - } - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taler://tip/asd", { + prepareTip: async () => + ({ + accepted: tipAccepted, + exchangeBaseUrl: "exchange url", + merchantBaseUrl: "merchant url", + tipAmountEffective: "EUR:1", + walletTipId: "tip_id", + } as PrepareTipResult as any), + acceptTip: async () => { + tipAccepted = true; + }, + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== "ready") expect.fail() + if (state.status !== "ready") expect.fail(); if (state.hook) expect.fail(); expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1")); expect(state.merchantBaseUrl).eq("merchant url"); @@ -93,45 +96,46 @@ describe("Tip CTA states", () => { state.accept.onClick(); } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== "accepted") expect.fail() + if (state.status !== "accepted") expect.fail(); if (state.hook) expect.fail(); expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1")); expect(state.merchantBaseUrl).eq("merchant url"); expect(state.exchangeBaseUrl).eq("exchange url"); - } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should be ignored after clicking the ignore button", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState("taler://tip/asd", { - prepareTip: async () => ({ - exchangeBaseUrl: "exchange url", - merchantBaseUrl: "merchant url", - tipAmountEffective: "EUR:1", - walletTipId: "tip_id", - } as PrepareTipResult as any), - acceptTip: async () => ({}) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taler://tip/asd", { + prepareTip: async () => + ({ + exchangeBaseUrl: "exchange url", + merchantBaseUrl: "merchant url", + tipAmountEffective: "EUR:1", + walletTipId: "tip_id", + } as PrepareTipResult as any), + acceptTip: async () => ({}), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== "ready") expect.fail() + if (state.status !== "ready") expect.fail(); if (state.hook) expect.fail(); expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1")); expect(state.merchantBaseUrl).eq("merchant url"); @@ -141,52 +145,49 @@ describe("Tip CTA states", () => { state.ignore.onClick(); } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== "ignored") expect.fail() + if (state.status !== "ignored") expect.fail(); if (state.hook) expect.fail(); - } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should render accepted if the tip has been used previously", async () => { - - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState("taler://tip/asd", { - prepareTip: async () => ({ - accepted: true, - exchangeBaseUrl: "exchange url", - merchantBaseUrl: "merchant url", - tipAmountEffective: "EUR:1", - walletTipId: "tip_id", - } as PrepareTipResult as any), - acceptTip: async () => ({}) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taler://tip/asd", { + prepareTip: async () => + ({ + accepted: true, + exchangeBaseUrl: "exchange url", + merchantBaseUrl: "merchant url", + tipAmountEffective: "EUR:1", + walletTipId: "tip_id", + } as PrepareTipResult as any), + acceptTip: async () => ({}), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() + const state = getLastResultOrThrow(); - if (state.status !== "accepted") expect.fail() + if (state.status !== "accepted") expect.fail(); if (state.hook) expect.fail(); expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1")); expect(state.merchantBaseUrl).eq("merchant url"); expect(state.exchangeBaseUrl).eq("exchange url"); - } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); - - -});
\ No newline at end of file +}); diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts index 7f05870c1..6fa8933c3 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts @@ -19,234 +19,249 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { Amounts, ExchangeListItem, GetExchangeTosResult } 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"; -const exchanges: ExchangeListItem[] = [{ - currency: 'ARS', - exchangeBaseUrl: 'http://exchange.demo.taler.net', - paytoUris: [], - tos: { - acceptedVersion: '', - } -}] +const exchanges: ExchangeListItem[] = [ + { + currency: "ARS", + exchangeBaseUrl: "http://exchange.demo.taler.net", + paytoUris: [], + tos: { + acceptedVersion: "", + }, + }, +]; describe("Withdraw CTA states", () => { it("should tell the user that the URI is missing", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState(undefined, { - listExchanges: async () => ({ exchanges }), - getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({ - amount: 'ARS:2', - possibleExchanges: exchanges, - }) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState(undefined, { + listExchanges: async () => ({ exchanges }), + getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({ + amount: "ARS:2", + possibleExchanges: exchanges, + }), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading-uri') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading-uri"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const { status, hook } = getLastResultOrThrow() + const { status, hook } = getLastResultOrThrow(); - expect(status).equals('loading-uri') + expect(status).equals("loading-uri"); if (!hook) expect.fail(); if (!hook.hasError) expect.fail(); if (hook.operational) expect.fail(); expect(hook.message).eq("ERROR_NO-URI-FOR-WITHDRAWAL"); } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); it("should tell the user that there is not known exchange", async () => { - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState('taler-withdraw://', { - listExchanges: async () => ({ exchanges }), - getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({ - amount: 'EUR:2', - possibleExchanges: [], - }) - } as any), - ); + const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + mountHook(() => + useComponentState("taler-withdraw://", { + listExchanges: async () => ({ exchanges }), + getWithdrawalDetailsForUri: async ({ talerWithdrawUri }: any) => ({ + amount: "EUR:2", + possibleExchanges: [], + }), + } as any), + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading-uri') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading-uri"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const { status, hook } = getLastResultOrThrow() + const { status, hook } = getLastResultOrThrow(); - expect(status).equals('loading-exchange') + expect(status).equals("loading-exchange"); - expect(hook).deep.equals({ "hasError": true, "operational": false, "message": "ERROR_NO-DEFAULT-EXCHANGE" }); + expect(hook).deep.equals({ + hasError: true, + operational: false, + message: "ERROR_NO-DEFAULT-EXCHANGE", + }); } - await assertNoPendingUpdate() + 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', + 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), - getExchangeTos: async (): Promise<GetExchangeTosResult> => ({ - contentType: 'text', - content: 'just accept', - acceptedEtag: 'v1', - currentEtag: 'v1' - }) - } as any), - ); + ); { - const { status, hook } = getLastResultOrThrow() - expect(status).equals('loading-uri') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading-uri"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const { status, hook } = getLastResultOrThrow() + const { status, hook } = getLastResultOrThrow(); - expect(status).equals('loading-info') + expect(status).equals("loading-info"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() - expect(state.status).equals("success") + 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.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")) + "http://exchange.demo.taler.net": "http://exchange.demo.taler.net", + }); + expect(state.showExchangeSelection).false; - expect(state.doWithdrawal.onClick).not.undefined - expect(state.mustAcceptFirst).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.onClick).not.undefined; + expect(state.mustAcceptFirst).false; } - await assertNoPendingUpdate() + 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', + 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), - 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') + const { status, hook } = getLastResultOrThrow(); + expect(status).equals("loading-uri"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const { status, hook } = getLastResultOrThrow() + const { status, hook } = getLastResultOrThrow(); - expect(status).equals('loading-info') + expect(status).equals("loading-info"); expect(hook).undefined; } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() - expect(state.status).equals("success") + 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.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 + "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.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.onClick).undefined - expect(state.mustAcceptFirst).true + expect(state.doWithdrawal.onClick).undefined; + expect(state.mustAcceptFirst).true; // accept TOS - state.tosProps?.onAccept(true) + state.tosProps?.onAccept(true); } - await waitNextUpdate() + await waitNextUpdate(); { - const state = getLastResultOrThrow() - expect(state.status).equals("success") + 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.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 + "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.onClick).not.undefined - expect(state.mustAcceptFirst).true + 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.onClick).not.undefined; + expect(state.mustAcceptFirst).true; } - await assertNoPendingUpdate() + await assertNoPendingUpdate(); }); - -});
\ No newline at end of file +}); diff --git a/packages/taler-wallet-webextension/src/cta/termsExample.ts b/packages/taler-wallet-webextension/src/cta/termsExample.ts index 986874c18..4210e7a7e 100644 --- a/packages/taler-wallet-webextension/src/cta/termsExample.ts +++ b/packages/taler-wallet-webextension/src/cta/termsExample.ts @@ -779,4 +779,3 @@ trailer << /Root 3 0 R >> %%EOF `; - |