merchant-backoffice

ZZZ: Inactive/Deprecated
Log | Files | Refs | Submodules | README

commit 2981b6e16925af7a40caa25c3a8d7c741e0630c3
parent de67d9daef0b8f8fc444f8ce6f6e3525c536e9f0
Author: ms <ms@taler.net>
Date:   Sun, 19 Dec 2021 09:09:17 +0100

bank tests

mocking Sandbox default 'demobank' base URL

Diffstat:
Mpackages/bank/src/pages/home/index.tsx | 8++++----
Mpackages/bank/tests/__tests__/homepage.js | 22++++++++++++++++++----
2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx @@ -171,7 +171,7 @@ async function confirmWithdrawalCall( `Basic ${Buffer.from(backendState.username + ":" + backendState.password).toString("base64")}` ); var res = await fetch( - `${backendState.url}accounts/${backendState.username}/withdrawals/confirm`, { + `${backendState.url}/accounts/${backendState.username}/withdrawals/confirm`, { method: 'POST', headers: headers }) @@ -242,7 +242,7 @@ async function createWithdrawalCall( `Basic ${Buffer.from(backendState.username + ":" + backendState.password).toString("base64")}` ); var res = await fetch( - `${backendState.url}accounts/${backendState.username}/withdrawals`, { + `${backendState.url}/accounts/${backendState.username}/withdrawals`, { method: 'POST', headers: headers, body: JSON.stringify({amount: amount}), @@ -324,7 +324,7 @@ async function registrationCall( let headersNoCache = new Headers(); try { var res = await fetch( - `${baseUrl}testing/register`, { + `${baseUrl}/testing/register`, { method: 'POST', body: JSON.stringify(req), }); @@ -362,7 +362,7 @@ async function registrationCall( */ function Account(props: any) { const { withdrawalOutcome, talerWithdrawUri, accountLabel } = props; - const { data, error } = useSWR(`accounts/${props.accountLabel}`); + const { data, error } = useSWR(`/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 @@ -7,6 +7,16 @@ import { waitFor, cleanup, render, fireEvent, screen } from '@testing-library/pr import expect from 'expect'; import fetchMock from "jest-fetch-mock"; + +beforeAll(() => { + Object.defineProperty(window, 'location', { + value: { + origin: "http://localhost", + pathname: "/demobanks/default" + } + }) +}) + /** * Insert username and password into the registration * form and returns the submit button. NOTE: the username @@ -86,7 +96,7 @@ describe("withdraw", () => { */ fireEvent.click(withdrawButton); expect(fetch).toHaveBeenCalledWith( - `http://localhost/accounts/${context.username}/withdrawals`, + `http://localhost/demobanks/default/accounts/${context.username}/withdrawals`, expect.objectContaining({body: JSON.stringify({amount: "EUR:5"})}) ) await screen.findByText("give this address to", {exact: false}) @@ -151,7 +161,7 @@ describe("home page", () => { fireEvent.click(signupButton); await screen.findByText("has a problem", {exact: false}); expect(fetch).toHaveBeenCalledWith( - "http://localhost/testing/register", + "http://localhost/demobanks/default/testing/register", {body: JSON.stringify({username: username, password: "bar"}), method: "POST"}, ) }) @@ -164,7 +174,7 @@ describe("home page", () => { fireEvent.click(signupButton); await screen.findByText("has a problem", {exact: false}); expect(fetch).toHaveBeenCalledWith( - "http://localhost/testing/register", + "http://localhost/demobanks/default/testing/register", {body: JSON.stringify({username: username, password: "bar"}), method: "POST"}, ) }) @@ -222,8 +232,12 @@ describe("home page", () => { * The expectation below tests whether the account * balance was requested after the successful registration. */ + expect(fetch).toHaveBeenCalledWith( + "http://localhost/demobanks/default/testing/register", + expect.anything() // no need to match auth headers. + ) expect(fetch).toHaveBeenLastCalledWith( - `http://localhost/accounts/${username}`, + `http://localhost/demobanks/default/accounts/${username}`, expect.anything() // no need to match auth headers. ) })