Skip to content

Commit

Permalink
fix: fix tests and compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlukasse committed Jan 10, 2025
1 parent 151b59f commit 02f6f00
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
11 changes: 8 additions & 3 deletions tests/controllers_tests/controllers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func (h dummyCohortDataModel) RetrieveHistogramDataBySourceIdAndCohortIdAndConce
return cohortData, nil
}

func (h dummyCohortDataModel) RetrieveHistogramDataBySourceIdAndCohortIdAndConceptDefsPlusCohortPairs(sourceId int, cohortDefinitionId int, histogramConceptId int64, filterConceptDefsAndCohortPairs []interface{}) ([]*models.PersonConceptAndValue, error) {
cohortData := []*models.PersonConceptAndValue{}
return cohortData, nil
}

func (h dummyCohortDataModel) RetrieveHistogramDataBySourceIdAndConceptId(sourceId int, histogramConceptId int64) ([]*models.PersonConceptAndValue, error) {

cohortData := []*models.PersonConceptAndValue{}
Expand Down Expand Up @@ -907,13 +912,13 @@ func TestGetAttritionRowForConceptIdsAndCohortPairs(t *testing.T) {

// mix of concept ids and CustomDichotomousVariableDef items:
conceptIdsAndCohortPairs := []interface{}{
utils.CustomConceptVariableDef{ConceptId: int64(1234), ConceptValues: []int64{}},
utils.CustomConceptVariableDef{ConceptId: int64(5678), ConceptValues: []int64{}},
utils.CustomConceptVariableDef{ConceptId: int64(1234)},
utils.CustomConceptVariableDef{ConceptId: int64(5678)},
utils.CustomDichotomousVariableDef{
CohortDefinitionId1: 1,
CohortDefinitionId2: 2,
ProvidedName: "testA12"},
utils.CustomConceptVariableDef{ConceptId: int64(2090006880), ConceptValues: []int64{}},
utils.CustomConceptVariableDef{ConceptId: int64(2090006880)},
utils.CustomDichotomousVariableDef{
CohortDefinitionId1: 3,
CohortDefinitionId2: 4,
Expand Down
31 changes: 26 additions & 5 deletions tests/utils_tests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestParsePrefixedConceptIdsAndDichotomousIds(t *testing.T) {
requestContext.Writer = new(tests.CustomResponseWriter)
requestContext.Request = new(http.Request)
requestBody := "{\"variables\":[{\"variable_type\": \"concept\", \"concept_id\": 2000000324}," +
"{\"variable_type\": \"concept\", \"concept_id\": 2000000123, \"values\": [2000000237, 2000000238]}," +
"{\"variable_type\": \"concept\", \"concept_id\": 2000000123, \"filters\": [{\"type\": \"in\", \"values_as_concept_ids\": [2000000237, 2000000238]}]}," +
"{\"variable_type\": \"custom_dichotomous\", \"provided_name\": \"test\", \"cohort_ids\": [1, 3]}]}"
requestContext.Request.Body = io.NopCloser(strings.NewReader(requestBody))

Expand All @@ -60,9 +60,20 @@ func TestParsePrefixedConceptIdsAndDichotomousIds(t *testing.T) {
t.Errorf("Did not expect this request to abort")
}

expectedPrefixedConceptDefs := []utils.CustomConceptVariableDef{{ConceptId: 2000000324, ConceptValues: []int64{}}, {ConceptId: 2000000123, ConceptValues: []int64{2000000237, 2000000238}}}
expectedPrefixedConceptDefs := []utils.CustomConceptVariableDef{
{ConceptId: 2000000324},
{ConceptId: 2000000123,
Filters: []utils.Filter{
{
Type: "in",
ValuesAsConceptIds: []int64{2000000237, 2000000238},
},
},
},
}

if !reflect.DeepEqual(conceptDefs, expectedPrefixedConceptDefs) {
t.Errorf("Expected %d but found %d", expectedPrefixedConceptDefs, conceptDefs)
t.Errorf("Expected %v but found %v", expectedPrefixedConceptDefs, conceptDefs)
}

expectedCohortPairs := []utils.CustomDichotomousVariableDef{
Expand Down Expand Up @@ -336,7 +347,7 @@ func TestGenerateStatsData(t *testing.T) {
func TestConvertConceptIdToCustomConceptVariablesDef(t *testing.T) {
setUp(t)

expectedResult := []utils.CustomConceptVariableDef{{ConceptId: 1234, ConceptValues: []int64{}}, {ConceptId: 5678, ConceptValues: []int64{}}}
expectedResult := []utils.CustomConceptVariableDef{{ConceptId: 1234}, {ConceptId: 5678}}
conceptIds := []int64{1234, 5678}
result := utils.ConvertConceptIdToCustomConceptVariablesDef(conceptIds)

Expand All @@ -348,7 +359,17 @@ func TestConvertConceptIdToCustomConceptVariablesDef(t *testing.T) {
func TestExtractConceptIdsFromCustomConceptVariablesDef(t *testing.T) {
setUp(t)

var testData = []utils.CustomConceptVariableDef{{ConceptId: 1234, ConceptValues: []int64{7890}}, {ConceptId: 5678, ConceptValues: []int64{}}}
var testData = []utils.CustomConceptVariableDef{
{ConceptId: 1234,
Filters: []utils.Filter{
{
Type: "in",
ValuesAsConceptIds: []int64{7890},
},
},
},
{ConceptId: 5678},
}
expectedResult := []int64{1234, 5678}
result := utils.ExtractConceptIdsFromCustomConceptVariablesDef(testData)
if !reflect.DeepEqual(expectedResult, result) {
Expand Down
2 changes: 1 addition & 1 deletion utils/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type Filter struct {
Value *float64 `json:"value,omitempty"`
Values []float64 `json:"values,omitempty"`
ValueAsConceptId *int64 `json:"value_as_concept_id,omitempty"`
ValuesAsConceptIds []int64 `json:"values_as_concept_id,omitempty"`
ValuesAsConceptIds []int64 `json:"values_as_concept_ids,omitempty"`
}

// fields that define a custom dichotomous variable:
Expand Down

0 comments on commit 02f6f00

Please sign in to comment.