gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant-backoffice] branch master updated: testing public histor


From: gnunet
Subject: [taler-merchant-backoffice] branch master updated: testing public histories (WIP)
Date: Wed, 12 Jan 2022 21:56:20 +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 589f954  testing public histories (WIP)
589f954 is described below

commit 589f954dce1b52fa19d7cf18839a0930a454e479
Author: ms <ms@taler.net>
AuthorDate: Wed Jan 12 21:56:11 2022 +0100

    testing public histories (WIP)
---
 packages/bank/src/pages/home/index.tsx    | 71 ++++++++++++++++++-----------
 packages/bank/tests/__tests__/homepage.js | 74 +++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+), 25 deletions(-)

diff --git a/packages/bank/src/pages/home/index.tsx 
b/packages/bank/src/pages/home/index.tsx
index 2a42d03..9faf816 100644
--- a/packages/bank/src/pages/home/index.tsx
+++ b/packages/bank/src/pages/home/index.tsx
@@ -85,9 +85,11 @@ function prepareHeaders(username: string, password: string) {
 }
 
 const getRootPath = () => {
-  return typeof window !== undefined
+  const maybeRootPath = typeof window !== undefined
     ? window.location.origin + window.location.pathname
     : "/";
+  if (!maybeRootPath.endsWith("/")) return maybeRootPath + "/";
+  return maybeRootPath;
 };
 
 /*******************
@@ -510,25 +512,22 @@ function Transactions(Props: any): VNode {
       }
     }
   }
-  var txsPages = <p>"loading..."</p>
-
-  if (data) {
-    console.log("History data", data);
-    txsPages = <div>{
-      data.transactions.map(function(item: any) {
-       const sign = item.direction == "DBIT" ? "-" : "";
-       const counterpart = item.direction == "DBIT" ? item.creditorIban : 
item.debtorIban;
-       // Pattern:
-       //
-       // DD/MM YYYY subject -5 EUR
-       // DD/MM YYYY subject 5 EUR
-       const dateRegex = /^([0-9]{4})-([0-9]{2})-([0-9]{1,2})/
-       const dateParse = dateRegex.exec(item.date)
-       const date = dateParse !== null ? `${dateParse[3]}/${dateParse[2]} 
${dateParse[3]}` : "date not found"
-        return <span> {date} {item.subject} {sign}{item.amount} 
{item.currency}</span>
-    })}</div>
-  }
-  return txsPages;
+  if (!data) return <p>"Transactions page loading..."</p>;
+
+  console.log("History data", data);
+  return <div>{
+    data.transactions.map(function(item: any) {
+      const sign = item.direction == "DBIT" ? "-" : "";
+      const counterpart = item.direction == "DBIT" ? item.creditorIban : 
item.debtorIban;
+      // Pattern:
+      //
+      // DD/MM YYYY subject -5 EUR
+      // DD/MM YYYY subject 5 EUR
+      const dateRegex = /^([0-9]{4})-([0-9]{2})-([0-9]{1,2})/
+      const dateParse = dateRegex.exec(item.date)
+      const date = dateParse !== null ? `${dateParse[3]}/${dateParse[2]} 
${dateParse[1]}` : "date not found"
+      return <span> {date} {item.subject} {sign}{item.amount} 
{item.currency}</span>
+  })}</div>
 }
 
 /**
@@ -639,12 +638,30 @@ function SWRWithCredentials(props: any): VNode {
   );
 }
 
+function SWRWithoutCredentials(props: any): VNode {
+  const { baseUrl } = props;
+  console.log("Base URL", baseUrl);
+  return (
+    <SWRConfig
+      value={{
+        fetcher: (url) =>
+          fetch(baseUrl + url || "").then(
+           (r) => {
+             if (!r.ok) {
+               throw {status: r.status, json: r.json()};
+             }
+              return r.json()
+           }
+         ),
+      }}>{props.children}</SWRConfig>
+  );
+}
+
 /**
  * Show histories of public accounts.
  */
-export function PublicHistories(): VNode {
-
-  const { data, error } = useSWR(`access-api/public-accounts`);
+function PublicHistories(): VNode {
+  const { data, error } = useSWR("access-api/public-accounts")
   if (typeof error !== "undefined") {
     console.log("account error", error);
     switch(error.status) {
@@ -656,9 +673,10 @@ export function PublicHistories(): VNode {
       }
     }
   }
-  if (!data) return <p>Loading...</p>
+  if (!data) return <p>Waiting public accounts list...</p>
   var txs = [];
   for (const account of data.publicAccounts) {
+    console.log("Asking transactions for", account.accountLabel)
     txs.push(<Transactions accountLabel={account.accountLabel} pageNumber={0} 
/>)
   }
   return <div>{txs}</div>;
@@ -804,7 +822,10 @@ export function BankHome(): VNode {
         }}>{i18n`Sign in`}</button>
       <div>
         <p>{i18n`Public transactions:`}</p>
-       <PublicHistories />
+       <SWRWithoutCredentials
+         baseUrl={getRootPath()}>
+          <PublicHistories />
+       </SWRWithoutCredentials>
       </div>
     </Fragment>
   );
diff --git a/packages/bank/tests/__tests__/homepage.js 
b/packages/bank/tests/__tests__/homepage.js
index 71d300e..2394ad5 100644
--- a/packages/bank/tests/__tests__/homepage.js
+++ b/packages/bank/tests/__tests__/homepage.js
@@ -192,6 +192,80 @@ describe("home page", () => {
     fetch.resetMocks();
     cleanup();
   })
+  test("public histories", async () => {
+    // First, mock the public accounts list.
+    fetch.mockImplementationOnce(JSON.stringify({
+      "publicAccounts" : [ {
+        "balance" : "EUR:1",
+        "iban" : "XXX",
+        "accountLabel" : "foo"
+      }, {
+        "balance" : "EUR:2",
+        "iban" : "YYY",
+        "accountLabel" : "bar"
+      }]
+    }))
+    fetch.mockImplementationOnce(JSON.stringify({ // Response to history 
request.
+      transactions: [{
+        debtorIban: "XXX",
+        debtorBic: "YYY",
+        debtorName: "Foo",
+        creditorIban: "AAA",
+        creditorBic: "BBB",
+        creditorName: "Bar",
+       direction: "DBIT",
+        amount: "EUR:5",
+       subject: "Reimbursement",
+       date: "1970-01-01"
+      }, {
+        debtorIban: "XXX",
+        debtorBic: "YYY",
+        debtorName: "Foo",
+        creditorIban: "AAA",
+        creditorBic: "BBB",
+        creditorName: "Bar",
+       direction: "CRDT",
+        amount: "EUR:5",
+       subject: "Bonus",
+       date: "2000-01-01"
+      }]
+    }))
+    fetch.mockResponseOnce(JSON.stringify({ // Response to history request.
+      transactions: [{
+        debtorIban: "XXX",
+        debtorBic: "YYY",
+        debtorName: "Foo",
+        creditorIban: "AAA",
+        creditorBic: "BBB",
+        creditorName: "Bar",
+       direction: "DBIT",
+        amount: "EUR:5",
+       subject: "Donation",
+       date: "1970-01-01"
+      }, {
+        debtorIban: "XXX",
+        debtorBic: "YYY",
+        debtorName: "Foo",
+        creditorIban: "AAA",
+        creditorBic: "BBB",
+        creditorName: "Bar",
+       direction: "CRDT",
+        amount: "EUR:5",
+       subject: "Refund",
+       date: "2000-01-01"
+      }]
+    }))
+    render(<BankHome />);
+    await expect(fetch).toHaveBeenCalledWith(
+      "http://localhost/demobanks/default/access-api/public-accounts";
+    )
+    await expect(fetch).toHaveBeenCalledWith(
+      
"http://localhost/demobanks/default/access-api/accounts/foo/transactions?page=0";
+    )
+    await expect(fetch).toHaveBeenCalledWith(
+      
"http://localhost/demobanks/default/access-api/accounts/bar/transactions?page=0";
+    )
+  })
 
   // check page informs about the current balance
   // after a successful registration.

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]