diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index b3cb776..6078513 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -150,7 +150,10 @@ export const api: API = { } }, - async getUserProjects(token: string): Promise> { + async getUserProjects( + username: string, + token: string, + ): Promise> { try { const response = await fetch("/api/getUserProjects", { method: "GET", @@ -158,6 +161,7 @@ export const api: API = { "Content-Type": "application/json", Authorization: "Bearer " + token, }, + body: JSON.stringify({ username }), }); if (!response.ok) { diff --git a/frontend/src/Components/EditWeeklyReport.tsx b/frontend/src/Components/EditWeeklyReport.tsx index 9321d73..b0e8771 100644 --- a/frontend/src/Components/EditWeeklyReport.tsx +++ b/frontend/src/Components/EditWeeklyReport.tsx @@ -50,8 +50,8 @@ export default function GetWeeklyReport(): JSX.Element { } }; - fetchWeeklyReport(); - }, []); + void fetchWeeklyReport(); + }, [projectName, token, username, week]); const handleNewWeeklyReport = async (): Promise => { const newWeeklyReport: NewWeeklyReport = { diff --git a/frontend/src/Components/NewWeeklyReport.tsx b/frontend/src/Components/NewWeeklyReport.tsx index 4f919aa..0a84b48 100644 --- a/frontend/src/Components/NewWeeklyReport.tsx +++ b/frontend/src/Components/NewWeeklyReport.tsx @@ -1,5 +1,5 @@ import { useState, useContext } from "react"; -import { NewWeeklyReport } from "../Types/goTypes"; +import type { NewWeeklyReport } from "../Types/goTypes"; import { api } from "../API/API"; import { useNavigate } from "react-router-dom"; import Button from "./Button"; diff --git a/frontend/src/Components/UserProjectListAdmin.tsx b/frontend/src/Components/UserProjectListAdmin.tsx index 423e793..69258a1 100644 --- a/frontend/src/Components/UserProjectListAdmin.tsx +++ b/frontend/src/Components/UserProjectListAdmin.tsx @@ -9,7 +9,7 @@ const UserProjectListAdmin: React.FC = () => { const fetchProjects = async (): Promise => { try { const token = localStorage.getItem("accessToken") ?? ""; - const username = getUsernameFromContext(); // Assuming you have a function to get the username from your context + const username = "NoUser"; // getUsernameFromContext(); // Assuming you have a function to get the username from your context const response = await api.getUserProjects(username, token); if (response.success) { diff --git a/frontend/src/Pages/YourProjectsPage.tsx b/frontend/src/Pages/YourProjectsPage.tsx index aabc606..4c6e77f 100644 --- a/frontend/src/Pages/YourProjectsPage.tsx +++ b/frontend/src/Pages/YourProjectsPage.tsx @@ -1,4 +1,4 @@ -import React, { useState, createContext, useEffect } from "react"; +import { useState, createContext, useEffect } from "react"; import { Project } from "../Types/goTypes"; import { api } from "../API/API"; import { Link } from "react-router-dom"; @@ -23,7 +23,7 @@ function UserProjectPage(): JSX.Element { }; // Call getProjects when the component mounts useEffect(() => { - getProjects(); + void getProjects(); }, []); const handleProjectClick = (projectName: string): void => { diff --git a/testing.py b/testing.py index e342598..6381afc 100644 --- a/testing.py +++ b/testing.py @@ -22,13 +22,11 @@ loginPath = base_url + "/api/login" addProjectPath = base_url + "/api/project" submitReportPath = base_url + "/api/submitReport" getWeeklyReportPath = base_url + "/api/getWeeklyReport" -<<<<<<< HEAD getProjectPath = base_url + "/api/project" -======= signReportPath = base_url + "/api/signReport" addUserToProjectPath = base_url + "/api/addUserToProject" promoteToAdminPath = base_url + "/api/promoteToAdmin" ->>>>>>> 9ad89d60636ac6091d71b0bf307982becc9b89fe +getUserProjectsPath = base_url + "/api/getUserProjects" # Posts the username and password to the register endpoint @@ -150,6 +148,16 @@ def test_add_user_to_project(): assert response.status_code == 200, "Add user to project failed" print("Add user to project successful") + # Check if the user is added to the project + response = requests.get( + getUserProjectsPath, + json={"username": new_user}, + headers={"Authorization": "Bearer " + admin_token}, + ) + print(response.text) + assert response.status_code == 200, "Get user projects failed" + print("got user projects successfully") + # Test function to sign a report def test_sign_report(): # Create a project manager user @@ -232,9 +240,6 @@ if __name__ == "__main__": test_add_project() test_submit_report() test_get_weekly_report() -<<<<<<< HEAD test_get_project() -======= test_sign_report() test_add_user_to_project() ->>>>>>> 9ad89d60636ac6091d71b0bf307982becc9b89fe