From c8527c2ce6e1db8d50b409076569b2d2ccb97862 Mon Sep 17 00:00:00 2001 From: Connor Barker Date: Tue, 11 Jun 2024 09:15:22 -0400 Subject: [PATCH] [JN-1076] trim stableids (#931) --- .../core/service/survey/SurveyService.java | 1 + .../service/survey/SurveyServiceTests.java | 35 +++++++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/bio/terra/pearl/core/service/survey/SurveyService.java b/core/src/main/java/bio/terra/pearl/core/service/survey/SurveyService.java index d777780eba..83154f6191 100644 --- a/core/src/main/java/bio/terra/pearl/core/service/survey/SurveyService.java +++ b/core/src/main/java/bio/terra/pearl/core/service/survey/SurveyService.java @@ -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); diff --git a/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyServiceTests.java b/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyServiceTests.java index c872fff2dd..8b5c7dbb97 100644 --- a/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyServiceTests.java +++ b/core/src/test/java/bio/terra/pearl/core/service/survey/SurveyServiceTests.java @@ -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; @@ -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; @@ -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()); + } + }