lint bro happ + test for getUserProject

This commit is contained in:
al8763be 2024-03-18 21:08:33 +01:00
parent 4392b68397
commit 8eb23bf7f9
6 changed files with 22 additions and 13 deletions

View file

@ -150,7 +150,10 @@ export const api: API = {
}
},
async getUserProjects(token: string): Promise<APIResponse<Project[]>> {
async getUserProjects(
username: string,
token: string,
): Promise<APIResponse<Project[]>> {
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) {

View file

@ -50,8 +50,8 @@ export default function GetWeeklyReport(): JSX.Element {
}
};
fetchWeeklyReport();
}, []);
void fetchWeeklyReport();
}, [projectName, token, username, week]);
const handleNewWeeklyReport = async (): Promise<void> => {
const newWeeklyReport: NewWeeklyReport = {

View file

@ -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";

View file

@ -9,7 +9,7 @@ const UserProjectListAdmin: React.FC = () => {
const fetchProjects = async (): Promise<void> => {
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) {

View file

@ -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 => {

View file

@ -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