Merge branch 'johanna-testing' into dev
This commit is contained in:
commit
ef6c3951fd
6 changed files with 91 additions and 4 deletions
|
@ -130,4 +130,12 @@ install-just:
|
||||||
|
|
||||||
.PHONY: types
|
.PHONY: types
|
||||||
types:
|
types:
|
||||||
tygo generate
|
tygo generate
|
||||||
|
|
||||||
|
.PHONY: install-golds
|
||||||
|
install-golds:
|
||||||
|
go install go101.org/golds@latest
|
||||||
|
|
||||||
|
.PHONY: golds
|
||||||
|
golds:
|
||||||
|
golds -port 6060 -nouses -plainsrc -wdpkgs-listing=promoted ./...
|
||||||
|
|
|
@ -5,8 +5,12 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TestNewConfig tests the creation of a new configuration object
|
||||||
func TestNewConfig(t *testing.T) {
|
func TestNewConfig(t *testing.T) {
|
||||||
|
// Arrange
|
||||||
c := NewConfig()
|
c := NewConfig()
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
if c.Port != 8080 {
|
if c.Port != 8080 {
|
||||||
t.Errorf("Expected port to be 8080, got %d", c.Port)
|
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) {
|
func TestWriteConfig(t *testing.T) {
|
||||||
|
// Arrange
|
||||||
c := NewConfig()
|
c := NewConfig()
|
||||||
|
|
||||||
|
//Act
|
||||||
err := c.WriteConfigToFile("test.toml")
|
err := c.WriteConfigToFile("test.toml")
|
||||||
|
|
||||||
|
// Assert
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected no error, got %s", err)
|
t.Errorf("Expected no error, got %s", err)
|
||||||
}
|
}
|
||||||
|
@ -35,14 +45,23 @@ func TestWriteConfig(t *testing.T) {
|
||||||
_ = os.Remove("test.toml")
|
_ = os.Remove("test.toml")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestReadConfig tests the function to read the configuration from a file
|
||||||
func TestReadConfig(t *testing.T) {
|
func TestReadConfig(t *testing.T) {
|
||||||
|
// Arrange
|
||||||
c := NewConfig()
|
c := NewConfig()
|
||||||
|
|
||||||
|
// Act
|
||||||
err := c.WriteConfigToFile("test.toml")
|
err := c.WriteConfigToFile("test.toml")
|
||||||
|
|
||||||
|
// Assert
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected no error, got %s", err)
|
t.Errorf("Expected no error, got %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Act
|
||||||
c2, err := ReadConfigFromFile("test.toml")
|
c2, err := ReadConfigFromFile("test.toml")
|
||||||
|
|
||||||
|
// Assert
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected no error, got %s", err)
|
t.Errorf("Expected no error, got %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
// Tests are not guaranteed to be sequential
|
// Tests are not guaranteed to be sequential
|
||||||
|
|
||||||
|
// setupState initializes a database instance with necessary setup for testing
|
||||||
func setupState() (Database, error) {
|
func setupState() (Database, error) {
|
||||||
db := DbConnect(":memory:")
|
db := DbConnect(":memory:")
|
||||||
err := db.Migrate()
|
err := db.Migrate()
|
||||||
|
@ -16,11 +17,13 @@ func setupState() (Database, error) {
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestDbConnect tests the connection to the database
|
||||||
func TestDbConnect(t *testing.T) {
|
func TestDbConnect(t *testing.T) {
|
||||||
db := DbConnect(":memory:")
|
db := DbConnect(":memory:")
|
||||||
_ = db
|
_ = db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestDbAddUser tests the AddUser function of the database
|
||||||
func TestDbAddUser(t *testing.T) {
|
func TestDbAddUser(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestDbGetUserId(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestDbAddProject(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestDbRemoveUser(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestPromoteToAdmin(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestAddWeeklyReport(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestAddUserToProject(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestChangeUserRole(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestGetAllUsersProject(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestGetAllUsersApplication(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestGetProjectsForUser(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -338,6 +351,7 @@ func TestGetProjectsForUser(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestAddProject tests AddProject function of the database
|
||||||
func TestAddProject(t *testing.T) {
|
func TestAddProject(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -373,6 +387,7 @@ func TestAddProject(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestGetWeeklyReport tests GetWeeklyReport function of the database
|
||||||
func TestGetWeeklyReport(t *testing.T) {
|
func TestGetWeeklyReport(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -412,6 +427,7 @@ func TestGetWeeklyReport(t *testing.T) {
|
||||||
// Check other fields similarly
|
// Check other fields similarly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestSignWeeklyReport tests SignWeeklyReport function of the database
|
||||||
func TestSignWeeklyReport(t *testing.T) {
|
func TestSignWeeklyReport(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
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) {
|
func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -537,6 +554,7 @@ func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestGetProject tests GetProject function of the database
|
||||||
func TestGetProject(t *testing.T) {
|
func TestGetProject(t *testing.T) {
|
||||||
db, err := setupState()
|
db, err := setupState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
38
frontend/src/Components/ChangeUsername.tsx
Normal file
38
frontend/src/Components/ChangeUsername.tsx
Normal file
|
@ -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<HTMLInputElement>): void => {
|
||||||
|
setNewUsername(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (): Promise<void> => {
|
||||||
|
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 (
|
||||||
|
<div>
|
||||||
|
<InputField
|
||||||
|
label="New Username"
|
||||||
|
type="text"
|
||||||
|
value={newUsername}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ChangeUsername;
|
|
@ -1,9 +1,14 @@
|
||||||
import BackButton from "../../Components/BackButton";
|
import BackButton from "../../Components/BackButton";
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
import BasicWindow from "../../Components/BasicWindow";
|
||||||
import Button from "../../Components/Button";
|
import Button from "../../Components/Button";
|
||||||
|
import ChangeUsername from "../../Components/ChangeUsername";
|
||||||
|
|
||||||
function AdminChangeUsername(): JSX.Element {
|
function AdminChangeUsername(): JSX.Element {
|
||||||
const content = <></>;
|
const content = (
|
||||||
|
<>
|
||||||
|
<ChangeUsername />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
const buttons = (
|
const buttons = (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { useState, createContext, useEffect } from "react";
|
import { useState, createContext } from "react";
|
||||||
import { Project } from "../Types/goTypes";
|
import { Project } from "../Types/goTypes";
|
||||||
import { api } from "../API/API";
|
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import BasicWindow from "../Components/BasicWindow";
|
import BasicWindow from "../Components/BasicWindow";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue