Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 온보딩 설문 제출 오류 수정 #124

Closed
NaMinhyeok opened this issue Feb 20, 2025 · 0 comments · Fixed by #125
Closed

fix: 온보딩 설문 제출 오류 수정 #124

NaMinhyeok opened this issue Feb 20, 2025 · 0 comments · Fixed by #125
Labels
bug Something isn't working

Comments

@NaMinhyeok
Copy link
Member

NaMinhyeok commented Feb 20, 2025

심각성

A

버그 설명

Image

Duplicate key org.nexters.jaknaesocore.domain.survey.model.OnboardingSurvey@4bcb5415 (attempted merging values org.nexters.jaknaesocore.domain.survey.model.SurveyOption@6eb61a31 and org.nexters.jaknaesocore.domain.survey.model.SurveyOption@568e814c)
java.lang.IllegalStateException: Duplicate key org.nexters.jaknaesocore.domain.survey.model.OnboardingSurvey@4bcb5415 (attempted merging values org.nexters.jaknaesocore.domain.survey.model.SurveyOption@6eb61a31 and org.nexters.jaknaesocore.domain.survey.model.SurveyOption@568e814c)

기대 동작 설명

  • 온보딩 설문 등록시 온보딩 설문 결과 등록 성공 및 캐릭터 생성

버그 재현법

  1. 온보딩 설문 요청 RequestBody에 동일한 Survey에 대한 요청이 포함되어야 합니다. ex) {[surveyId : 1, optionId : 1], [surveyId : 1, optionId : 2]}

버그 재현 테스트 코드

@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()));
  }

테스트 실행 결과

Image

실제 프로덕션코드의 에러와 동일

실행 환경

No response

기타 참고 사항

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant