Skip to content

Commit

Permalink
Merge branch 'feat/team_project_feature' into feat/integrate_arborist…
Browse files Browse the repository at this point in the history
…_validation_for_team_project
  • Loading branch information
pieterlukasse authored Dec 13, 2023
2 parents cc06ba8 + 6751594 commit e783f33
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
16 changes: 6 additions & 10 deletions models/cohortdefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,15 @@ func (h CohortDefinition) GetAllCohortDefinitionsAndStatsOrderBySizeDesc(sourceI
cohortDefinitionStat.CohortSize)
continue
} else {
cohortDefinitionStat.Name = cohortDefinition.Name
finalList = append(finalList, cohortDefinitionStat)
}
}
// filter to keep only the allowed ones:
filteredFinalList := []*CohortDefinitionStats{}
for _, cohortDefinitionStat := range finalList {
if utils.Contains(allowedCohortDefinitionIds, cohortDefinitionStat.Id) {
filteredFinalList = append(filteredFinalList, cohortDefinitionStat)
// filter to keep only the allowed ones:
if utils.Contains(allowedCohortDefinitionIds, cohortDefinitionStat.Id) {
cohortDefinitionStat.Name = cohortDefinition.Name
finalList = append(finalList, cohortDefinitionStat)
}
}
}

return filteredFinalList, meta_result.Error
return finalList, meta_result.Error
}

func (h CohortDefinition) GetCohortName(cohortId int) (string, error) {
Expand Down
18 changes: 18 additions & 0 deletions tests/models_tests/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,24 @@ func TestGetAllCohortDefinitionsAndStatsOrderBySizeDesc(t *testing.T) {
}
previousSize = cohortDefinition.CohortSize
}

// some extra tests to cover also the teamProject option for this method:
testTeamProject := "teamprojectX"
allowedCohortDefinitions, _ := cohortDefinitionModel.GetAllCohortDefinitionsAndStatsOrderBySizeDesc(testSourceId, testTeamProject)
if len(allowedCohortDefinitions) != 1 {
t.Errorf("Expected teamProject '%s' to have one cohort, but found %d",
testTeamProject, len(allowedCohortDefinitions))
}
if len(cohortDefinitions) <= len(allowedCohortDefinitions) {
t.Errorf("Expected list of projects for '%s' to be larger than for %s",
defaultTeamProject, testTeamProject)
}
testTeamProject = "teamprojectNonExisting"
allowedCohortDefinitions, _ = cohortDefinitionModel.GetAllCohortDefinitionsAndStatsOrderBySizeDesc(testSourceId, testTeamProject)
if len(allowedCohortDefinitions) != 0 {
t.Errorf("Expected teamProject '%s' to have NO cohort, but found %d",
testTeamProject, len(allowedCohortDefinitions))
}
}

// Tests whether the code deals correctly with the (error) situation where
Expand Down

0 comments on commit e783f33

Please sign in to comment.