[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant-backoffice] 04/11: bank: fix URL generation
From: |
gnunet |
Subject: |
[taler-merchant-backoffice] 04/11: bank: fix URL generation |
Date: |
Mon, 20 Dec 2021 17:45:02 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository merchant-backoffice.
commit 871b71601b4402dae4c50ff838c37cc27c9d6391
Author: ms <ms@taler.net>
AuthorDate: Sun Dec 19 14:15:22 2021 +0100
bank: fix URL generation
---
packages/bank/src/pages/home/index.tsx | 34 +++++++++++++++++++++++--------
packages/bank/tests/__tests__/homepage.js | 10 ++++-----
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/packages/bank/src/pages/home/index.tsx
b/packages/bank/src/pages/home/index.tsx
index d3ec261..7700a9d 100644
--- a/packages/bank/src/pages/home/index.tsx
+++ b/packages/bank/src/pages/home/index.tsx
@@ -170,10 +170,14 @@ async function confirmWithdrawalCall(
"Authorization",
`Basic ${Buffer.from(backendState.username + ":" +
backendState.password).toString("base64")}`
);
- var res = await fetch(
-
`${backendState.url}/accounts/${backendState.username}/withdrawals/confirm`, {
- method: 'POST',
- headers: headers
+ // Backend URL must have been stored _with_ a final slash.
+ const url = new URL(
+ `access-api/accounts/${backendState.username}/withdrawals/confirm`,
+ backendState.url
+ )
+ var res = await fetch(url.href, {
+ method: 'POST',
+ headers: headers
})
} catch (error) {
console.log("Could not POST withdrawal confirmation to the bank", error);
@@ -241,8 +245,12 @@ async function createWithdrawalCall(
"Authorization",
`Basic ${Buffer.from(backendState.username + ":" +
backendState.password).toString("base64")}`
);
- var res = await fetch(
- `${backendState.url}/accounts/${backendState.username}/withdrawals`, {
+ // Backend URL must have been stored _with_ a final slash.
+ const url = new URL(
+ `access-api/accounts/${backendState.username}/withdrawals`,
+ backendState.url
+ )
+ var res = await fetch(url.href, {
method: 'POST',
headers: headers,
body: JSON.stringify({amount: amount}),
@@ -321,10 +329,18 @@ async function registrationCall(
) {
let baseUrl = getRootPath();
+ /**
+ * If the base URL doesn't end with slash and the path
+ * is not empty, then the concatenation made by URL()
+ * drops the last path element.
+ */
+ if (!baseUrl.endsWith('/')) {
+ baseUrl += '/'
+ }
let headersNoCache = new Headers();
+ const url = new URL("access-api/testing/register", baseUrl)
try {
- var res = await fetch(
- `${baseUrl}/testing/register`, {
+ var res = await fetch(url.href, {
method: 'POST',
body: JSON.stringify(req),
});
@@ -362,7 +378,7 @@ async function registrationCall(
*/
function Account(props: any) {
const { withdrawalOutcome, talerWithdrawUri, accountLabel } = props;
- const { data, error } = useSWR(`/accounts/${props.accountLabel}`);
+ const { data, error } = useSWR(`access-api/accounts/${props.accountLabel}`);
console.log("account data", data);
console.log("account error", error);
if (typeof error !== "undefined") {
diff --git a/packages/bank/tests/__tests__/homepage.js
b/packages/bank/tests/__tests__/homepage.js
index a33088b..b677ed1 100644
--- a/packages/bank/tests/__tests__/homepage.js
+++ b/packages/bank/tests/__tests__/homepage.js
@@ -96,7 +96,7 @@ describe("withdraw", () => {
*/
fireEvent.click(withdrawButton);
expect(fetch).toHaveBeenCalledWith(
-
`http://localhost/demobanks/default/accounts/${context.username}/withdrawals`,
+
`http://localhost/demobanks/default/access-api/accounts/${context.username}/withdrawals`,
expect.objectContaining({body: JSON.stringify({amount: "EUR:5"})})
)
await screen.findByText("give this address to", {exact: false})
@@ -161,7 +161,7 @@ describe("home page", () => {
fireEvent.click(signupButton);
await screen.findByText("has a problem", {exact: false});
expect(fetch).toHaveBeenCalledWith(
- "http://localhost/demobanks/default/testing/register",
+ "http://localhost/demobanks/default/access-api/testing/register",
{body: JSON.stringify({username: username, password: "bar"}), method:
"POST"},
)
})
@@ -174,7 +174,7 @@ describe("home page", () => {
fireEvent.click(signupButton);
await screen.findByText("has a problem", {exact: false});
expect(fetch).toHaveBeenCalledWith(
- "http://localhost/demobanks/default/testing/register",
+ "http://localhost/demobanks/default/access-api/testing/register",
{body: JSON.stringify({username: username, password: "bar"}), method:
"POST"},
)
})
@@ -233,11 +233,11 @@ describe("home page", () => {
* balance was requested after the successful registration.
*/
expect(fetch).toHaveBeenCalledWith(
- "http://localhost/demobanks/default/testing/register",
+ "http://localhost/demobanks/default/access-api/testing/register",
expect.anything() // no need to match auth headers.
)
expect(fetch).toHaveBeenLastCalledWith(
- `http://localhost/demobanks/default/accounts/${username}`,
+ `http://localhost/demobanks/default/access-api/accounts/${username}`,
expect.anything() // no need to match auth headers.
)
})
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-merchant-backoffice] branch master updated (aa05541 -> 8003d41), gnunet, 2021/12/20
- [taler-merchant-backoffice] 03/11: bank tests, gnunet, 2021/12/20
- [taler-merchant-backoffice] 08/11: bank: fix URL, gnunet, 2021/12/20
- [taler-merchant-backoffice] 01/11: bank: implement login, gnunet, 2021/12/20
- [taler-merchant-backoffice] 04/11: bank: fix URL generation,
gnunet <=
- [taler-merchant-backoffice] 10/11: bank: implement withdrawal abort, gnunet, 2021/12/20
- [taler-merchant-backoffice] 02/11: Bank tests., gnunet, 2021/12/20
- [taler-merchant-backoffice] 11/11: bank: test withdrawal abort, gnunet, 2021/12/20
- [taler-merchant-backoffice] 09/11: bank: fix URL, gnunet, 2021/12/20
- [taler-merchant-backoffice] 06/11: remove misplaced comments, gnunet, 2021/12/20
- [taler-merchant-backoffice] 05/11: bank: make tests 'Content-Type' aware, gnunet, 2021/12/20
- [taler-merchant-backoffice] 07/11: bank: fix URL generation, gnunet, 2021/12/20