@@ -16,15 +16,24 @@ test_that(
1616 # Verify the user was added
1717 expect_true(EXPENDABLE_USER %in% rcon $ users()$ username )
1818
19+ # ensure export > import > export equality
20+ # initial import fixes the state
21+ importUsers(rcon , rcon $ users())
22+ Users <- exportUsers(rcon )
23+ importUsers(rcon , Users )
24+ # cache should be correct
25+ expect_equal(rcon $ users(), exportUsers(rcon ))
26+ expect_equal(rcon $ users(), Users )
27+
1928 # Modify the user permissions
2029
2130 n_imported <- importUsers(rcon ,
2231 data = data.frame (username = EXPENDABLE_USER ,
2332 alerts = 1 ))
2433 expect_equal(n_imported , " 1" )
2534
26- Users <- exportUsers( rcon )
27- Users <- Users [rcon $ users() $ username %in% EXPENDABLE_USER , ]
35+ Users <- rcon $ users( )
36+ Users <- Users [Users $ username %in% EXPENDABLE_USER , ]
2837 expect_true(Users $ alerts %in% " Access" )
2938 }
3039)
@@ -82,7 +91,7 @@ test_that(
8291 data = data.frame (username = EXPENDABLE_USER ,
8392 data_export = 1 ,
8493 forms = c(" record_id:0" ),
85- # leaving an instrument off implicitly sets permission to 0
94+ # leaving an instrument off implicitly sets permission to 0
8695 forms_export = " " ),
8796 consolidate = FALSE )
8897
@@ -97,20 +106,60 @@ test_that(
97106 record_id_form_access = 1 ,
98107 forms = ' record_id:0' ,
99108 forms_export = ' ' ),
100- consolidate = FALSE ))
109+ consolidate = FALSE ))
101110 Users <- exportUsers(rcon )
102111 Users <- Users [Users $ username %in% EXPENDABLE_USER , ]
103112 expect_true(grepl(" record_id:0" ,Users $ forms ))
104-
105- # NEED TO ADD TWO TESTS
106- # Update data_access_group to "No Assignment"
107- # functionality not supported as of version 2.11.5
108- # Update data_access_group to a legitimate DAG
109- # functionality not supported as of version 2.11.5
110113 }
111114)
112115
116+ test_that(
117+ " Import User DAG Assignments" ,
118+ {
119+ skip_if(! RUN_USER_TESTS ,
120+ " User tests without an expendable user could have negative consequences and are not run." )
121+
122+ if (EXPENDABLE_USER %in% rcon $ users()$ username ){
123+ deleteUsers(rcon ,
124+ users = EXPENDABLE_USER )
125+ }
126+
127+ importUsers(rcon ,
128+ data = data.frame (username = EXPENDABLE_USER ))
129+
130+ # create temporary DAG; it probably already exists at this point
131+ TmpDag <- ! ' test_dag_1' %in% exportDags(rcon )$ unique_group_name
132+ if (TmpDag ) {
133+ NewDag <- data.frame (data_access_group_name = ' test_dag_1' ,
134+ unique_group_name = NA_character_ )
135+ importDags(rcon , data = NewDag )
136+ }
113137
138+ # Update data_access_group to a legitimate DAG
139+ Users <- exportUsers(rcon )
140+ Users <- Users [Users $ username %in% EXPENDABLE_USER , ]
141+ Users [,' data_access_group' ] <- ' test_dag_1'
142+ importUsers(rcon , data = Users )
143+ DagAsgmt <- exportUserDagAssignments(rcon )
144+ expect_equal(' test_dag_1' ,
145+ DagAsgmt [DagAsgmt [,' username' ] == EXPENDABLE_USER , ' redcap_data_access_group' ])
146+
147+ # Update data_access_group to "No Assignment"
148+ Users [,' data_access_group' ] <- NA_character_
149+ # warning indicates this gives view access to all records
150+ expect_warning(importUsers(rcon , data = Users ), ' view all records' )
151+ DagAsgmt <- exportUserDagAssignments(rcon )
152+ expect_true(is.na(DagAsgmt [DagAsgmt [,' username' ] == EXPENDABLE_USER , ' redcap_data_access_group' ]))
153+
154+ # Try a bad DAG
155+ Users [,' data_access_group' ] <- ' uncouth_dag'
156+ expect_error(importUsers(rcon , data = Users ))
157+
158+ if (TmpDag ) {
159+ deleteDags(rcon , ' test_dag_1' )
160+ }
161+ }
162+ )
114163
115164test_that(
116165 " Export User Options" ,
0 commit comments