From 3525598df25cacb0d65e04a2b366d7dd1442039f Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 20 Mar 2024 18:47:37 +0100 Subject: [PATCH] Tests for AddProject to ensure creator is Manager --- backend/internal/database/db_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/backend/internal/database/db_test.go b/backend/internal/database/db_test.go index 6757522..e834135 100644 --- a/backend/internal/database/db_test.go +++ b/backend/internal/database/db_test.go @@ -711,3 +711,31 @@ func TestChangeUserName(t *testing.T) { t.Error("Expected GetUserId to fail for the old name, but it didn't") } } + +func TestEnsureManagerOfCreatedProject(t *testing.T) { + db, err := setupState() + if err != nil { + t.Error("setupState failed:", err) + } + + // Add a user + err = db.AddUser("testuser", "password") + if err != nil { + t.Error("AddUser failed:", err) + } + + // Add a project + err = db.AddProject("testproject", "description", "testuser") + if err != nil { + t.Error("AddProject failed:", err) + } + + managerState, err := db.IsProjectManager("testuser", "testproject") + if err != nil { + t.Error("IsProjectManager failed:", err) + } + + if !managerState { + t.Error("Expected testuser to be a project manager, but it's not.") + } +}