26
26
import bio .terra .pearl .core .service .study .StudyService ;
27
27
import bio .terra .pearl .core .service .survey .SurveyResponseService ;
28
28
import com .fasterxml .jackson .core .JsonProcessingException ;
29
- import org .junit .jupiter .api .Assertions ;
30
29
import org .junit .jupiter .api .Test ;
31
30
import org .junit .jupiter .api .TestInfo ;
32
31
import org .springframework .beans .factory .annotation .Autowired ;
37
36
38
37
import static org .hamcrest .MatcherAssert .assertThat ;
39
38
import static org .hamcrest .Matchers .*;
39
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
40
40
41
41
public class EnrollmentServiceTests extends BaseSpringBootTest {
42
42
@ Autowired
@@ -134,6 +134,30 @@ public void testEnrollDoesNotRequirePreEnroll(TestInfo testInfo) {
134
134
assertThat (hubResponse .getEnrollee (), notNullValue ());
135
135
}
136
136
137
+ @ Test
138
+ @ Transactional
139
+ public void testEnrollRequiresPreEnrollIfSurveyRequired (TestInfo testInfo ) {
140
+ PortalEnvironment portalEnv = portalEnvironmentFactory .buildPersisted (getTestName (testInfo ));
141
+ StudyEnvironment studyEnv = studyEnvironmentFactory .buildPersisted (portalEnv , getTestName (testInfo ));
142
+ Survey survey = surveyFactory .buildPersisted (surveyFactory .builder (getTestName (testInfo ))
143
+ .surveyType (SurveyType .PRE_ENROLL )
144
+ .required (true )
145
+ .portalId (portalEnv .getPortalId ()));
146
+ surveyFactory .attachToEnv (survey , studyEnv .getId (), true );
147
+ ParticipantUserFactory .ParticipantUserAndPortalUser userBundle = participantUserFactory .buildPersisted (portalEnv ,
148
+ getTestName (testInfo ));
149
+ String studyShortcode = studyService .find (studyEnv .getStudyId ()).get ().getShortcode ();
150
+
151
+
152
+ assertThrows (
153
+ IllegalArgumentException .class ,
154
+ () -> {
155
+ enrollmentService .enroll (userBundle .ppUser (), studyEnv .getEnvironmentName (), studyShortcode ,
156
+ userBundle .user (), userBundle .ppUser (), null , false );
157
+ });
158
+
159
+ }
160
+
137
161
@ Test
138
162
@ Transactional
139
163
public void testEnrollChecksConfigAllowsEnrollment (TestInfo testInfo ) {
@@ -148,7 +172,7 @@ public void testEnrollChecksConfigAllowsEnrollment(TestInfo testInfo) {
148
172
getTestName (testInfo ));
149
173
String studyShortcode = studyService .find (studyEnv .getStudyId ()).get ().getShortcode ();
150
174
String portalShortcode = portalService .find (portalEnv .getPortalId ()).get ().getShortcode ();
151
- Assertions . assertThrows (IllegalArgumentException .class , () -> {
175
+ assertThrows (IllegalArgumentException .class , () -> {
152
176
enrollmentService .enroll (userBundle .ppUser (), studyEnv .getEnvironmentName (), studyShortcode , userBundle .user (), userBundle .ppUser (),
153
177
null , false );
154
178
});
0 commit comments