diff --git a/src/App.tsx b/src/App.tsx index 6265b4e..f87c7a8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,8 +5,7 @@ import OtpPage from "./pages/OtpPage"; import DashboardPage from "./pages/DashboardPage"; import Header from "./components/Header"; import "./App.css"; -import 'react-toastify/dist/ReactToastify.css'; - +import "react-toastify/dist/ReactToastify.css"; const App: React.FC = () => { return ( diff --git a/src/__tests__/Register.test.tsx b/src/__tests__/Register.test.tsx index 0d5c6cf..b0d4269 100644 --- a/src/__tests__/Register.test.tsx +++ b/src/__tests__/Register.test.tsx @@ -3,12 +3,15 @@ import Register from "../pages/RegisterPage"; import "@testing-library/jest-dom"; import { MemoryRouter } from "react-router-dom"; import { describe, it, beforeEach, vi, expect } from "vitest"; +import { toast } from "react-toastify"; describe("Register component", () => { beforeEach(() => { vi.clearAllMocks(); // Clear mocks before each test window.alert = vi.fn(); - vi.spyOn(window, "alert").mockImplementation(() => {}); + // Mock the toast.success and toast.error methods to return a mock ID (string or number) + vi.spyOn(toast, "success").mockImplementation(() => "mock-toast-id"); + vi.spyOn(toast, "error").mockImplementation(() => "mock-toast-id"); }); const renderWithRouter = (component: React.ReactNode) => { @@ -28,7 +31,7 @@ describe("Register component", () => { fireEvent.click(sendOTPButton); // Wait for the alert to be shown - await waitFor(() => expect(window.alert).toHaveBeenCalledTimes(1)); + await waitFor(() => expect(toast.error).toHaveBeenCalledTimes(1)); }); it("displays error message on invalid phone number", async () => { @@ -42,7 +45,7 @@ describe("Register component", () => { fireEvent.click(sendOTPButton); await waitFor(() => - expect(window.alert).toHaveBeenCalledWith( + expect(toast.error).toHaveBeenCalledWith( "Please enter a valid phone number.", ), ); diff --git a/src/pages/OtpPage.tsx b/src/pages/OtpPage.tsx index e4970a2..2992a6c 100644 --- a/src/pages/OtpPage.tsx +++ b/src/pages/OtpPage.tsx @@ -4,7 +4,6 @@ import { useNavigate, useLocation } from "react-router-dom"; import { RequestToValidateOTP } from "../services/keyManagement/requestService.ts"; import { toast, ToastContainer } from "react-toastify"; - const Otp = () => { const navigate = useNavigate(); const location = useLocation(); @@ -26,7 +25,7 @@ const Otp = () => { if (response.split(" ")[0] === "Registration") { toast.success("Registration successful"); - // Simulate an async action (e.g., sending OTP) + // Simulate an async action (e.g., sending OTP) await new Promise((resolve) => setTimeout(resolve, 2000)); navigate("/dashboard"); } else { diff --git a/src/services/keyManagement/apiService.ts b/src/services/keyManagement/apiService.ts index 602b149..53d738e 100644 --- a/src/services/keyManagement/apiService.ts +++ b/src/services/keyManagement/apiService.ts @@ -21,8 +21,8 @@ export const sendOTP = async ( try { // Send the post request to the backend const response = await axios.post( - // `${envVariables.VITE_BACKEND_URL}/api/otp/send`, - 'http://localhost:8080/api/otp/send', + `${envVariables.VITE_BACKEND_URL}/api/otp/send`, + // 'http://localhost:8080/api/otp/send', requestBody, { headers }, ); @@ -56,8 +56,8 @@ export const validateOTP = async ( try { // Send the post request to the backend const response = await axios.post( - // `${envVariables.VITE_BACKEND_URL}/api/otp/validate`, - "http://localhost:8080/api/otp/validate", + `${envVariables.VITE_BACKEND_URL}/api/otp/validate`, + // "http://localhost:8080/api/otp/validate", requestBody, { headers }, ); @@ -70,4 +70,4 @@ export const validateOTP = async ( throw new Error("Incorrect OTP"); } }; -export const getAccountId = () => accountId; \ No newline at end of file +export const getAccountId = () => accountId;