Skip to content

Commit

Permalink
[#124] feat: 온보딩 설문 제출 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
NaMinhyeok committed Feb 20, 2025
1 parent ca3f242 commit e611864
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ private Map<Survey, SurveyOption> createSurveyToSelectedOption(
List<OnboardingSubmissionResult> submissionResults, Map<Long, Survey> surveyMap) {
Map<Survey, SurveyOption> surveyOptionMap =
submissionResults.stream()
.distinct()
.map(
submission -> {
Survey survey = surveyMap.get(submission.surveyId());
Expand All @@ -266,6 +267,7 @@ private Map<Survey, SurveyOption> createSurveyToSelectedOption(
return Map.entry(survey, option);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
// (existingOption, newOption) -> newOption));
return surveyOptionMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,108 @@ void getNextSurvey() {
submittedAt.toLocalDate()));
}

@Transactional
@Test
void 온보딩_설문을_제출할_때_동일한_설문에_대한_요청이_있으면_후순위_요청이_저장된다() {
// given
Member member = Member.create("나민혁", "[email protected]");
memberRepository.save(member);
SurveyBundle surveyBundle = new SurveyBundle();

final ValueCharacter valueCharacter =
valueCharacterRepository.save(
ValueCharacter.builder()
.name("아낌없이 주는 보금자리 유형")
.description("보금자리 유형 설명")
.keyword(Keyword.BENEVOLENCE)
.build());

surveyBundleRepository.save(surveyBundle);

OnboardingSurvey survey1 =
new OnboardingSurvey(
"새로운 아이디어를 갖고 창의적인 것이 그/그녀에게 중요하다. 그/그녀는 일을 자신만의 독특한 방식으로 하는 것을 좋아한다.", surveyBundle);
OnboardingSurvey survey2 =
new OnboardingSurvey("그/그녀에게 부자가 되는 것은 중요하다. 많은 돈과 비싼 물건들을 가지길 원한다.", surveyBundle);
OnboardingSurvey survey3 =
new OnboardingSurvey(
"세상의 모든 사람들이 평등하게 대우받아야 한다고 생각한다. 그/그녀는 모든 사람이 인생에서 동등한 기회를 가져야 한다고 믿는다.",
surveyBundle);
OnboardingSurvey survey4 =
new OnboardingSurvey(
"그/그녀에게 자신의 능력을 보여주는 것이 매우 중요하다. 사람들이 자신이 하는 일을 인정해주길 바란다.", surveyBundle);

surveyRepository.saveAll(List.of(survey1, survey2, survey3, survey4));

List<KeywordScore> scores1 =
List.of(
KeywordScore.builder().keyword(Keyword.ADVENTURE).score(BigDecimal.ONE).build(),
KeywordScore.builder().keyword(Keyword.BENEVOLENCE).score(BigDecimal.TWO).build());
List<KeywordScore> scores2 =
List.of(
KeywordScore.builder()
.keyword(Keyword.ADVENTURE)
.score(BigDecimal.valueOf(-1))
.build());

SurveyOption option0 =
SurveyOption.builder().survey(survey1).scores(scores1).content("전혀 나와 같지않다.").build();
SurveyOption option1 =
SurveyOption.builder().survey(survey1).scores(scores1).content("전혀 나와 같지않다.").build();
SurveyOption option2 =
SurveyOption.builder().survey(survey2).scores(scores1).content("나와 같지 않다.").build();
SurveyOption option3 =
SurveyOption.builder().survey(survey3).scores(scores2).content("나와 조금 같다.").build();
SurveyOption option4 =
SurveyOption.builder().survey(survey4).scores(scores2).content("나와 같다.").build();

surveyOptionRepository.saveAll(List.of(option0, option1, option2, option3, option4));
LocalDateTime submittedAt = LocalDateTime.of(2025, 2, 13, 18, 25, 0);

OnboardingSubmissionsCommand command =
new OnboardingSubmissionsCommand(
List.of(
new OnboardingSubmissionResult(survey1.getId(), option0.getId()),
new OnboardingSubmissionResult(survey1.getId(), option1.getId()),
new OnboardingSubmissionResult(survey2.getId(), option2.getId()),
new OnboardingSubmissionResult(survey3.getId(), option3.getId()),
new OnboardingSubmissionResult(survey4.getId(), option4.getId())),
member.getId());
// when
surveyService.submitOnboardingSurvey(command, submittedAt);
// then
List<SurveySubmission> submissions = surveySubmissionRepository.findAll();

then(submissions).hasSize(4);
then(submissions)
.extracting("member.id", "survey.id", "selectedOption.id", "submittedAt")
.containsExactlyInAnyOrder(
tuple(member.getId(), survey1.getId(), option1.getId(), submittedAt),
tuple(member.getId(), survey2.getId(), option2.getId(), submittedAt),
tuple(member.getId(), survey3.getId(), option3.getId(), submittedAt),
tuple(member.getId(), survey4.getId(), option4.getId(), submittedAt));
then(member).extracting("completedOnboardingAt").isEqualTo(submittedAt);
then(characterRecordRepository.findAll())
.hasSize(1)
.extracting(
"ordinalNumber",
"characterNo",
"member.id",
"surveyBundle.id",
"valueCharacter.id",
"startDate",
"endDate")
.containsExactly(
tuple(
1,
"첫번째 캐릭터",
member.getId(),
surveyBundle.getId(),
valueCharacter.getId(),
submittedAt.toLocalDate(),
submittedAt.toLocalDate()));
}

@Test
void 온보딩을_이미_완료했으면_진행할_수_없다() {
// given
Expand Down

0 comments on commit e611864

Please sign in to comment.