commit f0e1944ffd82d1d6a8093230a590a6762a13bc6b
parent 7a0ac77386f46eaf0064b00737dc02df73cea5e0
Author: ms <ms@taler.net>
Date: Wed, 15 Dec 2021 13:34:51 +0100
bank: test register 404 case
Diffstat:
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx
@@ -181,6 +181,7 @@ async function registrationCall(
return;
}
if (!res.ok) {
+ console.log(`New registration gave response error (${res.status})`, res.statusText);
pageStateSetter((prevState) => ({ ...prevState, hasProblem: true }));
} else {
console.log("Credentials are valid");
diff --git a/packages/bank/tests/__tests__/homepage.js b/packages/bank/tests/__tests__/homepage.js
@@ -12,17 +12,42 @@ beforeEach(() => {
fetch.resetMocks();
});
+// Insert username and password into the registration
+// form and returns the submit button.
+function fillRegistrationForm() {
+ const u = screen.getByPlaceholderText("username");
+ const p = screen.getByPlaceholderText("password");
+ fireEvent.input(u, {target: {value: "foo"}})
+ fireEvent.input(p, {target: {value: "bar"}})
+ return screen.getByText("Submit");
+}
+
describe("home page", () => {
- test("new registration failure", async () => {
+ // check page informs about the current balance
+ // after a successful registration.
+
+ test("new registration response error 404", async () => {
+ render(<BankHome />);
+ let submitButton = fillRegistrationForm();
+ fetch.mockResponseOnce("Not found", {status: 404})
+ fireEvent.click(submitButton);
+ await screen.findByText("has a problem", {exact: false});
+ expect(fetch).toHaveBeenCalledWith(
+ "http://localhost/testing/register",
+ {body: JSON.stringify({username: "foo", password: "bar"}), method: "POST"},
+ )
+ })
+
+ test("new registration network failure", async () => {
render(<BankHome />);
- const u = screen.getByPlaceholderText("username");
- const p = screen.getByPlaceholderText("password");
- fireEvent.input(u, {target: {value: "foo"}})
- fireEvent.input(p, {target: {value: "bar"}})
+ let submitButton = fillRegistrationForm();
// Mocking network failure.
fetch.mockReject("API is down");
- const s = screen.getByText("Submit");
- fireEvent.click(s);
+ fireEvent.click(submitButton);
await screen.findByText("has a problem", {exact: false});
+ expect(fetch).toHaveBeenCalledWith(
+ "http://localhost/testing/register",
+ {body: JSON.stringify({username: "foo", password: "bar"}), method: "POST"},
+ )
})
})