-dce and type fixes
This commit is contained in:
parent
8442452c33
commit
ae818df3bf
@ -28,21 +28,6 @@ export default {
|
|||||||
title: "wallet/deposit",
|
title: "wallet/deposit",
|
||||||
};
|
};
|
||||||
|
|
||||||
const accountsType = {
|
|
||||||
"": labelForAccountType(""),
|
|
||||||
iban: labelForAccountType("iban"),
|
|
||||||
bitcoin: labelForAccountType("bitcoin"),
|
|
||||||
"x-taler-bank": labelForAccountType("x-taler-bank"),
|
|
||||||
};
|
|
||||||
async function alwaysReturnFeeToOne(): Promise<DepositGroupFees> {
|
|
||||||
const fee = {
|
|
||||||
currency: "EUR",
|
|
||||||
value: 1,
|
|
||||||
fraction: 0,
|
|
||||||
};
|
|
||||||
return { coin: fee, refresh: fee, wire: fee };
|
|
||||||
}
|
|
||||||
|
|
||||||
// const ac = parsePaytoUri("payto://iban/ES8877998399652238")!;
|
// const ac = parsePaytoUri("payto://iban/ES8877998399652238")!;
|
||||||
// const accountMap = createLabelsForBankAccount([ac]);
|
// const accountMap = createLabelsForBankAccount([ac]);
|
||||||
|
|
||||||
|
@ -20,53 +20,60 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Amounts, DepositGroupFees,
|
Amounts,
|
||||||
|
DepositGroupFees,
|
||||||
parsePaytoUri,
|
parsePaytoUri,
|
||||||
stringifyPaytoUri
|
stringifyPaytoUri,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { createWalletApiMock, mountHook, nullFunction } from "../../test-utils.js";
|
import {
|
||||||
|
createWalletApiMock,
|
||||||
|
mountHook,
|
||||||
|
nullFunction,
|
||||||
|
} from "../../test-utils.js";
|
||||||
|
|
||||||
import { useComponentState } from "./state.js";
|
import { useComponentState } from "./state.js";
|
||||||
|
|
||||||
const currency = "EUR";
|
const currency = "EUR";
|
||||||
const withoutFee = (): DepositGroupFees => ({
|
const withoutFee = (): DepositGroupFees => ({
|
||||||
coin: Amounts.parseOrThrow(`${currency}:0`),
|
coin: Amounts.stringify(`${currency}:0`),
|
||||||
wire: Amounts.parseOrThrow(`${currency}:0`),
|
wire: Amounts.stringify(`${currency}:0`),
|
||||||
refresh: Amounts.parseOrThrow(`${currency}:0`),
|
refresh: Amounts.stringify(`${currency}:0`),
|
||||||
});
|
});
|
||||||
|
|
||||||
const withSomeFee = (): DepositGroupFees => ({
|
const withSomeFee = (): DepositGroupFees => ({
|
||||||
coin: Amounts.parseOrThrow(`${currency}:1`),
|
coin: Amounts.stringify(`${currency}:1`),
|
||||||
wire: Amounts.parseOrThrow(`${currency}:1`),
|
wire: Amounts.stringify(`${currency}:1`),
|
||||||
refresh: Amounts.parseOrThrow(`${currency}:1`),
|
refresh: Amounts.stringify(`${currency}:1`),
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("DepositPage states", () => {
|
describe("DepositPage states", () => {
|
||||||
it("should have status 'no-enough-balance' when balance is empty", async () => {
|
it("should have status 'no-enough-balance' when balance is empty", async () => {
|
||||||
const { handler, mock } = createWalletApiMock();
|
const { handler, mock } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction }
|
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [{
|
balances: [
|
||||||
available: `${currency}:0`,
|
{
|
||||||
hasPendingTransactions: false,
|
available: `${currency}:0`,
|
||||||
pendingIncoming: `${currency}:0`,
|
hasPendingTransactions: false,
|
||||||
pendingOutgoing: `${currency}:0`,
|
pendingIncoming: `${currency}:0`,
|
||||||
requiresUserInput: false,
|
pendingOutgoing: `${currency}:0`,
|
||||||
}],
|
requiresUserInput: false,
|
||||||
})
|
},
|
||||||
handler.addWalletCallResponse(WalletApiOperation.ListKnownBankAccounts, undefined, {
|
],
|
||||||
accounts: []
|
|
||||||
});
|
});
|
||||||
|
handler.addWalletCallResponse(
|
||||||
|
WalletApiOperation.ListKnownBankAccounts,
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
accounts: [],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
||||||
mountHook(() =>
|
mountHook(() => useComponentState(props, mock));
|
||||||
useComponentState(
|
|
||||||
props, mock
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const { status } = pullLastResultOrThrow();
|
const { status } = pullLastResultOrThrow();
|
||||||
@ -81,31 +88,33 @@ describe("DepositPage states", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await assertNoPendingUpdate();
|
await assertNoPendingUpdate();
|
||||||
expect(handler.getCallingQueueState()).eq("empty")
|
expect(handler.getCallingQueueState()).eq("empty");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should have status 'no-accounts' when balance is not empty and accounts is empty", async () => {
|
it("should have status 'no-accounts' when balance is not empty and accounts is empty", async () => {
|
||||||
const { handler, mock } = createWalletApiMock();
|
const { handler, mock } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction }
|
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [{
|
balances: [
|
||||||
available: `${currency}:1`,
|
{
|
||||||
hasPendingTransactions: false,
|
available: `${currency}:1`,
|
||||||
pendingIncoming: `${currency}:0`,
|
hasPendingTransactions: false,
|
||||||
pendingOutgoing: `${currency}:0`,
|
pendingIncoming: `${currency}:0`,
|
||||||
requiresUserInput: false,
|
pendingOutgoing: `${currency}:0`,
|
||||||
}],
|
requiresUserInput: false,
|
||||||
})
|
},
|
||||||
handler.addWalletCallResponse(WalletApiOperation.ListKnownBankAccounts, undefined, {
|
],
|
||||||
accounts: []
|
|
||||||
});
|
});
|
||||||
|
handler.addWalletCallResponse(
|
||||||
|
WalletApiOperation.ListKnownBankAccounts,
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
accounts: [],
|
||||||
|
},
|
||||||
|
);
|
||||||
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
||||||
mountHook(() =>
|
mountHook(() => useComponentState(props, mock));
|
||||||
useComponentState(
|
|
||||||
props, mock
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const { status } = pullLastResultOrThrow();
|
const { status } = pullLastResultOrThrow();
|
||||||
@ -120,7 +129,7 @@ describe("DepositPage states", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await assertNoPendingUpdate();
|
await assertNoPendingUpdate();
|
||||||
expect(handler.getCallingQueueState()).eq("empty")
|
expect(handler.getCallingQueueState()).eq("empty");
|
||||||
});
|
});
|
||||||
|
|
||||||
const ibanPayto = {
|
const ibanPayto = {
|
||||||
@ -138,27 +147,29 @@ describe("DepositPage states", () => {
|
|||||||
|
|
||||||
it("should have status 'ready' but unable to deposit ", async () => {
|
it("should have status 'ready' but unable to deposit ", async () => {
|
||||||
const { handler, mock } = createWalletApiMock();
|
const { handler, mock } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction }
|
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [{
|
balances: [
|
||||||
available: `${currency}:1`,
|
{
|
||||||
hasPendingTransactions: false,
|
available: `${currency}:1`,
|
||||||
pendingIncoming: `${currency}:0`,
|
hasPendingTransactions: false,
|
||||||
pendingOutgoing: `${currency}:0`,
|
pendingIncoming: `${currency}:0`,
|
||||||
requiresUserInput: false,
|
pendingOutgoing: `${currency}:0`,
|
||||||
}],
|
requiresUserInput: false,
|
||||||
})
|
},
|
||||||
handler.addWalletCallResponse(WalletApiOperation.ListKnownBankAccounts, undefined, {
|
],
|
||||||
accounts: [ibanPayto]
|
|
||||||
});
|
});
|
||||||
|
handler.addWalletCallResponse(
|
||||||
|
WalletApiOperation.ListKnownBankAccounts,
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
accounts: [ibanPayto],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
||||||
mountHook(() =>
|
mountHook(() => useComponentState(props, mock));
|
||||||
useComponentState(
|
|
||||||
props, mock
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const { status } = pullLastResultOrThrow();
|
const { status } = pullLastResultOrThrow();
|
||||||
@ -178,35 +189,49 @@ describe("DepositPage states", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await assertNoPendingUpdate();
|
await assertNoPendingUpdate();
|
||||||
expect(handler.getCallingQueueState()).eq("empty")
|
expect(handler.getCallingQueueState()).eq("empty");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not be able to deposit more than the balance ", async () => {
|
it("should not be able to deposit more than the balance ", async () => {
|
||||||
const { handler, mock } = createWalletApiMock();
|
const { handler, mock } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction }
|
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [{
|
balances: [
|
||||||
available: `${currency}:5`,
|
{
|
||||||
hasPendingTransactions: false,
|
available: `${currency}:5`,
|
||||||
pendingIncoming: `${currency}:0`,
|
hasPendingTransactions: false,
|
||||||
pendingOutgoing: `${currency}:0`,
|
pendingIncoming: `${currency}:0`,
|
||||||
requiresUserInput: false,
|
pendingOutgoing: `${currency}:0`,
|
||||||
}],
|
requiresUserInput: false,
|
||||||
})
|
},
|
||||||
handler.addWalletCallResponse(WalletApiOperation.ListKnownBankAccounts, undefined, {
|
],
|
||||||
accounts: [talerBankPayto, ibanPayto]
|
|
||||||
});
|
});
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetFeeForDeposit, undefined, withoutFee())
|
handler.addWalletCallResponse(
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetFeeForDeposit, undefined, withoutFee())
|
WalletApiOperation.ListKnownBankAccounts,
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetFeeForDeposit, undefined, withoutFee())
|
undefined,
|
||||||
|
{
|
||||||
|
accounts: [talerBankPayto, ibanPayto],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
handler.addWalletCallResponse(
|
||||||
|
WalletApiOperation.GetFeeForDeposit,
|
||||||
|
undefined,
|
||||||
|
withoutFee(),
|
||||||
|
);
|
||||||
|
handler.addWalletCallResponse(
|
||||||
|
WalletApiOperation.GetFeeForDeposit,
|
||||||
|
undefined,
|
||||||
|
withoutFee(),
|
||||||
|
);
|
||||||
|
handler.addWalletCallResponse(
|
||||||
|
WalletApiOperation.GetFeeForDeposit,
|
||||||
|
undefined,
|
||||||
|
withoutFee(),
|
||||||
|
);
|
||||||
|
|
||||||
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
||||||
mountHook(() =>
|
mountHook(() => useComponentState(props, mock));
|
||||||
useComponentState(
|
|
||||||
props, mock
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const { status } = pullLastResultOrThrow();
|
const { status } = pullLastResultOrThrow();
|
||||||
@ -214,7 +239,7 @@ describe("DepositPage states", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(await waitForStateUpdate()).true;
|
expect(await waitForStateUpdate()).true;
|
||||||
const accountSelected = stringifyPaytoUri(ibanPayto.uri)
|
const accountSelected = stringifyPaytoUri(ibanPayto.uri);
|
||||||
|
|
||||||
{
|
{
|
||||||
const r = pullLastResultOrThrow();
|
const r = pullLastResultOrThrow();
|
||||||
@ -227,7 +252,7 @@ describe("DepositPage states", () => {
|
|||||||
expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`));
|
expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`));
|
||||||
expect(r.account.onChange).not.undefined;
|
expect(r.account.onChange).not.undefined;
|
||||||
|
|
||||||
r.account.onChange!(accountSelected)
|
r.account.onChange!(accountSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(await waitForStateUpdate()).true;
|
expect(await waitForStateUpdate()).true;
|
||||||
@ -316,29 +341,39 @@ describe("DepositPage states", () => {
|
|||||||
|
|
||||||
it("should calculate the fee upon entering amount ", async () => {
|
it("should calculate the fee upon entering amount ", async () => {
|
||||||
const { handler, mock } = createWalletApiMock();
|
const { handler, mock } = createWalletApiMock();
|
||||||
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction }
|
const props = { currency, onCancel: nullFunction, onSuccess: nullFunction };
|
||||||
|
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, {
|
||||||
balances: [{
|
balances: [
|
||||||
available: `${currency}:10`,
|
{
|
||||||
hasPendingTransactions: false,
|
available: `${currency}:10`,
|
||||||
pendingIncoming: `${currency}:0`,
|
hasPendingTransactions: false,
|
||||||
pendingOutgoing: `${currency}:0`,
|
pendingIncoming: `${currency}:0`,
|
||||||
requiresUserInput: false,
|
pendingOutgoing: `${currency}:0`,
|
||||||
}],
|
requiresUserInput: false,
|
||||||
})
|
},
|
||||||
handler.addWalletCallResponse(WalletApiOperation.ListKnownBankAccounts, undefined, {
|
],
|
||||||
accounts: [talerBankPayto, ibanPayto]
|
|
||||||
});
|
});
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetFeeForDeposit, undefined, withSomeFee())
|
handler.addWalletCallResponse(
|
||||||
handler.addWalletCallResponse(WalletApiOperation.GetFeeForDeposit, undefined, withSomeFee())
|
WalletApiOperation.ListKnownBankAccounts,
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
accounts: [talerBankPayto, ibanPayto],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
handler.addWalletCallResponse(
|
||||||
|
WalletApiOperation.GetFeeForDeposit,
|
||||||
|
undefined,
|
||||||
|
withSomeFee(),
|
||||||
|
);
|
||||||
|
handler.addWalletCallResponse(
|
||||||
|
WalletApiOperation.GetFeeForDeposit,
|
||||||
|
undefined,
|
||||||
|
withSomeFee(),
|
||||||
|
);
|
||||||
|
|
||||||
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
|
||||||
mountHook(() =>
|
mountHook(() => useComponentState(props, mock));
|
||||||
useComponentState(
|
|
||||||
props, mock
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const { status } = pullLastResultOrThrow();
|
const { status } = pullLastResultOrThrow();
|
||||||
@ -346,7 +381,7 @@ describe("DepositPage states", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(await waitForStateUpdate()).true;
|
expect(await waitForStateUpdate()).true;
|
||||||
const accountSelected = stringifyPaytoUri(ibanPayto.uri)
|
const accountSelected = stringifyPaytoUri(ibanPayto.uri);
|
||||||
|
|
||||||
{
|
{
|
||||||
const r = pullLastResultOrThrow();
|
const r = pullLastResultOrThrow();
|
||||||
@ -359,7 +394,7 @@ describe("DepositPage states", () => {
|
|||||||
expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`));
|
expect(r.totalFee).deep.eq(Amounts.parseOrThrow(`${currency}:0`));
|
||||||
expect(r.account.onChange).not.undefined;
|
expect(r.account.onChange).not.undefined;
|
||||||
|
|
||||||
r.account.onChange!(accountSelected)
|
r.account.onChange!(accountSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(await waitForStateUpdate()).true;
|
expect(await waitForStateUpdate()).true;
|
||||||
@ -392,7 +427,6 @@ describe("DepositPage states", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await assertNoPendingUpdate();
|
await assertNoPendingUpdate();
|
||||||
expect(handler.getCallingQueueState()).eq("empty")
|
expect(handler.getCallingQueueState()).eq("empty");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user