[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant-backoffice] branch master updated: bank: test successful
From: |
gnunet |
Subject: |
[taler-merchant-backoffice] branch master updated: bank: test successful registration |
Date: |
Wed, 15 Dec 2021 15:01:46 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository merchant-backoffice.
The following commit(s) were added to refs/heads/master by this push:
new 4536c0c bank: test successful registration
4536c0c is described below
commit 4536c0c8f92818856076a2fba6e8015deca135c6
Author: ms <ms@taler.net>
AuthorDate: Wed Dec 15 15:01:36 2021 +0100
bank: test successful registration
---
packages/bank/src/pages/home/index.tsx | 67 +++++--------------------------
packages/bank/tests/__tests__/homepage.js | 18 ++++++++-
2 files changed, 28 insertions(+), 57 deletions(-)
diff --git a/packages/bank/src/pages/home/index.tsx
b/packages/bank/src/pages/home/index.tsx
index 80fca27..d056021 100644
--- a/packages/bank/src/pages/home/index.tsx
+++ b/packages/bank/src/pages/home/index.tsx
@@ -103,58 +103,11 @@ function usePageState(
*****************/
/**
- * Wrappers for HTTP requests specific to individual API calls.
- * Each wrapper will (1) manage HTTP requests and responses,
- * and (2) update the state accordingly.
- *
- * Their signature is:
- * RequestType x ResponseType x use*State() => void
- *
- * For example, a 'wrap()' function can look like:
- *
- * wrap(url: string,
- * req: WrapTypeReq,
- * state: StateType // Will only have setters used.
- * ) {
- *
- * let cb: (resp: WrapTypeRes) => void = {
- * // implementation here.
- * // ..
- * state.setter(...)
- * };
- *
- * post(url, req, (resp) => cb(resp))
- * }
- *
- ***/
-
-/**
- * This function requests GET /accounts/{account_name}.
- *
- * It's only a information retriever, without any effect
- * on the state.
+ * A 'wrapper' is typically a function that prepares one
+ * particular API call and updates the state accordingly.
+ * Whether a new component should be returned too, depends
+ * on each case.
*/
-async function accountInfoCall(
- backendState: BackendStateType,
- accountStateSetter: (fn: (state: AccountStateType) => void) => void
-) {
- const url = new URL(`accounts/${backendState.username}`, backendState.url);
- const handleResp = (respStatus: number) => {
- switch (respStatus) {
- case 200: {
- accountStateSetter((state) => ({ ...state, balance: "1 EUR" }));
- break;
- }
- default: {
- accountStateSetter((state) => ({
- ...state,
- error: "Missing information.",
- }));
- }
- }
- };
- handleResp(200);
-}
/**
* This function requests /register.
@@ -202,11 +155,13 @@ async function registrationCall(
/**
* Show only the account's balance.
*/
-export function Account(props: any) {
+function Account(props: any) {
const { data, error } = useSWR(`accounts/${props.accountLabel}`);
- console.log("data", data);
- console.log("error", error);
- return <p>Your balance is coming...</p>;
+ if (typeof error != "undefined") {
+ return <p>Account information could not be retrieved</p>
+ }
+ if (!data) return <p>Retrieving the balance...</p>;
+ return <p>Your balance is {data.balance.amount}.</p>;
}
/**
@@ -219,7 +174,7 @@ function SWRWithCredentials(props: any): VNode {
"Authorization",
`Basic ${Buffer.from(username + ":" + password).toString("base64")}`
);
- console.log("API call to", backendUrl);
+ console.log("Likely backend base URL", backendUrl);
return (
<SWRConfig
value={{
diff --git a/packages/bank/tests/__tests__/homepage.js
b/packages/bank/tests/__tests__/homepage.js
index cfb69e1..d03dbb0 100644
--- a/packages/bank/tests/__tests__/homepage.js
+++ b/packages/bank/tests/__tests__/homepage.js
@@ -38,7 +38,7 @@ describe("home page", () => {
)
})
- test("new registration network failure", async () => {
+ test("registration network failure", async () => {
render(<BankHome />);
let submitButton = fillRegistrationForm();
// Mocking network failure.
@@ -50,4 +50,20 @@ describe("home page", () => {
{body: JSON.stringify({username: "foo", password: "bar"}), method:
"POST"},
)
})
+
+ test("registration success", async () => {
+ render(<BankHome />);
+ let submitButton = fillRegistrationForm();
+ fetch.once("{}", {
+ status: 200
+ }).once(JSON.stringify({
+ balance: {
+ amount: "EUR:10",
+ credit_debit_indicator: "credit"
+ },
+ paytoUri: "payto://iban/123/ABC"
+ }))
+ fireEvent.click(submitButton);
+ await screen.findByText("balance is EUR:10", {exact: false})
+ })
})
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-merchant-backoffice] branch master updated: bank: test successful registration,
gnunet <=