From 97518febbde7ec03de39857e8a28ff7fa8fd3b3d Mon Sep 17 00:00:00 2001 From: Gyuhyeok99 <126947828+Gyuhyeok99@users.noreply.github.com> Date: Wed, 21 May 2025 19:33:08 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20ApplicationFixture=EC=97=90=20?= =?UTF-8?q?=EC=A7=80=EC=9B=90=EC=84=9C=20=EC=83=9D=EC=84=B1=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fixture/ApplicationFixture.java | 38 ++++++++ .../fixture/ApplicationFixtureBuilder.java | 86 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 src/test/java/com/example/solidconnection/application/fixture/ApplicationFixture.java create mode 100644 src/test/java/com/example/solidconnection/application/fixture/ApplicationFixtureBuilder.java diff --git a/src/test/java/com/example/solidconnection/application/fixture/ApplicationFixture.java b/src/test/java/com/example/solidconnection/application/fixture/ApplicationFixture.java new file mode 100644 index 000000000..b2cbc6460 --- /dev/null +++ b/src/test/java/com/example/solidconnection/application/fixture/ApplicationFixture.java @@ -0,0 +1,38 @@ +package com.example.solidconnection.application.fixture; + +import com.example.solidconnection.application.domain.Application; +import com.example.solidconnection.application.domain.Gpa; +import com.example.solidconnection.application.domain.LanguageTest; +import com.example.solidconnection.siteuser.domain.SiteUser; +import com.example.solidconnection.university.domain.UniversityInfoForApply; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.test.context.TestComponent; + +@TestComponent +@RequiredArgsConstructor +public class ApplicationFixture { + + private final ApplicationFixtureBuilder applicationFixtureBuilder; + + public Application 지원서( + SiteUser siteUser, + String nicknameForApply, + String term, + Gpa gpa, + LanguageTest languageTest, + UniversityInfoForApply firstChoiceUniversity, + UniversityInfoForApply secondChoiceUniversity, + UniversityInfoForApply thirdChoiceUniversity + ) { + return applicationFixtureBuilder.application() + .siteUser(siteUser) + .gpa(gpa) + .languageTest(languageTest) + .nicknameForApply(nicknameForApply) + .term(term) + .firstChoiceUniversity(firstChoiceUniversity) + .secondChoiceUniversity(secondChoiceUniversity) + .thirdChoiceUniversity(thirdChoiceUniversity) + .create(); + } +} diff --git a/src/test/java/com/example/solidconnection/application/fixture/ApplicationFixtureBuilder.java b/src/test/java/com/example/solidconnection/application/fixture/ApplicationFixtureBuilder.java new file mode 100644 index 000000000..5f6c06741 --- /dev/null +++ b/src/test/java/com/example/solidconnection/application/fixture/ApplicationFixtureBuilder.java @@ -0,0 +1,86 @@ +package com.example.solidconnection.application.fixture; + +import com.example.solidconnection.application.domain.Application; +import com.example.solidconnection.application.domain.Gpa; +import com.example.solidconnection.application.domain.LanguageTest; +import com.example.solidconnection.application.domain.VerifyStatus; +import com.example.solidconnection.application.repository.ApplicationRepository; +import com.example.solidconnection.siteuser.domain.SiteUser; +import com.example.solidconnection.university.domain.UniversityInfoForApply; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.test.context.TestComponent; + +@TestComponent +@RequiredArgsConstructor +public class ApplicationFixtureBuilder { + + private final ApplicationRepository applicationRepository; + + private Gpa gpa; + private LanguageTest languageTest; + private UniversityInfoForApply firstChoiceUniversity; + private UniversityInfoForApply secondChoiceUniversity; + private UniversityInfoForApply thirdChoiceUniversity; + private SiteUser siteUser; + private String nicknameForApply; + private String term; + + public ApplicationFixtureBuilder application() { + return new ApplicationFixtureBuilder(applicationRepository); + } + + public ApplicationFixtureBuilder gpa(Gpa gpa) { + this.gpa = gpa; + return this; + } + + public ApplicationFixtureBuilder languageTest(LanguageTest languageTest) { + this.languageTest = languageTest; + return this; + } + + public ApplicationFixtureBuilder firstChoiceUniversity(UniversityInfoForApply firstChoiceUniversity) { + this.firstChoiceUniversity = firstChoiceUniversity; + return this; + } + + public ApplicationFixtureBuilder secondChoiceUniversity(UniversityInfoForApply secondChoiceUniversity) { + this.secondChoiceUniversity = secondChoiceUniversity; + return this; + } + + public ApplicationFixtureBuilder thirdChoiceUniversity(UniversityInfoForApply thirdChoiceUniversity) { + this.thirdChoiceUniversity = thirdChoiceUniversity; + return this; + } + + public ApplicationFixtureBuilder siteUser(SiteUser siteUser) { + this.siteUser = siteUser; + return this; + } + + public ApplicationFixtureBuilder nicknameForApply(String nicknameForApply) { + this.nicknameForApply = nicknameForApply; + return this; + } + + public ApplicationFixtureBuilder term(String term) { + this.term = term; + return this; + } + + public Application create() { + Application application = new Application( + siteUser, + gpa, + languageTest, + term, + firstChoiceUniversity, + secondChoiceUniversity, + thirdChoiceUniversity, + nicknameForApply + ); + application.setVerifyStatus(VerifyStatus.APPROVED); + return applicationRepository.save(application); + } +} From eceaab35902fde47d2dd620e38012ec3f9819cbd Mon Sep 17 00:00:00 2001 From: Gyuhyeok99 <126947828+Gyuhyeok99@users.noreply.github.com> Date: Wed, 21 May 2025 19:33:32 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=EC=A7=80=EC=9B=90=EC=84=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20Fixture=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ApplicationQueryServiceTest.java | 464 ++++++++++++------ .../ApplicationSubmissionServiceTest.java | 130 +++-- 2 files changed, 367 insertions(+), 227 deletions(-) diff --git a/src/test/java/com/example/solidconnection/application/service/ApplicationQueryServiceTest.java b/src/test/java/com/example/solidconnection/application/service/ApplicationQueryServiceTest.java index 240217496..ec68fa440 100644 --- a/src/test/java/com/example/solidconnection/application/service/ApplicationQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/application/service/ApplicationQueryServiceTest.java @@ -1,32 +1,37 @@ package com.example.solidconnection.application.service; import com.example.solidconnection.application.domain.Application; -import com.example.solidconnection.application.domain.Gpa; -import com.example.solidconnection.application.domain.LanguageTest; import com.example.solidconnection.application.domain.VerifyStatus; import com.example.solidconnection.application.dto.ApplicantResponse; import com.example.solidconnection.application.dto.ApplicationsResponse; import com.example.solidconnection.application.dto.UniversityApplicantsResponse; +import com.example.solidconnection.application.fixture.ApplicationFixture; import com.example.solidconnection.application.repository.ApplicationRepository; +import com.example.solidconnection.location.region.fixture.RegionFixture; import com.example.solidconnection.score.domain.GpaScore; import com.example.solidconnection.score.domain.LanguageTestScore; -import com.example.solidconnection.score.repository.GpaScoreRepository; -import com.example.solidconnection.score.repository.LanguageTestScoreRepository; +import com.example.solidconnection.score.fixture.GpaScoreFixture; +import com.example.solidconnection.score.fixture.LanguageTestScoreFixture; import com.example.solidconnection.siteuser.domain.SiteUser; -import com.example.solidconnection.support.integration.BaseIntegrationTest; -import com.example.solidconnection.university.domain.LanguageTestType; +import com.example.solidconnection.siteuser.fixture.SiteUserFixture; +import com.example.solidconnection.support.TestContainerSpringBootTest; import com.example.solidconnection.university.domain.UniversityInfoForApply; +import com.example.solidconnection.university.fixture.LanguageRequirementFixture; +import com.example.solidconnection.university.fixture.UniversityInfoForApplyFixture; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +@TestContainerSpringBootTest @DisplayName("지원서 조회 서비스 테스트") -class ApplicationQueryServiceTest extends BaseIntegrationTest { +class ApplicationQueryServiceTest { @Autowired private ApplicationQueryService applicationQueryService; @@ -35,19 +40,111 @@ class ApplicationQueryServiceTest extends BaseIntegrationTest { private ApplicationRepository applicationRepository; @Autowired - private GpaScoreRepository gpaScoreRepository; + private SiteUserFixture siteUserFixture; @Autowired - private LanguageTestScoreRepository languageTestScoreRepository; + private RegionFixture regionFixture; + + @Autowired + private UniversityInfoForApplyFixture universityInfoForApplyFixture; + + @Autowired + private LanguageRequirementFixture languageRequirementFixture; + + @Autowired + private GpaScoreFixture gpaScoreFixture; + + @Autowired + private LanguageTestScoreFixture languageTestScoreFixture; + + @Autowired + private ApplicationFixture applicationFixture; + + @Value("${university.term}") + private String term; + + private SiteUser user1; + private SiteUser user2; + private SiteUser user3; + + private GpaScore gpaScore1; + private GpaScore gpaScore2; + private GpaScore gpaScore3; + + private LanguageTestScore languageTestScore1; + private LanguageTestScore languageTestScore2; + private LanguageTestScore languageTestScore3; + + private UniversityInfoForApply 괌대학_A_지원_정보; + private UniversityInfoForApply 괌대학_B_지원_정보; + private UniversityInfoForApply 서던덴마크대학교_지원_정보; + + @BeforeEach + void setUp() { + user1 = siteUserFixture.사용자(1, "test1"); + gpaScore1 = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user1); + languageTestScore1 = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user1); + + user2 = siteUserFixture.사용자(2, "test2"); + gpaScore2 = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user2); + languageTestScore2 = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user2); + + user3 = siteUserFixture.사용자(3, "test3"); + gpaScore3 = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user3); + languageTestScore3 = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user3); + + 괌대학_A_지원_정보 = universityInfoForApplyFixture.괌대학_A_지원_정보(); + languageRequirementFixture.토플_80(괌대학_A_지원_정보); + languageRequirementFixture.토익_800(괌대학_A_지원_정보); + + 괌대학_B_지원_정보 = universityInfoForApplyFixture.괌대학_B_지원_정보(); + languageRequirementFixture.토플_70(괌대학_B_지원_정보); + languageRequirementFixture.토익_900(괌대학_B_지원_정보); + + 서던덴마크대학교_지원_정보 = universityInfoForApplyFixture.서던덴마크대학교_지원_정보(); + languageRequirementFixture.토플_70(서던덴마크대학교_지원_정보); + } @Nested class 지원자_목록_조회_테스트 { @Test void 이번_학기_전체_지원자를_조회한다() { + // given + Application application1 = applicationFixture.지원서( + user1, + "nickname1", + term, + gpaScore1.getGpa(), + languageTestScore1.getLanguageTest(), + 괌대학_A_지원_정보, + null, + null + ); + Application application2 = applicationFixture.지원서( + user2, + "nickname2", + term, + gpaScore2.getGpa(), + languageTestScore2.getLanguageTest(), + 괌대학_B_지원_정보, + null, + null + ); + Application application3 = applicationFixture.지원서( + user3, + "nickname3", + term, + gpaScore3.getGpa(), + languageTestScore3.getLanguageTest(), + 서던덴마크대학교_지원_정보, + null, + null + ); + // when ApplicationsResponse response = applicationQueryService.getApplicants( - 테스트유저_2, + user1, "", "" ); @@ -55,128 +152,174 @@ class 지원자_목록_조회_테스트 { // then assertThat(response.firstChoice()).containsAll(List.of( UniversityApplicantsResponse.of(괌대학_A_지원_정보, - List.of(ApplicantResponse.of(테스트유저_3_괌대학_A_괌대학_B_그라츠공과대학_지원서, false))), + List.of(ApplicantResponse.of(application1, true))), UniversityApplicantsResponse.of(괌대학_B_지원_정보, - List.of(ApplicantResponse.of(테스트유저_2_괌대학_B_괌대학_A_린츠_카톨릭대학_지원서, true))), - UniversityApplicantsResponse.of(메이지대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_4_메이지대학_그라츠대학_서던덴마크대학_지원서, false))), - UniversityApplicantsResponse.of(네바다주립대학_라스베이거스_지원_정보, - List.of(ApplicantResponse.of(테스트유저_5_네바다주립대학_그라츠공과대학_메이지대학_지원서, false))), - UniversityApplicantsResponse.of(코펜하겐IT대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_7_코펜하겐IT대학_X_X_지원서, false))) - )); - - assertThat(response.secondChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(괌대학_A_지원_정보, - List.of(ApplicantResponse.of(테스트유저_2_괌대학_B_괌대학_A_린츠_카톨릭대학_지원서, true))), - UniversityApplicantsResponse.of(괌대학_B_지원_정보, - List.of(ApplicantResponse.of(테스트유저_3_괌대학_A_괌대학_B_그라츠공과대학_지원서, false))), - UniversityApplicantsResponse.of(그라츠대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_4_메이지대학_그라츠대학_서던덴마크대학_지원서, false))), - UniversityApplicantsResponse.of(그라츠공과대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_5_네바다주립대학_그라츠공과대학_메이지대학_지원서, false))) - )); - - assertThat(response.thirdChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_2_괌대학_B_괌대학_A_린츠_카톨릭대학_지원서, true))), - UniversityApplicantsResponse.of(그라츠공과대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_3_괌대학_A_괌대학_B_그라츠공과대학_지원서, false))), + List.of(ApplicantResponse.of(application2, false))), UniversityApplicantsResponse.of(서던덴마크대학교_지원_정보, - List.of(ApplicantResponse.of(테스트유저_4_메이지대학_그라츠대학_서던덴마크대학_지원서, false))), - UniversityApplicantsResponse.of(메이지대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_5_네바다주립대학_그라츠공과대학_메이지대학_지원서, false))) + List.of(ApplicantResponse.of(application3, false))) )); } @Test void 이번_학기_특정_지역_지원자를_조회한다() { + //given + Application application1 = applicationFixture.지원서( + user1, + "nickname1", + term, + gpaScore1.getGpa(), + languageTestScore1.getLanguageTest(), + 괌대학_A_지원_정보, + null, + null + ); + Application application2 = applicationFixture.지원서( + user2, + "nickname2", + term, + gpaScore2.getGpa(), + languageTestScore2.getLanguageTest(), + 괌대학_B_지원_정보, + null, + null + ); + applicationFixture.지원서( + user3, + "nickname3", + term, + gpaScore3.getGpa(), + languageTestScore3.getLanguageTest(), + 서던덴마크대학교_지원_정보, + null, + null + ); + // when ApplicationsResponse response = applicationQueryService.getApplicants( - 테스트유저_2, - 영미권.getCode(), + user1, + regionFixture.영미권().getCode(), "" ); // then - assertThat(response.firstChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(괌대학_A_지원_정보, - List.of(ApplicantResponse.of(테스트유저_3_괌대학_A_괌대학_B_그라츠공과대학_지원서, false))), - UniversityApplicantsResponse.of(괌대학_B_지원_정보, - List.of(ApplicantResponse.of(테스트유저_2_괌대학_B_괌대학_A_린츠_카톨릭대학_지원서, true))), - UniversityApplicantsResponse.of(네바다주립대학_라스베이거스_지원_정보, - List.of(ApplicantResponse.of(테스트유저_5_네바다주립대학_그라츠공과대학_메이지대학_지원서, false))) - )); - - assertThat(response.secondChoice()).containsAll(List.of( + assertThat(response.firstChoice()).containsExactlyInAnyOrder( UniversityApplicantsResponse.of(괌대학_A_지원_정보, - List.of(ApplicantResponse.of(테스트유저_2_괌대학_B_괌대학_A_린츠_카톨릭대학_지원서, true))), + List.of(ApplicantResponse.of(application1, true))), UniversityApplicantsResponse.of(괌대학_B_지원_정보, - List.of(ApplicantResponse.of(테스트유저_3_괌대학_A_괌대학_B_그라츠공과대학_지원서, false))) - )); + List.of(ApplicantResponse.of(application2, false))) + ); } @Test void 이번_학기_지원자를_대학_국문_이름으로_필터링해서_조회한다() { + //given + Application application1 = applicationFixture.지원서( + user1, + "nickname1", + term, + gpaScore1.getGpa(), + languageTestScore1.getLanguageTest(), + 괌대학_A_지원_정보, + null, + null + ); + Application application2 = applicationFixture.지원서( + user2, + "nickname2", + term, + gpaScore2.getGpa(), + languageTestScore2.getLanguageTest(), + 괌대학_B_지원_정보, + null, + null + ); + applicationFixture.지원서( + user3, + "nickname3", + term, + gpaScore3.getGpa(), + languageTestScore3.getLanguageTest(), + 서던덴마크대학교_지원_정보, + null, + null + ); + // when ApplicationsResponse response = applicationQueryService.getApplicants( - 테스트유저_2, + user1, null, - "일본" + "괌" ); // then - assertThat(response.firstChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(메이지대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_4_메이지대학_그라츠대학_서던덴마크대학_지원서, false))) - )); - - assertThat(response.secondChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(메이지대학_지원_정보, List.of()) - )); - - assertThat(response.thirdChoice()).containsExactlyInAnyOrder( - UniversityApplicantsResponse.of(메이지대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_5_네바다주립대학_그라츠공과대학_메이지대학_지원서, false))) + assertThat(response.firstChoice()).containsExactlyInAnyOrder( + UniversityApplicantsResponse.of(괌대학_A_지원_정보, + List.of(ApplicantResponse.of(application1, true))), + UniversityApplicantsResponse.of(괌대학_B_지원_정보, + List.of(ApplicantResponse.of(application2, false))) ); } @Test void 이전_학기_지원자는_조회되지_않는다() { + // given + Application application = applicationFixture.지원서( + user1, + "nickname1", + "1988-1", + gpaScore1.getGpa(), + languageTestScore1.getLanguageTest(), + 괌대학_A_지원_정보, + null, + null + ); + // when ApplicationsResponse response = applicationQueryService.getApplicants( - 테스트유저_1, + user1, "", "" ); // then assertThat(response.firstChoice()).doesNotContainAnyElementsOf(List.of( - UniversityApplicantsResponse.of(네바다주립대학_라스베이거스_지원_정보, - List.of(ApplicantResponse.of(이전학기_지원서, false))) - )); - assertThat(response.secondChoice()).doesNotContainAnyElementsOf(List.of( - UniversityApplicantsResponse.of(그라츠공과대학_지원_정보, - List.of(ApplicantResponse.of(이전학기_지원서, false))) - )); - assertThat(response.thirdChoice()).doesNotContainAnyElementsOf(List.of( - UniversityApplicantsResponse.of(메이지대학_지원_정보, - List.of(ApplicantResponse.of(이전학기_지원서, false))) + UniversityApplicantsResponse.of(괌대학_A_지원_정보, + List.of(ApplicantResponse.of(application, true))) )); } @Test void 동일_유저의_여러_지원서_중_최신_지원서만_조회된다() { // given - Application firstApplication = createApplication(테스트유저_1, 괌대학_A_지원_정보); + Application firstApplication = applicationFixture.지원서( + user1, + "nickname1", + term, + gpaScore1.getGpa(), + languageTestScore1.getLanguageTest(), + 괌대학_A_지원_정보, + null, + null + ); firstApplication.setIsDeleteTrue(); applicationRepository.save(firstApplication); - Application secondApplication = createApplication(테스트유저_1, 네바다주립대학_라스베이거스_지원_정보); - + Application secondApplication = applicationFixture.지원서( + user1, + "nickname2", + term, + gpaScore1.getGpa(), + languageTestScore1.getLanguageTest(), + 괌대학_B_지원_정보, + null, + null + ); // when ApplicationsResponse response = applicationQueryService.getApplicants( - 테스트유저_1, "", ""); + user1, + "", + "" + ); // then assertThat(response.firstChoice().stream() @@ -191,100 +334,99 @@ class 경쟁자_목록_조회_테스트 { @Test void 이번_학기_지원한_대학의_경쟁자_목록을_조회한다() { - // when - ApplicationsResponse response = applicationQueryService.getApplicantsByUserApplications( - 테스트유저_2 + // given + Application application1 = applicationFixture.지원서( + user1, + "nickname1", + term, + gpaScore1.getGpa(), + languageTestScore1.getLanguageTest(), + 괌대학_A_지원_정보, + null, + null + ); + Application application2 = applicationFixture.지원서( + user2, + "nickname2", + term, + gpaScore2.getGpa(), + languageTestScore2.getLanguageTest(), + 괌대학_A_지원_정보, + null, + null + ); + applicationFixture.지원서( + user3, + "nickname3", + term, + gpaScore3.getGpa(), + languageTestScore3.getLanguageTest(), + 괌대학_B_지원_정보, + null, + null ); + // when + ApplicationsResponse response = applicationQueryService.getApplicantsByUserApplications(user1); // then - assertThat(response.firstChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(괌대학_B_지원_정보, - List.of(ApplicantResponse.of(테스트유저_2_괌대학_B_괌대학_A_린츠_카톨릭대학_지원서, true))), - UniversityApplicantsResponse.of(괌대학_A_지원_정보, - List.of(ApplicantResponse.of(테스트유저_3_괌대학_A_괌대학_B_그라츠공과대학_지원서, false))) - )); - - assertThat(response.secondChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(괌대학_A_지원_정보, - List.of(ApplicantResponse.of(테스트유저_2_괌대학_B_괌대학_A_린츠_카톨릭대학_지원서, true))), - UniversityApplicantsResponse.of(괌대학_B_지원_정보, - List.of(ApplicantResponse.of(테스트유저_3_괌대학_A_괌대학_B_그라츠공과대학_지원서, false))) - )); - - assertThat(response.thirdChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_2_괌대학_B_괌대학_A_린츠_카톨릭대학_지원서, true))) - )); + assertThat(response.firstChoice()).containsExactlyInAnyOrder( + UniversityApplicantsResponse.of(괌대학_A_지원_정보, List.of( + ApplicantResponse.of(application1, true), + ApplicantResponse.of(application2, false) + )) + ); } @Test void 이번_학기_지원한_대학_중_미선택이_있을_때_경쟁자_목록을_조회한다() { - // when - ApplicationsResponse response = applicationQueryService.getApplicantsByUserApplications( - 테스트유저_7 + // given + Application application1 = applicationFixture.지원서( + user1, + "nickname1", + term, + gpaScore1.getGpa(), + languageTestScore1.getLanguageTest(), + 괌대학_A_지원_정보, + null, + null ); + applicationFixture.지원서( + user2, + "nickname2", + term, + gpaScore2.getGpa(), + languageTestScore2.getLanguageTest(), + null, + 괌대학_B_지원_정보, + null + ); + applicationFixture.지원서( + user3, + "nickname3", + term, + gpaScore3.getGpa(), + languageTestScore3.getLanguageTest(), + null, + null, + 서던덴마크대학교_지원_정보 + ); + + // when + ApplicationsResponse response = applicationQueryService.getApplicantsByUserApplications(user1); // then - assertThat(response.firstChoice()).containsAll(List.of( - UniversityApplicantsResponse.of(코펜하겐IT대학_지원_정보, - List.of(ApplicantResponse.of(테스트유저_7_코펜하겐IT대학_X_X_지원서, true))) - )); + assertThat(response.firstChoice()).containsExactlyInAnyOrder( + UniversityApplicantsResponse.of(괌대학_A_지원_정보, + List.of(ApplicantResponse.of(application1, true))) + ); assertThat(response.secondChoice()).containsExactlyInAnyOrder( - UniversityApplicantsResponse.of(코펜하겐IT대학_지원_정보, List.of()) + UniversityApplicantsResponse.of(괌대학_A_지원_정보, List.of()) ); assertThat(response.thirdChoice()).containsExactlyInAnyOrder( - UniversityApplicantsResponse.of(코펜하겐IT대학_지원_정보, List.of()) + UniversityApplicantsResponse.of(괌대학_A_지원_정보, List.of()) ); } - - @Test - void 이번_학기_지원한_대학이_모두_미선택일_때_경쟁자_목록을_조회한다() { - //when - ApplicationsResponse response = applicationQueryService.getApplicantsByUserApplications( - 테스트유저_6 - ); - - // then - assertThat(response.firstChoice()).isEmpty(); - assertThat(response.secondChoice()).isEmpty(); - assertThat(response.thirdChoice()).isEmpty(); - } - } - - private GpaScore createApprovedGpaScore(SiteUser siteUser) { - GpaScore gpaScore = new GpaScore( - new Gpa(4.0, 4.5, "/gpa-report.pdf"), - siteUser - ); - gpaScore.setVerifyStatus(VerifyStatus.APPROVED); - return gpaScoreRepository.save(gpaScore); - } - - private LanguageTestScore createApprovedLanguageTestScore(SiteUser siteUser) { - LanguageTestScore languageTestScore = new LanguageTestScore( - new LanguageTest(LanguageTestType.TOEIC, "100", "/gpa-report.pdf"), - siteUser - ); - languageTestScore.setVerifyStatus(VerifyStatus.APPROVED); - return languageTestScoreRepository.save(languageTestScore); - } - - private Application createApplication( - SiteUser siteUser, - UniversityInfoForApply universityInfoForApply) { - Application application = new Application( - siteUser, - createApprovedGpaScore(siteUser).getGpa(), - createApprovedLanguageTestScore(siteUser).getLanguageTest(), - term, - universityInfoForApply, - null, - null, - null - ); - application.setVerifyStatus(VerifyStatus.APPROVED); - return applicationRepository.save(application); } } diff --git a/src/test/java/com/example/solidconnection/application/service/ApplicationSubmissionServiceTest.java b/src/test/java/com/example/solidconnection/application/service/ApplicationSubmissionServiceTest.java index 3c107424a..3884f51dc 100644 --- a/src/test/java/com/example/solidconnection/application/service/ApplicationSubmissionServiceTest.java +++ b/src/test/java/com/example/solidconnection/application/service/ApplicationSubmissionServiceTest.java @@ -1,8 +1,6 @@ package com.example.solidconnection.application.service; import com.example.solidconnection.application.domain.Application; -import com.example.solidconnection.application.domain.Gpa; -import com.example.solidconnection.application.domain.LanguageTest; import com.example.solidconnection.application.domain.VerifyStatus; import com.example.solidconnection.application.dto.ApplicationSubmissionResponse; import com.example.solidconnection.application.dto.ApplyRequest; @@ -11,14 +9,19 @@ import com.example.solidconnection.common.exception.CustomException; import com.example.solidconnection.score.domain.GpaScore; import com.example.solidconnection.score.domain.LanguageTestScore; -import com.example.solidconnection.score.repository.GpaScoreRepository; -import com.example.solidconnection.score.repository.LanguageTestScoreRepository; +import com.example.solidconnection.score.fixture.GpaScoreFixture; +import com.example.solidconnection.score.fixture.LanguageTestScoreFixture; import com.example.solidconnection.siteuser.domain.SiteUser; -import com.example.solidconnection.support.integration.BaseIntegrationTest; -import com.example.solidconnection.university.domain.LanguageTestType; +import com.example.solidconnection.siteuser.fixture.SiteUserFixture; +import com.example.solidconnection.support.TestContainerSpringBootTest; +import com.example.solidconnection.university.domain.UniversityInfoForApply; +import com.example.solidconnection.university.fixture.LanguageRequirementFixture; +import com.example.solidconnection.university.fixture.UniversityInfoForApplyFixture; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import static com.example.solidconnection.application.service.ApplicationSubmissionService.APPLICATION_UPDATE_COUNT_LIMIT; import static com.example.solidconnection.common.exception.ErrorCode.APPLY_UPDATE_LIMIT_EXCEED; @@ -28,8 +31,9 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; import static org.junit.jupiter.api.Assertions.assertAll; +@TestContainerSpringBootTest @DisplayName("지원서 제출 서비스 테스트") -class ApplicationSubmissionServiceTest extends BaseIntegrationTest { +class ApplicationSubmissionServiceTest { @Autowired private ApplicationSubmissionService applicationSubmissionService; @@ -38,48 +42,76 @@ class ApplicationSubmissionServiceTest extends BaseIntegrationTest { private ApplicationRepository applicationRepository; @Autowired - private GpaScoreRepository gpaScoreRepository; + private SiteUserFixture siteUserFixture; @Autowired - private LanguageTestScoreRepository languageTestScoreRepository; + private UniversityInfoForApplyFixture universityInfoForApplyFixture; + + @Autowired + private LanguageRequirementFixture languageRequirementFixture; + + @Autowired + private GpaScoreFixture gpaScoreFixture; + + @Autowired + private LanguageTestScoreFixture languageTestScoreFixture; + + @Value("${university.term}") + private String term; + + private SiteUser user; + private UniversityInfoForApply 괌대학_A_지원_정보; + private UniversityInfoForApply 괌대학_B_지원_정보; + private UniversityInfoForApply 서던덴마크대학교_지원_정보; + + @BeforeEach + void setUp() { + user = siteUserFixture.사용자(); + + 괌대학_A_지원_정보 = universityInfoForApplyFixture.괌대학_A_지원_정보(); + languageRequirementFixture.토플_80(괌대학_A_지원_정보); + languageRequirementFixture.토익_800(괌대학_A_지원_정보); + + 괌대학_B_지원_정보 = universityInfoForApplyFixture.괌대학_B_지원_정보(); + languageRequirementFixture.토플_70(괌대학_B_지원_정보); + languageRequirementFixture.토익_900(괌대학_B_지원_정보); + + 서던덴마크대학교_지원_정보 = universityInfoForApplyFixture.서던덴마크대학교_지원_정보(); + languageRequirementFixture.토플_70(서던덴마크대학교_지원_정보); + } @Test void 정상적으로_지원서를_제출한다() { // given - GpaScore gpaScore = createApprovedGpaScore(테스트유저_1); - LanguageTestScore languageTestScore = createApprovedLanguageTestScore(테스트유저_1); + GpaScore gpaScore = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user); + LanguageTestScore languageTestScore = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user); UniversityChoiceRequest universityChoiceRequest = new UniversityChoiceRequest( 괌대학_A_지원_정보.getId(), - 네바다주립대학_라스베이거스_지원_정보.getId(), - 메모리얼대학_세인트존스_A_지원_정보.getId() + 괌대학_B_지원_정보.getId(), + 서던덴마크대학교_지원_정보.getId() ); ApplyRequest request = new ApplyRequest(gpaScore.getId(), languageTestScore.getId(), universityChoiceRequest); // when - ApplicationSubmissionResponse response = applicationSubmissionService.apply(테스트유저_1, request); + ApplicationSubmissionResponse response = applicationSubmissionService.apply(user, request); // then - Application savedApplication = applicationRepository.findBySiteUserAndTerm(테스트유저_1, term).orElseThrow(); + Application savedApplication = applicationRepository.findBySiteUserAndTerm(user, term).orElseThrow(); assertAll( () -> assertThat(response.applyCount()).isEqualTo(savedApplication.getUpdateCount()), - () -> assertThat(savedApplication.getGpa()).isEqualTo(gpaScore.getGpa()), - () -> assertThat(savedApplication.getLanguageTest()).isEqualTo(languageTestScore.getLanguageTest()), () -> assertThat(savedApplication.getVerifyStatus()).isEqualTo(VerifyStatus.APPROVED), - () -> assertThat(savedApplication.getNicknameForApply()).isNotNull(), - () -> assertThat(savedApplication.getTerm()).isEqualTo(term), () -> assertThat(savedApplication.isDelete()).isFalse(), () -> assertThat(savedApplication.getFirstChoiceUniversity().getId()).isEqualTo(괌대학_A_지원_정보.getId()), - () -> assertThat(savedApplication.getSecondChoiceUniversity().getId()).isEqualTo(네바다주립대학_라스베이거스_지원_정보.getId()), - () -> assertThat(savedApplication.getThirdChoiceUniversity().getId()).isEqualTo(메모리얼대학_세인트존스_A_지원_정보.getId()), - () -> assertThat(savedApplication.getSiteUser().getId()).isEqualTo(테스트유저_1.getId()) + () -> assertThat(savedApplication.getSecondChoiceUniversity().getId()).isEqualTo(괌대학_B_지원_정보.getId()), + () -> assertThat(savedApplication.getThirdChoiceUniversity().getId()).isEqualTo(서던덴마크대학교_지원_정보.getId()) ); } @Test void 미승인된_GPA_성적으로_지원하면_예외_응답을_반환한다() { // given - GpaScore gpaScore = createUnapprovedGpaScore(테스트유저_1); - LanguageTestScore languageTestScore = createApprovedLanguageTestScore(테스트유저_1); + GpaScore gpaScore = gpaScoreFixture.GPA_점수(VerifyStatus.PENDING, user); + LanguageTestScore languageTestScore = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user); UniversityChoiceRequest universityChoiceRequest = new UniversityChoiceRequest( 괌대학_A_지원_정보.getId(), null, @@ -89,7 +121,7 @@ class ApplicationSubmissionServiceTest extends BaseIntegrationTest { // when & then assertThatCode(() -> - applicationSubmissionService.apply(테스트유저_1, request) + applicationSubmissionService.apply(user, request) ) .isInstanceOf(CustomException.class) .hasMessage(INVALID_GPA_SCORE_STATUS.getMessage()); @@ -98,8 +130,8 @@ class ApplicationSubmissionServiceTest extends BaseIntegrationTest { @Test void 미승인된_어학성적으로_지원하면_예외_응답을_반환한다() { // given - GpaScore gpaScore = createApprovedGpaScore(테스트유저_1); - LanguageTestScore languageTestScore = createUnapprovedLanguageTestScore(테스트유저_1); + GpaScore gpaScore = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user); + LanguageTestScore languageTestScore = languageTestScoreFixture.어학_점수(VerifyStatus.PENDING, user); UniversityChoiceRequest universityChoiceRequest = new UniversityChoiceRequest( 괌대학_A_지원_정보.getId(), null, @@ -109,7 +141,7 @@ class ApplicationSubmissionServiceTest extends BaseIntegrationTest { // when & then assertThatCode(() -> - applicationSubmissionService.apply(테스트유저_1, request) + applicationSubmissionService.apply(user, request) ) .isInstanceOf(CustomException.class) .hasMessage(INVALID_LANGUAGE_TEST_SCORE_STATUS.getMessage()); @@ -118,8 +150,8 @@ class ApplicationSubmissionServiceTest extends BaseIntegrationTest { @Test void 지원서_수정_횟수를_초과하면_예외_응답을_반환한다() { // given - GpaScore gpaScore = createApprovedGpaScore(테스트유저_1); - LanguageTestScore languageTestScore = createApprovedLanguageTestScore(테스트유저_1); + GpaScore gpaScore = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user); + LanguageTestScore languageTestScore = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user); UniversityChoiceRequest universityChoiceRequest = new UniversityChoiceRequest( 괌대학_A_지원_정보.getId(), null, @@ -128,48 +160,14 @@ class ApplicationSubmissionServiceTest extends BaseIntegrationTest { ApplyRequest request = new ApplyRequest(gpaScore.getId(), languageTestScore.getId(), universityChoiceRequest); for (int i = 0; i < APPLICATION_UPDATE_COUNT_LIMIT; i++) { - applicationSubmissionService.apply(테스트유저_1, request); + applicationSubmissionService.apply(user, request); } // when & then assertThatCode(() -> - applicationSubmissionService.apply(테스트유저_1, request) + applicationSubmissionService.apply(user, request) ) .isInstanceOf(CustomException.class) .hasMessage(APPLY_UPDATE_LIMIT_EXCEED.getMessage()); } - - private GpaScore createUnapprovedGpaScore(SiteUser siteUser) { - GpaScore gpaScore = new GpaScore( - new Gpa(4.0, 4.5, "/gpa-report.pdf"), - siteUser - ); - return gpaScoreRepository.save(gpaScore); - } - - private GpaScore createApprovedGpaScore(SiteUser siteUser) { - GpaScore gpaScore = new GpaScore( - new Gpa(4.0, 4.5, "/gpa-report.pdf"), - siteUser - ); - gpaScore.setVerifyStatus(VerifyStatus.APPROVED); - return gpaScoreRepository.save(gpaScore); - } - - private LanguageTestScore createUnapprovedLanguageTestScore(SiteUser siteUser) { - LanguageTestScore languageTestScore = new LanguageTestScore( - new LanguageTest(LanguageTestType.TOEIC, "100", "/gpa-report.pdf"), - siteUser - ); - return languageTestScoreRepository.save(languageTestScore); - } - - private LanguageTestScore createApprovedLanguageTestScore(SiteUser siteUser) { - LanguageTestScore languageTestScore = new LanguageTestScore( - new LanguageTest(LanguageTestType.TOEIC, "100", "/gpa-report.pdf"), - siteUser - ); - languageTestScore.setVerifyStatus(VerifyStatus.APPROVED); - return languageTestScoreRepository.save(languageTestScore); - } } From e4e83129ff18e47079ee56286e87e06557dae56c Mon Sep 17 00:00:00 2001 From: Gyuhyeok99 <126947828+Gyuhyeok99@users.noreply.github.com> Date: Thu, 22 May 2025 20:47:28 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=84=B1=EC=A0=81=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=84=B8=ED=8C=85=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ApplicationQueryServiceTest.java | 11 ----------- .../service/ApplicationSubmissionServiceTest.java | 12 ------------ 2 files changed, 23 deletions(-) diff --git a/src/test/java/com/example/solidconnection/application/service/ApplicationQueryServiceTest.java b/src/test/java/com/example/solidconnection/application/service/ApplicationQueryServiceTest.java index ec68fa440..ac0b83619 100644 --- a/src/test/java/com/example/solidconnection/application/service/ApplicationQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/application/service/ApplicationQueryServiceTest.java @@ -16,7 +16,6 @@ import com.example.solidconnection.siteuser.fixture.SiteUserFixture; import com.example.solidconnection.support.TestContainerSpringBootTest; import com.example.solidconnection.university.domain.UniversityInfoForApply; -import com.example.solidconnection.university.fixture.LanguageRequirementFixture; import com.example.solidconnection.university.fixture.UniversityInfoForApplyFixture; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -48,9 +47,6 @@ class ApplicationQueryServiceTest { @Autowired private UniversityInfoForApplyFixture universityInfoForApplyFixture; - @Autowired - private LanguageRequirementFixture languageRequirementFixture; - @Autowired private GpaScoreFixture gpaScoreFixture; @@ -94,15 +90,8 @@ void setUp() { languageTestScore3 = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user3); 괌대학_A_지원_정보 = universityInfoForApplyFixture.괌대학_A_지원_정보(); - languageRequirementFixture.토플_80(괌대학_A_지원_정보); - languageRequirementFixture.토익_800(괌대학_A_지원_정보); - 괌대학_B_지원_정보 = universityInfoForApplyFixture.괌대학_B_지원_정보(); - languageRequirementFixture.토플_70(괌대학_B_지원_정보); - languageRequirementFixture.토익_900(괌대학_B_지원_정보); - 서던덴마크대학교_지원_정보 = universityInfoForApplyFixture.서던덴마크대학교_지원_정보(); - languageRequirementFixture.토플_70(서던덴마크대학교_지원_정보); } @Nested diff --git a/src/test/java/com/example/solidconnection/application/service/ApplicationSubmissionServiceTest.java b/src/test/java/com/example/solidconnection/application/service/ApplicationSubmissionServiceTest.java index 3884f51dc..f70cd9fc0 100644 --- a/src/test/java/com/example/solidconnection/application/service/ApplicationSubmissionServiceTest.java +++ b/src/test/java/com/example/solidconnection/application/service/ApplicationSubmissionServiceTest.java @@ -15,7 +15,6 @@ import com.example.solidconnection.siteuser.fixture.SiteUserFixture; import com.example.solidconnection.support.TestContainerSpringBootTest; import com.example.solidconnection.university.domain.UniversityInfoForApply; -import com.example.solidconnection.university.fixture.LanguageRequirementFixture; import com.example.solidconnection.university.fixture.UniversityInfoForApplyFixture; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -47,9 +46,6 @@ class ApplicationSubmissionServiceTest { @Autowired private UniversityInfoForApplyFixture universityInfoForApplyFixture; - @Autowired - private LanguageRequirementFixture languageRequirementFixture; - @Autowired private GpaScoreFixture gpaScoreFixture; @@ -67,17 +63,9 @@ class ApplicationSubmissionServiceTest { @BeforeEach void setUp() { user = siteUserFixture.사용자(); - 괌대학_A_지원_정보 = universityInfoForApplyFixture.괌대학_A_지원_정보(); - languageRequirementFixture.토플_80(괌대학_A_지원_정보); - languageRequirementFixture.토익_800(괌대학_A_지원_정보); - 괌대학_B_지원_정보 = universityInfoForApplyFixture.괌대학_B_지원_정보(); - languageRequirementFixture.토플_70(괌대학_B_지원_정보); - languageRequirementFixture.토익_900(괌대학_B_지원_정보); - 서던덴마크대학교_지원_정보 = universityInfoForApplyFixture.서던덴마크대학교_지원_정보(); - languageRequirementFixture.토플_70(서던덴마크대학교_지원_정보); } @Test