diff --git a/backend/Makefile b/backend/Makefile index 65a2f3c..331f8d5 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -130,4 +130,12 @@ install-just: .PHONY: types types: - tygo generate \ No newline at end of file + tygo generate + +.PHONY: install-golds +install-golds: + go install go101.org/golds@latest + +.PHONY: golds +golds: + golds -port 6060 -nouses -plainsrc -wdpkgs-listing=promoted ./... diff --git a/backend/internal/config/config_test.go b/backend/internal/config/config_test.go index cb02a31..e8ddce8 100644 --- a/backend/internal/config/config_test.go +++ b/backend/internal/config/config_test.go @@ -5,8 +5,12 @@ import ( "testing" ) +// TestNewConfig tests the creation of a new configuration object func TestNewConfig(t *testing.T) { + // Arrange c := NewConfig() + + // Act & Assert if c.Port != 8080 { t.Errorf("Expected port to be 8080, got %d", c.Port) } @@ -24,9 +28,15 @@ func TestNewConfig(t *testing.T) { } } +// TestWriteConfig tests the function to write the configuration to a file func TestWriteConfig(t *testing.T) { + // Arrange c := NewConfig() + + //Act err := c.WriteConfigToFile("test.toml") + + // Assert if err != nil { t.Errorf("Expected no error, got %s", err) } @@ -35,14 +45,23 @@ func TestWriteConfig(t *testing.T) { _ = os.Remove("test.toml") } +// TestReadConfig tests the function to read the configuration from a file func TestReadConfig(t *testing.T) { + // Arrange c := NewConfig() + + // Act err := c.WriteConfigToFile("test.toml") + + // Assert if err != nil { t.Errorf("Expected no error, got %s", err) } + // Act c2, err := ReadConfigFromFile("test.toml") + + // Assert if err != nil { t.Errorf("Expected no error, got %s", err) } diff --git a/backend/internal/database/db_test.go b/backend/internal/database/db_test.go index 2448e7e..3b18abb 100644 --- a/backend/internal/database/db_test.go +++ b/backend/internal/database/db_test.go @@ -7,6 +7,7 @@ import ( // Tests are not guaranteed to be sequential +// setupState initializes a database instance with necessary setup for testing func setupState() (Database, error) { db := DbConnect(":memory:") err := db.Migrate() @@ -16,11 +17,13 @@ func setupState() (Database, error) { return db, nil } +// TestDbConnect tests the connection to the database func TestDbConnect(t *testing.T) { db := DbConnect(":memory:") _ = db } +// TestDbAddUser tests the AddUser function of the database func TestDbAddUser(t *testing.T) { db, err := setupState() if err != nil { @@ -32,6 +35,7 @@ func TestDbAddUser(t *testing.T) { } } +// TestDbGetUserId tests the GetUserID function of the database func TestDbGetUserId(t *testing.T) { db, err := setupState() if err != nil { @@ -52,6 +56,7 @@ func TestDbGetUserId(t *testing.T) { } } +// TestDbAddProject tests the AddProject function of the database func TestDbAddProject(t *testing.T) { db, err := setupState() if err != nil { @@ -64,6 +69,7 @@ func TestDbAddProject(t *testing.T) { } } +// TestDbRemoveUser tests the RemoveUser function of the database func TestDbRemoveUser(t *testing.T) { db, err := setupState() if err != nil { @@ -76,6 +82,7 @@ func TestDbRemoveUser(t *testing.T) { } } +// TestPromoteToAdmin tests the PromoteToAdmin function of the database func TestPromoteToAdmin(t *testing.T) { db, err := setupState() if err != nil { @@ -93,6 +100,7 @@ func TestPromoteToAdmin(t *testing.T) { } } +// TestAddWeeklyReport tests the AddWeeklyReport function of the database func TestAddWeeklyReport(t *testing.T) { db, err := setupState() if err != nil { @@ -115,6 +123,7 @@ func TestAddWeeklyReport(t *testing.T) { } } +// TestAddUserToProject tests the AddUseToProject function of the database func TestAddUserToProject(t *testing.T) { db, err := setupState() if err != nil { @@ -142,6 +151,7 @@ func TestAddUserToProject(t *testing.T) { } } +// TestChangeUserRole tests the ChangeUserRole function of the database func TestChangeUserRole(t *testing.T) { db, err := setupState() if err != nil { @@ -186,6 +196,7 @@ func TestChangeUserRole(t *testing.T) { } +// TestGetAllUsersProject tests the GetAllUsersProject function of the database func TestGetAllUsersProject(t *testing.T) { db, err := setupState() if err != nil { @@ -252,6 +263,7 @@ func TestGetAllUsersProject(t *testing.T) { } } +// TestGetAllUsersApplication tests the GetAllUsersApplicsation function of the database func TestGetAllUsersApplication(t *testing.T) { db, err := setupState() if err != nil { @@ -298,6 +310,7 @@ func TestGetAllUsersApplication(t *testing.T) { } } +// TestGetProjectsForUser tests the GetProjectsForUser function of the database func TestGetProjectsForUser(t *testing.T) { db, err := setupState() if err != nil { @@ -338,6 +351,7 @@ func TestGetProjectsForUser(t *testing.T) { } } +// TestAddProject tests AddProject function of the database func TestAddProject(t *testing.T) { db, err := setupState() if err != nil { @@ -373,6 +387,7 @@ func TestAddProject(t *testing.T) { } } +// TestGetWeeklyReport tests GetWeeklyReport function of the database func TestGetWeeklyReport(t *testing.T) { db, err := setupState() if err != nil { @@ -412,6 +427,7 @@ func TestGetWeeklyReport(t *testing.T) { // Check other fields similarly } +// TestSignWeeklyReport tests SignWeeklyReport function of the database func TestSignWeeklyReport(t *testing.T) { db, err := setupState() if err != nil { @@ -484,6 +500,7 @@ func TestSignWeeklyReport(t *testing.T) { } } +// TestSignWeeklyReportByAnotherProjectManager tests the scenario where a project manager attempts to sign a weekly report for a user who is not assigned to their project func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) { db, err := setupState() if err != nil { @@ -537,6 +554,7 @@ func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) { } } +// TestGetProject tests GetProject function of the database func TestGetProject(t *testing.T) { db, err := setupState() if err != nil { diff --git a/frontend/src/Components/ChangeUsername.tsx b/frontend/src/Components/ChangeUsername.tsx new file mode 100644 index 0000000..71d5e57 --- /dev/null +++ b/frontend/src/Components/ChangeUsername.tsx @@ -0,0 +1,38 @@ +import React, { useState } from "react"; +import { api } from "../API/API"; +import InputField from "./InputField"; +import BackButton from "./BackButton"; +import Button from "./Button"; + + +function ChangeUsername(): JSX.Element { + const [newUsername, setNewUsername] = useState(""); + + const handleChange = (e: React.ChangeEvent): void => { + setNewUsername(e.target.value); + }; + + const handleSubmit = async (): Promise => { + try { + // Call the API function to update the username + await api.updateUsername(newUsername); + // Optionally, add a success message or redirect the user + } catch (error) { + console.error("Error updating username:", error); + // Optionally, handle the error + } + }; + + return ( +
+ +
+ ); +} + +export default ChangeUsername; diff --git a/frontend/src/Pages/AdminPages/AdminChangeUsername.tsx b/frontend/src/Pages/AdminPages/AdminChangeUsername.tsx index 7eb2e2e..b130fae 100644 --- a/frontend/src/Pages/AdminPages/AdminChangeUsername.tsx +++ b/frontend/src/Pages/AdminPages/AdminChangeUsername.tsx @@ -1,9 +1,14 @@ import BackButton from "../../Components/BackButton"; import BasicWindow from "../../Components/BasicWindow"; import Button from "../../Components/Button"; +import ChangeUsername from "../../Components/ChangeUsername"; function AdminChangeUsername(): JSX.Element { - const content = <>; + const content = ( + <> + + + ); const buttons = ( <> diff --git a/frontend/src/Pages/YourProjectsPage.tsx b/frontend/src/Pages/YourProjectsPage.tsx index a3cd47a..0f2428e 100644 --- a/frontend/src/Pages/YourProjectsPage.tsx +++ b/frontend/src/Pages/YourProjectsPage.tsx @@ -1,6 +1,5 @@ -import { useState, createContext, useEffect } from "react"; +import { useState, createContext } from "react"; import { Project } from "../Types/goTypes"; -import { api } from "../API/API"; import { Link } from "react-router-dom"; import BasicWindow from "../Components/BasicWindow";