From f6dcdcc376e2e3276db34959d2f4951e00a4ff6d Mon Sep 17 00:00:00 2001 From: al8763be Date: Thu, 28 Mar 2024 16:40:55 +0100 Subject: [PATCH] GetUnsignedReports --- backend/internal/database/db_test.go | 10 +++++ .../handlers/handlers_report_related.go | 2 +- backend/main.go | 2 +- testing.py | 45 ++----------------- 4 files changed, 15 insertions(+), 44 deletions(-) diff --git a/backend/internal/database/db_test.go b/backend/internal/database/db_test.go index cff70a0..fb394e0 100644 --- a/backend/internal/database/db_test.go +++ b/backend/internal/database/db_test.go @@ -481,6 +481,11 @@ func TestGetUnsignedWeeklyReports(t *testing.T) { t.Error("AddUser failed:", err) } + err = db.AddUser("testuser1", "password") + if err != nil { + t.Error("AddUser failed:", err) + } + err = db.AddProject("testproject", "description", "testuser") if err != nil { t.Error("AddProject failed:", err) @@ -491,6 +496,11 @@ func TestGetUnsignedWeeklyReports(t *testing.T) { t.Error("AddWeeklyReport failed:", err) } + err = db.AddWeeklyReport("testproject", "testuser1", 1, 1, 1, 1, 1, 1, 1) + if err != nil { + t.Error("AddWeeklyReport failed:", err) + } + reports, err := db.GetUnsignedWeeklyReports("testproject") if err != nil { t.Error("GetUnsignedWeeklyReports failed:", err) diff --git a/backend/internal/handlers/handlers_report_related.go b/backend/internal/handlers/handlers_report_related.go index 534050a..5ac49b0 100644 --- a/backend/internal/handlers/handlers_report_related.go +++ b/backend/internal/handlers/handlers_report_related.go @@ -122,7 +122,7 @@ func (gs *GState) GetUnsignedReports(c *fiber.Ctx) error { projectManagerUsername := claims["name"].(string) // Extract project name and week from query parameters - projectName := c.Query("projectName") + projectName := c.Params("projectName") log.Info("Getting unsigned reports for") diff --git a/backend/main.go b/backend/main.go index 835524c..dc5b86b 100644 --- a/backend/main.go +++ b/backend/main.go @@ -92,7 +92,7 @@ func main() { server.Get("/api/project/:projectId", gs.GetProject) server.Get("/api/project/getAllUsers", gs.GetAllUsersProject) server.Get("/api/getWeeklyReport", gs.GetWeeklyReport) - server.Get("/api/getUnsignedReports", gs.GetUnsignedReports) + server.Get("/api/getUnsignedReports/:projectName", gs.GetUnsignedReports) server.Post("/api/signReport", gs.SignReport) server.Put("/api/addUserToProject", gs.AddUserToProjectHandler) server.Put("/api/changeUserName", gs.ChangeUserName) diff --git a/testing.py b/testing.py index 3350497..ca23e78 100644 --- a/testing.py +++ b/testing.py @@ -2,7 +2,7 @@ import requests import string import random -debug_output = False +debug_output = True def gprint(*args, **kwargs): print("\033[92m", *args, "\033[00m", **kwargs) @@ -41,7 +41,7 @@ getWeeklyReportsUserPath = base_url + "/api/getWeeklyReportsUser" checkIfProjectManagerPath = base_url + "/api/checkIfProjectManager" ProjectRoleChangePath = base_url + "/api/ProjectRoleChange" getUsersProjectPath = base_url + "/api/getUsersProject" -getUsignedReportsPath = base_url + "/api/getUsignedReports" +getUnsignedReportsPath = base_url + "/api/getUnsignedReports" #ta bort auth i handlern för att få testet att gå igenom def test_ProjectRoleChange(): @@ -330,45 +330,6 @@ def test_get_weekly_reports_user(): assert response.status_code == 200, "Get weekly reports for user failed" gprint("test_get_weekly_reports_user successful") -def test_get_usigned_reports(): - # Log in as the user - - token = login(username, "always_same").json()["token"] - response = requests.post( - submitReportPath, - json={ - "projectName": projectName, - "week": 3, - "developmentTime": 10, - "meetingTime": 5, - "adminTime": 5, - "ownWorkTime": 10, - "studyTime": 10, - "testingTime": 10, - }, - headers={"Authorization": "Bearer " + token}, - ) - dprint(response.text) - assert response.status_code == 200, "Submit report failed" - - - # Get weekly reports for the user in the project - response = requests.get( - getWeeklyReportsUserPath + "/" + projectName, - headers={"Authorization": "Bearer " + token}, - ) - - dprint(response.text) - assert response.status_code == 200, "Get weekly reports for user failed" - - response = requests.get( - getUsignedReportsPath + "/" + projectName, - headers={"Authorization": "Bearer " + token}, - ) - dprint(response.text) - assert response.status_code == 200, "Get unsigned reports for user failed" - gprint("test_get_usigned_reports successful") - # Test function to check if a user is a project manager @@ -411,7 +372,6 @@ def test_ensure_manager_of_created_project(): if __name__ == "__main__": - test_get_usigned_reports() test_get_user_projects() test_create_user() test_login() @@ -426,3 +386,4 @@ if __name__ == "__main__": test_ProjectRoleChange() #test_list_all_users_project() test_ensure_manager_of_created_project() + test_get_unsigned_reports()