Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
tianj7 committed Sep 4, 2024
1 parent e4baee2 commit 0e4228a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion models/cohortdefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (h CohortDefinition) GetCohortDefinitionById(id int) (*CohortDefinition, er
query := db2.Model(&CohortDefinition{}).
Select("cohort_definition.id, cohort_definition.name, cohort_definition.description, cohort_definition_details.expression").
Where("cohort_definition.id = ?", id).
Joins("LEFT JOIN " + atlasDb.Schema + ".cohort_definition_details ON cohort_definition.id = cohort_definition_details.id")
Joins("INNER JOIN " + atlasDb.Schema + ".cohort_definition_details ON cohort_definition.id = cohort_definition_details.id")

query, cancel := utils.AddTimeoutToQuery(query)
defer cancel()
Expand Down
10 changes: 10 additions & 0 deletions tests/models_tests/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,13 @@ func TestGetAllCohortDefinitionsAndStatsOrderBySizeDescWhenCohortDefinitionIsMis
firstCohort.Id,
firstCohort.Name,
firstCohort.Name))

tests.ExecAtlasSQLString(fmt.Sprintf("insert into %s.cohort_definition_details (id,expression,hash_code) "+
"values (%d, '{\"expression\" : \"%d\" }', %d)",
db.GetAtlasDB().Schema,
firstCohort.Id,
firstCohort.Id,
555444))
}

func TestGetCohortName(t *testing.T) {
Expand Down Expand Up @@ -1022,6 +1029,9 @@ func TestGetCohortDefinitionById(t *testing.T) {
if allCohortDefinitions[0].Id != foundCohortDefinition.Id {
t.Errorf("Expected data not found")
}
if foundCohortDefinition.Expression != "{\"expression\" : \"1\" }" {
t.Errorf("Expected expression data not found")
}
}

func TestRetrieveDataByOriginalCohortAndNewCohort(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion tests/setup_local_db/ddl_atlas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ CREATE TABLE atlas.cohort_definition_details
hash_code integer,
CONSTRAINT PK_cohort_definition_details PRIMARY KEY (id),
CONSTRAINT fk_cohort_definition_details_to_cohort_definition FOREIGN KEY (id)
REFERENCES atlas.cohort_definition (id)
REFERENCES atlas.cohort_definition (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
);

CREATE TABLE atlas.sec_role
Expand Down
4 changes: 3 additions & 1 deletion tests/setup_local_db/test_data_atlas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ insert into atlas.cohort_definition_details
values
(1,'{"expression" : "1" }',987654321),
(2,'{"expression" : "2" }',1234567890),
(3,'{"expression" : "3" }', NULL)
(3,'{"expression" : "3" }', 33333445),
(4,'{"expression" : "4" }', 555444),
(32,'{"expression" : "32" }', 323232)
;

insert into atlas.sec_role
Expand Down

0 comments on commit 0e4228a

Please sign in to comment.