Merge branch 'melle' into dev
This commit is contained in:
		
						commit
						89ba0415f7
					
				
					 2 changed files with 105 additions and 39 deletions
				
			
		| 
						 | 
					@ -39,7 +39,9 @@ type Database interface {
 | 
				
			||||||
	SignWeeklyReport(reportId int, projectManagerId int) error
 | 
						SignWeeklyReport(reportId int, projectManagerId int) error
 | 
				
			||||||
	IsSiteAdmin(username string) (bool, error)
 | 
						IsSiteAdmin(username string) (bool, error)
 | 
				
			||||||
	IsProjectManager(username string, projectname string) (bool, error)
 | 
						IsProjectManager(username string, projectname string) (bool, error)
 | 
				
			||||||
	GetTotalTimePerActivity(projectName string) (map[string]int, error)
 | 
						GetProjectTimes(projectName string) (map[string]int, error)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This struct is a wrapper type that holds the database connection
 | 
					// This struct is a wrapper type that holds the database connection
 | 
				
			||||||
| 
						 | 
					@ -491,8 +493,8 @@ func (d *Db) MigrateSampleData() error {
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *Db) GetTotalTimePerActivity(projectName string) (map[string]int, error) {
 | 
					// GetProjectTimes retrieves a map with times per "Activity" for a given project
 | 
				
			||||||
 | 
					func (d *Db) GetProjectTimes(projectName string) (map[string]int, error) {
 | 
				
			||||||
    query := `
 | 
					    query := `
 | 
				
			||||||
        SELECT development_time, meeting_time, admin_time, own_work_time, study_time, testing_time
 | 
					        SELECT development_time, meeting_time, admin_time, own_work_time, study_time, testing_time
 | 
				
			||||||
        FROM weekly_reports
 | 
					        FROM weekly_reports
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -729,27 +729,91 @@ func TestIsProjectManager(t *testing.T) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGetTotalTimePerActivity(t *testing.T) {
 | 
					
 | 
				
			||||||
	// Initialize your test database connection
 | 
					func TestGetProjectTimes(t *testing.T) {
 | 
				
			||||||
 | 
					    // Initialize
 | 
				
			||||||
    db, err := setupState()
 | 
					    db, err := setupState()
 | 
				
			||||||
    if err != nil {
 | 
					    if err != nil {
 | 
				
			||||||
        t.Error("setupState failed:", err)
 | 
					        t.Error("setupState failed:", err)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Run the query to get total time per activity
 | 
					    // Create a user
 | 
				
			||||||
	totalTime, err := db.GetTotalTimePerActivity("projecttest")
 | 
					    user := "TeaUser"
 | 
				
			||||||
 | 
					    password := "Vanilla"
 | 
				
			||||||
 | 
					    err = db.AddUser(user, password)
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        t.Error("AddUser failed:", err)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Create a project
 | 
				
			||||||
 | 
					    projectName := "ProjectVanilla"
 | 
				
			||||||
 | 
					    projectDescription := "When tea tastes its best"
 | 
				
			||||||
 | 
					    err = db.AddProject(projectName, projectDescription, user) // Fix the variable name here
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        t.Error("AddProject failed:", err)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Tests the func in db.go
 | 
				
			||||||
 | 
					    totalTime, err := db.GetProjectTimes(projectName)
 | 
				
			||||||
    if err != nil {
 | 
					    if err != nil {
 | 
				
			||||||
        t.Error("GetTotalTimePerActivity failed:", err)
 | 
					        t.Error("GetTotalTimePerActivity failed:", err)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Check if the totalTime map is not nil
 | 
					    // Check if the totalTime map is not nil
 | 
				
			||||||
    if totalTime == nil {
 | 
					    if totalTime == nil {
 | 
				
			||||||
        t.Error("Expected non-nil totalTime map, got nil")
 | 
					        t.Error("Expected non-nil totalTime map, got nil")
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// ska lägga till fler  assertions
 | 
					    // Define the expected valeus
 | 
				
			||||||
}
 | 
					    expectedTotalTime := map[string]int{
 | 
				
			||||||
 | 
					        "development": 0,
 | 
				
			||||||
 | 
					        "meeting": 0,
 | 
				
			||||||
 | 
					        "admin": 0,
 | 
				
			||||||
 | 
					        "own_work": 0,
 | 
				
			||||||
 | 
					        "study": 0,
 | 
				
			||||||
 | 
					        "testing": 0,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Compare the expectedTotalTime with the totalTime retrieved from the database
 | 
				
			||||||
 | 
					    for activity, expectedTime := range expectedTotalTime {
 | 
				
			||||||
 | 
					        if totalTime[activity] != expectedTime {
 | 
				
			||||||
 | 
					            t.Errorf("Expected %s time to be %d, got %d", activity, expectedTime, totalTime[activity])
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						   // Insert some data into the database for different activities
 | 
				
			||||||
 | 
						   err = db.AddWeeklyReport(projectName, user, 1, 1, 3, 2, 1, 4, 5)
 | 
				
			||||||
 | 
						   if err != nil {
 | 
				
			||||||
 | 
							   t.Error("Failed to insert data into the database:", err)
 | 
				
			||||||
 | 
							   return
 | 
				
			||||||
 | 
						   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						newTotalTime, err := db.GetProjectTimes(projectName)
 | 
				
			||||||
 | 
					    if err != nil {
 | 
				
			||||||
 | 
					        t.Error("GetTotalTimePerActivity failed:", err)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						newExpectedTotalTime := map[string]int{
 | 
				
			||||||
 | 
					        "development": 1,
 | 
				
			||||||
 | 
					        "meeting": 3,
 | 
				
			||||||
 | 
					        "admin": 2,
 | 
				
			||||||
 | 
					        "own_work": 1,
 | 
				
			||||||
 | 
					        "study": 4,
 | 
				
			||||||
 | 
					        "testing": 5,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for activity, newExpectedTime := range newExpectedTotalTime {
 | 
				
			||||||
 | 
					        if newTotalTime[activity] != newExpectedTime {
 | 
				
			||||||
 | 
					            t.Errorf("Expected %s time to be %d, got %d", activity, newExpectedTime, newTotalTime[activity])
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
func TestEnsureManagerOfCreatedProject(t *testing.T) {
 | 
					func TestEnsureManagerOfCreatedProject(t *testing.T) {
 | 
				
			||||||
	db, err := setupState()
 | 
						db, err := setupState()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue