Skip to content

Commit

Permalink
[JN-1076] trim stableids (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorlbark authored Jun 11, 2024
1 parent 8597873 commit c8527c2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Survey create(Survey survey) {
Instant now = Instant.now();
survey.setCreatedAt(now);
survey.setLastUpdatedAt(now);
survey.setStableId(survey.getStableId().trim());
Survey savedSurvey = dao.create(survey);
for (AnswerMapping answerMapping : survey.getAnswerMappings()) {
answerMapping.setId(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
import bio.terra.pearl.core.factory.survey.SurveyFactory;
import bio.terra.pearl.core.model.admin.AdminUser;
import bio.terra.pearl.core.model.portal.Portal;
import bio.terra.pearl.core.model.survey.AnswerMapping;
import bio.terra.pearl.core.model.survey.AnswerMappingMapType;
import bio.terra.pearl.core.model.survey.AnswerMappingTargetType;
import bio.terra.pearl.core.model.survey.Survey;
import bio.terra.pearl.core.model.survey.SurveyQuestionDefinition;
import bio.terra.pearl.core.model.survey.SurveyType;
import bio.terra.pearl.core.model.survey.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -28,10 +23,7 @@
import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.samePropertyValuesAs;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.springframework.test.util.AssertionErrors.fail;
Expand Down Expand Up @@ -379,4 +371,27 @@ void testGetSurveyAnswerFromPreEnrollSurveyJsonData() {
assertEquals(true, result);
}

@Test
void createStripsWhitespace(TestInfo info) {

Portal portal = portalFactory.buildPersisted(getTestName(info));

Survey survey = Survey
.builder()
.stableId(" \t\t survey_1 ")
.content("""
{
"title": "The Basics",
"pages": []
}
""")
.portalId(portal.getId())
.eligibilityRule("")
.build();

Survey savedSurvey = surveyService.create(survey);

assertEquals("survey_1", savedSurvey.getStableId());
}

}

0 comments on commit c8527c2

Please sign in to comment.