From 4e7407c979a73eea84144e50ea621c92eb5bb7b0 Mon Sep 17 00:00:00 2001 From: weonest Date: Wed, 27 Dec 2023 21:07:52 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:bug:=20=EA=B9=83=20=ED=98=95=EC=83=81=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EC=8B=A4=ED=8C=A8=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 + .../repository/ApplicationRepository.java | 2 + .../exception/ApplicationErrorCode.java | 4 +- .../service/ApplicationService.java | 40 +++- .../global/advice/GlobalExceptionHandler.java | 28 +-- .../java/dev/steady/steady/domain/Steady.java | 33 +-- .../dto/request/SteadyCreateRequest.java | 10 +- .../dto/request/SteadyUpdateRequest.java | 3 +- .../dto/response/SteadyDetailResponse.java | 3 +- .../steady/steady/dto/response/SteadyDto.java | 10 - .../steady/steady/service/SteadyService.java | 1 - .../repository/ApplicationRepositoryTest.java | 22 +- .../service/ApplicationServiceTest.java | 109 ++++++--- .../auth/service/AccountServiceTest.java | 8 +- .../service/NotificationServiceTest.java | 58 +++-- .../steady/review/fixture/ReviewFixture.java | 4 +- .../review/service/ReviewServiceTest.java | 32 ++- .../controller/SteadyControllerTest.java | 56 ++--- .../steady/steady/fixture/SteadyFixtures.java | 192 --------------- .../SteadySearchRepositoryImplTest.java | 151 ++++-------- .../steady/service/SteadyLikeServiceTest.java | 30 +-- .../steady/service/SteadyServiceTest.java | 226 ++++++------------ .../steady/template/domain/TemplateTest.java | 10 +- .../repository/TemplateRepositoryTest.java | 9 +- .../template/service/TemplateServiceTest.java | 13 +- .../controller/PositionControllerTest.java | 2 +- .../user/controller/StackControllerTest.java | 2 +- .../user/controller/UserControllerTest.java | 10 +- .../dev/steady/user/fixture/UserFixtures.java | 184 -------------- .../user/service/PositionServiceTest.java | 2 +- .../steady/user/service/StackServiceTest.java | 4 +- .../steady/user/service/UserServiceTest.java | 32 +-- 32 files changed, 418 insertions(+), 877 deletions(-) delete mode 100644 src/main/java/dev/steady/steady/dto/response/SteadyDto.java delete mode 100644 src/test/java/dev/steady/steady/fixture/SteadyFixtures.java delete mode 100644 src/test/java/dev/steady/user/fixture/UserFixtures.java diff --git a/build.gradle b/build.gradle index 1c2e652..195f481 100644 --- a/build.gradle +++ b/build.gradle @@ -54,6 +54,7 @@ dependencies { // Test testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation group: 'org.instancio', name: 'instancio-junit', version: '3.0.0' // restdocs + swagger testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' testImplementation 'com.epages:restdocs-api-spec-mockmvc:0.18.3' @@ -95,3 +96,7 @@ tasks.register('copyDocs') { bootJar { dependsOn(':copyDocs') } + +jar { + enabled = false +} diff --git a/src/main/java/dev/steady/application/domain/repository/ApplicationRepository.java b/src/main/java/dev/steady/application/domain/repository/ApplicationRepository.java index c5cc080..b25d32e 100644 --- a/src/main/java/dev/steady/application/domain/repository/ApplicationRepository.java +++ b/src/main/java/dev/steady/application/domain/repository/ApplicationRepository.java @@ -21,6 +21,8 @@ default Application getById(Long applicationId) { Slice findAllByUser(User user, Pageable pageable); + Optional findBySteadyIdAndUserId(Long steadyId, Long userId); + Optional findBySteadyIdAndUserIdAndStatus(Long steadyId, Long userId, ApplicationStatus status); Slice findAllBySteadyIdAndStatus(Long steadyId, ApplicationStatus status, Pageable pageable); diff --git a/src/main/java/dev/steady/application/exception/ApplicationErrorCode.java b/src/main/java/dev/steady/application/exception/ApplicationErrorCode.java index 6a5877b..2c53a24 100644 --- a/src/main/java/dev/steady/application/exception/ApplicationErrorCode.java +++ b/src/main/java/dev/steady/application/exception/ApplicationErrorCode.java @@ -9,7 +9,9 @@ public enum ApplicationErrorCode implements ErrorCode { APPLICATION_NOT_FOUND("AP01", "신청서를 찾을 수 없습니다."), - APPLICATION_AUTH_FAILURE("AP02", "신청서에 접근 권한이 없습니다."); + APPLICATION_AUTH_FAILURE("AP02", "신청서에 접근 권한이 없습니다."), + STEADY_LEADER_SUBMISSION("AP03", "스테디 리더는 신청서를 제출할 수 없습니다."), + APPLICATION_DUPLICATION("AP04","신청서는 중복 제출이 불가능합니다."); private final String errorCode; private final String message; diff --git a/src/main/java/dev/steady/application/service/ApplicationService.java b/src/main/java/dev/steady/application/service/ApplicationService.java index e54a36d..7621744 100644 --- a/src/main/java/dev/steady/application/service/ApplicationService.java +++ b/src/main/java/dev/steady/application/service/ApplicationService.java @@ -14,6 +14,8 @@ import dev.steady.application.dto.response.MyApplicationSummaryResponse; import dev.steady.application.dto.response.SliceResponse; import dev.steady.global.auth.UserInfo; +import dev.steady.global.exception.DuplicateException; +import dev.steady.global.exception.ForbiddenException; import dev.steady.notification.domain.ApplicationResultNotificationStrategy; import dev.steady.notification.domain.FreshApplicationNotificationStrategy; import dev.steady.notification.domain.NotificationStrategy; @@ -34,6 +36,8 @@ import static dev.steady.application.domain.ApplicationStatus.ACCEPTED; import static dev.steady.application.domain.ApplicationStatus.WAITING; +import static dev.steady.application.exception.ApplicationErrorCode.APPLICATION_DUPLICATION; +import static dev.steady.application.exception.ApplicationErrorCode.STEADY_LEADER_SUBMISSION; @Slf4j @Service @@ -50,15 +54,13 @@ public class ApplicationService { public CreateApplicationResponse createApplication(Long steadyId, List request, UserInfo userInfo) { User user = userRepository.getUserBy(userInfo.userId()); Steady steady = steadyRepository.getSteady(steadyId); + checkIfLeaderAndValidateDuplication(steady, user, steadyId); - Application application = new Application(user, steady); - Application savedApplication = applicationRepository.save(application); - - List surveyResult = createSurveyResult(application, request); - surveyResultRepository.saveAll(surveyResult); + Application application = saveApplication(user, steady); + saveSurveyResults(application, request); createNotification(new FreshApplicationNotificationStrategy(steady)); - return CreateApplicationResponse.from(savedApplication); + return CreateApplicationResponse.from(application); } @Transactional(readOnly = true) @@ -123,13 +125,37 @@ public void deleteApplication(Long applicationId, UserInfo userInfo) { applicationRepository.delete(application); } + private void saveSurveyResults(Application application, List requests) { + List surveyResults = createSurveyResults(application, requests); + surveyResultRepository.saveAll(surveyResults); + } + + private Application saveApplication(User user, Steady steady) { + Application application = new Application(user, steady); + return applicationRepository.save(application); + } + + private void checkIfLeaderAndValidateDuplication(Steady steady, User user, Long steadyId) { + if (steady.isLeader(user)) { + throw new ForbiddenException(STEADY_LEADER_SUBMISSION); + } + validateApplicationDuplication(steadyId, user); + } + + private void validateApplicationDuplication(Long steadyId, User user) { + applicationRepository.findBySteadyIdAndUserId(steadyId, user.getId()) + .ifPresent(application -> { + throw new DuplicateException(APPLICATION_DUPLICATION); + }); + } + private void addParticipant(Application application, User leader) { Steady steady = application.getSteady(); User user = application.getUser(); steady.addParticipantByLeader(leader, user); } - private List createSurveyResult(Application application, List surveys) { + private List createSurveyResults(Application application, List surveys) { return IntStream.range(0, surveys.size()) .mapToObj(index -> SurveyResult.create(application, surveys.get(index).question(), diff --git a/src/main/java/dev/steady/global/advice/GlobalExceptionHandler.java b/src/main/java/dev/steady/global/advice/GlobalExceptionHandler.java index e7457d4..fc42914 100644 --- a/src/main/java/dev/steady/global/advice/GlobalExceptionHandler.java +++ b/src/main/java/dev/steady/global/advice/GlobalExceptionHandler.java @@ -2,6 +2,8 @@ import dev.steady.auth.exception.OAuthPlatformException; import dev.steady.global.exception.AuthenticationException; +import dev.steady.global.exception.BusinessException; +import dev.steady.global.exception.DuplicateException; import dev.steady.global.exception.ErrorCode; import dev.steady.global.exception.ForbiddenException; import dev.steady.global.exception.GlobalErrorCode; @@ -18,6 +20,7 @@ import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.UNAUTHORIZED; @Slf4j @@ -31,45 +34,38 @@ public ResponseEntity handlerException(Exception e) { .body(ErrorResponse.of(GlobalErrorCode.INTERNAL_SERVER_ERROR)); } - @ExceptionHandler - public ResponseEntity handlerException(AuthenticationException exception) { + @ExceptionHandler({InvalidStateException.class, InvalidValueException.class, DuplicateException.class}) + public ResponseEntity handlerException(BusinessException exception) { ErrorCode errorCode = exception.getErrorCode(); log.info(errorCode.message(), exception); - return ResponseEntity.status(UNAUTHORIZED) + return ResponseEntity.badRequest() .body(ErrorResponse.of(exception.getErrorCode())); } @ExceptionHandler - public ResponseEntity handlerException(ForbiddenException exception) { + public ResponseEntity handlerException(AuthenticationException exception) { ErrorCode errorCode = exception.getErrorCode(); log.info(errorCode.message(), exception); - return ResponseEntity.status(FORBIDDEN) + return ResponseEntity.status(UNAUTHORIZED) .body(ErrorResponse.of(exception.getErrorCode())); } @ExceptionHandler - public ResponseEntity handlerException(NotFoundException exception) { + public ResponseEntity handlerException(ForbiddenException exception) { ErrorCode errorCode = exception.getErrorCode(); log.info(errorCode.message(), exception); - return ResponseEntity.badRequest() + return ResponseEntity.status(FORBIDDEN) .body(ErrorResponse.of(exception.getErrorCode())); } @ExceptionHandler - public ResponseEntity handlerException(InvalidStateException exception) { + public ResponseEntity handlerException(NotFoundException exception) { ErrorCode errorCode = exception.getErrorCode(); log.info(errorCode.message(), exception); - return ResponseEntity.badRequest() + return ResponseEntity.status(NOT_FOUND) .body(ErrorResponse.of(exception.getErrorCode())); } - @ExceptionHandler - public ResponseEntity handlerException(InvalidValueException exception) { - ErrorCode errorCode = exception.getErrorCode(); - log.info(errorCode.message(), exception); - return ResponseEntity.badRequest() - .body(ErrorResponse.of(exception.getErrorCode())); - } @ExceptionHandler public ResponseEntity handlerException(OAuthPlatformException exception) { diff --git a/src/main/java/dev/steady/steady/domain/Steady.java b/src/main/java/dev/steady/steady/domain/Steady.java index 6447243..1a67165 100644 --- a/src/main/java/dev/steady/steady/domain/Steady.java +++ b/src/main/java/dev/steady/steady/domain/Steady.java @@ -37,6 +37,7 @@ public class Steady extends BaseEntity { private static final long REVIEW_POLICY = 2L; private static final int DEFAULT_VIEW_COUNT = 0; + private static final int DEFAULT_LIKE_COUNT = 0; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -108,10 +109,10 @@ private Steady(String name, LocalDate deadline, String title, String content, - User user, + User leader, List stacks) { this.promotion = new Promotion(); - this.participants = createParticipants(user, participantLimit); + this.participants = createParticipants(leader, participantLimit); this.numberOfParticipants = participants.getNumberOfParticipants(); this.name = name; this.bio = bio; @@ -128,7 +129,7 @@ private Steady(String name, this.steadyStacks = createSteadyStack(stacks); } - public void update(User user, + public void update(User leader, String name, String bio, String contact, @@ -136,12 +137,12 @@ public void update(User user, SteadyStatus status, int participantLimit, SteadyMode steadyMode, - String scheduledPeriod, + ScheduledPeriod scheduledPeriod, LocalDate deadline, String title, String content, List stacks) { - validateLeader(user); + validateLeader(leader); this.name = name; this.bio = bio; this.contact = contact; @@ -149,7 +150,7 @@ public void update(User user, this.status = status; this.participants.updateParticipantLimit(participantLimit); this.steadyMode = steadyMode; - this.scheduledPeriod = ScheduledPeriod.valueOf(scheduledPeriod); + this.scheduledPeriod = scheduledPeriod; this.deadline = deadline; this.title = title; this.content = content; @@ -157,8 +158,8 @@ public void update(User user, this.steadyStacks.addAll(createSteadyStack(stacks)); } - public void validateLeader(User user) { - if (!isLeader(user)) { + public void validateLeader(User leader) { + if (!isLeader(leader)) { throw new ForbiddenException(LEADER_PERMISSION_NEEDED); } } @@ -183,13 +184,13 @@ public void expelParticipantByLeader(User leader, Participant participant) { numberOfParticipants = participants.getNumberOfParticipants(); } - public void usePromotion(User user) { - validateLeader(user); + public void usePromotion(User leader) { + validateLeader(leader); promotion.use(); } - public void finish(User user) { - validateLeader(user); + public void finish(User leader) { + validateLeader(leader); if (finishedAt != null) { throw new InvalidStateException(ALREADY_FINISHED); } @@ -212,8 +213,8 @@ public int getParticipantLimit() { return participants.getParticipantLimit(); } - public boolean isDeletable(User user) { - validateLeader(user); + public boolean isDeletable(User leader) { + validateLeader(leader); return numberOfParticipants == 1; } @@ -237,9 +238,9 @@ public void decreaseLikeCount() { this.likeCount--; } - private Participants createParticipants(User user, int participantLimit) { + private Participants createParticipants(User leader, int participantLimit) { Participants participants = new Participants(participantLimit); - participants.add(Participant.createLeader(user, this)); + participants.add(Participant.createLeader(leader, this)); return participants; } diff --git a/src/main/java/dev/steady/steady/dto/request/SteadyCreateRequest.java b/src/main/java/dev/steady/steady/dto/request/SteadyCreateRequest.java index 09e5ef6..27426c6 100644 --- a/src/main/java/dev/steady/steady/dto/request/SteadyCreateRequest.java +++ b/src/main/java/dev/steady/steady/dto/request/SteadyCreateRequest.java @@ -4,6 +4,7 @@ import dev.steady.steady.domain.Steady; import dev.steady.steady.domain.SteadyMode; import dev.steady.steady.domain.SteadyType; +import dev.steady.user.domain.Stack; import dev.steady.user.domain.User; import jakarta.validation.constraints.FutureOrPresent; import jakarta.validation.constraints.NotBlank; @@ -30,7 +31,7 @@ public record SteadyCreateRequest( @NotNull(message = "NULL은 올 수 없습니다.") SteadyMode steadyMode, @NotNull(message = "NULL은 올 수 없습니다.") - String scheduledPeriod, + ScheduledPeriod scheduledPeriod, @FutureOrPresent(message = "마감 종료일은 오늘 이후로 설정해야합니다.") LocalDate deadline, @Size(min = 2, max = 25, message = "모집글 제목은 2글자 이상 25글자 이하입니다.") @@ -45,7 +46,7 @@ public record SteadyCreateRequest( List questions ) { - public Steady toEntity(User user) { + public Steady toEntity(User leader, List stacks) { return Steady.builder() .name(name) .bio(bio) @@ -53,11 +54,12 @@ public Steady toEntity(User user) { .type(type) .participantLimit(participantLimit) .steadyMode(steadyMode) - .scheduledPeriod(ScheduledPeriod.valueOf(scheduledPeriod)) + .scheduledPeriod(scheduledPeriod) .deadline(deadline) .title(title) .content(content) - .user(user) + .leader(leader) + .stacks(stacks) .build(); } diff --git a/src/main/java/dev/steady/steady/dto/request/SteadyUpdateRequest.java b/src/main/java/dev/steady/steady/dto/request/SteadyUpdateRequest.java index 72abac7..e991d59 100644 --- a/src/main/java/dev/steady/steady/dto/request/SteadyUpdateRequest.java +++ b/src/main/java/dev/steady/steady/dto/request/SteadyUpdateRequest.java @@ -1,5 +1,6 @@ package dev.steady.steady.dto.request; +import dev.steady.steady.domain.ScheduledPeriod; import dev.steady.steady.domain.SteadyMode; import dev.steady.steady.domain.SteadyStatus; import dev.steady.steady.domain.SteadyType; @@ -30,7 +31,7 @@ public record SteadyUpdateRequest( @NotNull(message = "NULL은 올 수 없습니다.") SteadyMode steadyMode, @NotNull(message = "NULL은 올 수 없습니다.") - String scheduledPeriod, + ScheduledPeriod scheduledPeriod, @FutureOrPresent(message = "마감 종료일은 오늘 이후로 설정해야합니다.") LocalDate deadline, @Size(min = 2, max = 25, message = "모집글 제목은 2글자 이상 25글자 이하입니다.") diff --git a/src/main/java/dev/steady/steady/dto/response/SteadyDetailResponse.java b/src/main/java/dev/steady/steady/dto/response/SteadyDetailResponse.java index cf5c1f7..9aa546c 100644 --- a/src/main/java/dev/steady/steady/dto/response/SteadyDetailResponse.java +++ b/src/main/java/dev/steady/steady/dto/response/SteadyDetailResponse.java @@ -41,7 +41,6 @@ public record SteadyDetailResponse( public static SteadyDetailResponse of(Steady steady, List positions, - List stacks, boolean isLeader, Long applicationId, boolean isLiked) { @@ -63,7 +62,7 @@ public static SteadyDetailResponse of(Steady steady, positions.stream() .map(SteadyPositionResponse::from) .toList(), - stacks.stream() + steady.getSteadyStacks().stream() .map(SteadyStackResponse::from) .toList(), isLeader, diff --git a/src/main/java/dev/steady/steady/dto/response/SteadyDto.java b/src/main/java/dev/steady/steady/dto/response/SteadyDto.java deleted file mode 100644 index 9450720..0000000 --- a/src/main/java/dev/steady/steady/dto/response/SteadyDto.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.steady.steady.dto.response; - -import java.time.LocalDateTime; - -public record SteadyDto( - Long id, - String name, - LocalDateTime promoted_at -) { -} diff --git a/src/main/java/dev/steady/steady/service/SteadyService.java b/src/main/java/dev/steady/steady/service/SteadyService.java index e3cf350..8622169 100644 --- a/src/main/java/dev/steady/steady/service/SteadyService.java +++ b/src/main/java/dev/steady/steady/service/SteadyService.java @@ -185,7 +185,6 @@ public void deleteSteady(Long steadyId, UserInfo userInfo) { User user = userRepository.getUserBy(userInfo.userId()); Steady steady = steadyRepository.getSteady(steadyId); if (steady.isDeletable(user)) { - steadyStackRepository.deleteBySteadyId(steadyId); steadyPositionRepository.deleteBySteadyId(steadyId); steadyQuestionRepository.deleteBySteadyId(steadyId); steadyRepository.delete(steady); diff --git a/src/test/java/dev/steady/application/domain/repository/ApplicationRepositoryTest.java b/src/test/java/dev/steady/application/domain/repository/ApplicationRepositoryTest.java index 49770d9..5d48557 100644 --- a/src/test/java/dev/steady/application/domain/repository/ApplicationRepositoryTest.java +++ b/src/test/java/dev/steady/application/domain/repository/ApplicationRepositoryTest.java @@ -20,12 +20,10 @@ import static dev.steady.application.domain.ApplicationStatus.WAITING; import static dev.steady.application.fixture.ApplicationFixture.createApplication; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createSecondUser; -import static dev.steady.user.fixture.UserFixtures.createStack; -import static dev.steady.user.fixture.UserFixtures.createThirdUser; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteady; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -61,12 +59,12 @@ void tearDown() { @Test void findAllBySteadyId() { //given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var savedStack = stackRepository.save(createStack()); - var steady = steadyRepository.save(createSteady(leader, savedStack)); - var secondUser = userRepository.save(createSecondUser(position)); - var thirdUser = userRepository.save(createThirdUser(position)); + var position = positionRepository.save(generatePosition()); + var leader = userRepository.save(generateUser(position)); + var savedStack = stackRepository.save(generateStack()); + var steady = steadyRepository.save(createSteady(leader, List.of(savedStack))); + var secondUser = userRepository.save(generateUser(position)); + var thirdUser = userRepository.save(generateUser(position)); applicationRepository.saveAll(List.of(createApplication(secondUser, steady), createApplication(thirdUser, steady))); //when diff --git a/src/test/java/dev/steady/application/service/ApplicationServiceTest.java b/src/test/java/dev/steady/application/service/ApplicationServiceTest.java index 226d228..49696f9 100644 --- a/src/test/java/dev/steady/application/service/ApplicationServiceTest.java +++ b/src/test/java/dev/steady/application/service/ApplicationServiceTest.java @@ -12,6 +12,7 @@ import dev.steady.application.dto.response.MyApplicationSummaryResponse; import dev.steady.application.dto.response.SliceResponse; import dev.steady.global.auth.UserInfo; +import dev.steady.global.exception.DuplicateException; import dev.steady.global.exception.ForbiddenException; import dev.steady.global.exception.NotFoundException; import dev.steady.notification.domain.repository.NotificationRepository; @@ -40,12 +41,10 @@ import static dev.steady.application.fixture.SurveyResultFixture.createAnswers; import static dev.steady.application.fixture.SurveyResultFixture.createSurveyResultRequests; import static dev.steady.global.auth.AuthFixture.createUserInfo; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createSecondUser; -import static dev.steady.user.fixture.UserFixtures.createStack; -import static dev.steady.user.fixture.UserFixtures.createThirdUser; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteady; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.groups.Tuple.tuple; @@ -84,9 +83,9 @@ class ApplicationServiceTest { @BeforeEach void setUp() { - this.position = positionRepository.save(createPosition()); - this.leader = userRepository.save(createFirstUser(position)); - this.stack = stackRepository.save(createStack()); + this.position = positionRepository.save(generatePosition()); + this.leader = userRepository.save(generateUser(position)); + this.stack = stackRepository.save(generateStack()); } @AfterEach @@ -104,9 +103,10 @@ void tearDown() { @Test void createApplicationTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); var surveyResultRequests = createSurveyResultRequests(); - var userInfo = createUserInfo(leader.getId()); + var otherUser = userRepository.save(generateUser(position)); + var userInfo = createUserInfo(otherUser.getId()); //when CreateApplicationResponse response = applicationService.createApplication(steady.getId(), @@ -117,13 +117,52 @@ void createApplicationTest() { assertThat(response.applicationId()).isNotNull(); } + @DisplayName("신청서를 중복으로 제출하면 중복 예외가 발생한다") + @Test + void duplicateApplicationTest() { + //given + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var surveyResultRequests = createSurveyResultRequests(); + var otherUser = userRepository.save(generateUser(position)); + var userInfo = createUserInfo(otherUser.getId()); + + //when + applicationService.createApplication(steady.getId(), + surveyResultRequests, + userInfo); + + //then + assertThatThrownBy( + () -> applicationService.createApplication(steady.getId(), + surveyResultRequests, + userInfo) + ).isInstanceOf(DuplicateException.class); + } + + @DisplayName("모집글 작성자가 신청서를 제출하면 예외가 발생한다") + @Test + void leaderSubmissionTest() { + //given + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var surveyResultRequests = createSurveyResultRequests(); + var userInfo = createUserInfo(leader.getId()); + + //when + //then + assertThatThrownBy( + () -> applicationService.createApplication(steady.getId(), + surveyResultRequests, + userInfo) + ).isInstanceOf(ForbiddenException.class); + } + @DisplayName("스터디 리더는 신청서 목록 조회를 할 수 있다.") @Test void getApplicationsTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); - var thirdUser = userRepository.save(createThirdUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); + var thirdUser = userRepository.save(generateUser(position)); applicationRepository.saveAll(List.of(createApplication(secondUser, steady), createApplication(thirdUser, steady))); //when @@ -136,16 +175,16 @@ void getApplicationsTest() { () -> assertThat(response.hasNext()).isFalse(), () -> assertThat(response.content()).hasSize(2) .extracting(ApplicationSummaryResponse::nickname) - .containsExactly("Jun", "Young")); + .containsExactly(secondUser.getNickname(), thirdUser.getNickname())); } @DisplayName("스터디 리더가 아니면 신청서 목록 조회를 할 수 없다.") @Test void getApplicationsFailTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); - var thirdUser = userRepository.save(createThirdUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); + var thirdUser = userRepository.save(generateUser(position)); applicationRepository.save(createApplication(secondUser, steady)); var userInfo = createUserInfo(thirdUser.getId()); var pageRequest = PageRequest.of(0, 10); @@ -161,8 +200,8 @@ void getApplicationsFailTest() { @Test void getApplicationDetailTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); var application = applicationRepository.save(createApplication(secondUser, steady)); surveyResultRepository.saveAll(createSurveyResults(application)); var userInfo = createUserInfo(leader.getId()); @@ -182,9 +221,9 @@ void getApplicationDetailTest() { @Test void getApplicationDetailFailTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); - var thirdUser = userRepository.save(createThirdUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); + var thirdUser = userRepository.save(generateUser(position)); var application = applicationRepository.save(createApplication(secondUser, steady)); var userInfo = createUserInfo(thirdUser.getId()); //when @@ -197,8 +236,8 @@ void getApplicationDetailFailTest() { @Test void createSurveyResultTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); var application = applicationRepository.save(createApplication(secondUser, steady)); var userInfo = createUserInfo(leader.getId()); var request = new ApplicationStatusUpdateRequest(ACCEPTED); @@ -214,8 +253,8 @@ void createSurveyResultTest() { @Test void createSurveyResultFailTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); var entity = createApplication(secondUser, steady); ReflectionTestUtils.setField(entity, "status", REJECTED); var application = applicationRepository.save(entity); @@ -232,8 +271,8 @@ void createSurveyResultFailTest() { @Test void updateApplicationAnswerTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); var application = createApplication(secondUser, steady); var savedApplication = applicationRepository.save(application); surveyResultRepository.saveAll(createSurveyResults(savedApplication)); @@ -255,8 +294,8 @@ void updateApplicationAnswerTest() { @Test void updateApplicationAnswerTest2() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); var application = createApplication(secondUser, steady); var savedApplication = applicationRepository.save(application); surveyResultRepository.saveAll(createSurveyResults(savedApplication)); @@ -273,8 +312,8 @@ void updateApplicationAnswerTest2() { @DisplayName("신청자는 본인이 신청한 신청서 리스트를 조회할 수 있다.") @Test void getMyApplications() { - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); var application = createApplication(secondUser, steady); var savedApplication = applicationRepository.save(application); var userInfo = new UserInfo(secondUser.getId()); @@ -291,8 +330,8 @@ void getMyApplications() { @DisplayName("본인의 신청서를 삭제할 수 있고 등록된 질답도 함께 삭제된다.") @Test void deleteApplication() { - var steady = steadyRepository.save(createSteady(leader, stack)); - var secondUser = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var secondUser = userRepository.save(generateUser(position)); var application = createApplication(secondUser, steady); var savedApplication = applicationRepository.save(application); var userInfo = new UserInfo(secondUser.getId()); diff --git a/src/test/java/dev/steady/auth/service/AccountServiceTest.java b/src/test/java/dev/steady/auth/service/AccountServiceTest.java index bdce8f1..f546782 100644 --- a/src/test/java/dev/steady/auth/service/AccountServiceTest.java +++ b/src/test/java/dev/steady/auth/service/AccountServiceTest.java @@ -3,7 +3,6 @@ import dev.steady.auth.domain.repository.AccountRepository; import dev.steady.user.domain.repository.PositionRepository; import dev.steady.user.domain.repository.UserRepository; -import dev.steady.user.fixture.UserFixtures; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -12,7 +11,8 @@ import org.springframework.transaction.support.TransactionTemplate; import static dev.steady.auth.fixture.AccountFixture.createAccount; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -48,10 +48,10 @@ void registerUser() { var account = createAccount(); var savedAccount = accountRepository.save(account); - var position = UserFixtures.createPosition(); + var position = generatePosition(); var savedPosition = positionRepository.save(position); - var user = createFirstUser(savedPosition); + var user = generateUser(savedPosition); var savedUser = userRepository.save(user); // when diff --git a/src/test/java/dev/steady/notification/service/NotificationServiceTest.java b/src/test/java/dev/steady/notification/service/NotificationServiceTest.java index dbdfb46..2972971 100644 --- a/src/test/java/dev/steady/notification/service/NotificationServiceTest.java +++ b/src/test/java/dev/steady/notification/service/NotificationServiceTest.java @@ -35,11 +35,10 @@ import static dev.steady.notification.domain.NotificationMessage.getFreshApplicationMessage; import static dev.steady.notification.fixture.NotificationFixture.createApplicationResultNoti; import static dev.steady.notification.fixture.NotificationFixture.createFreshApplicationNoti; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createSecondUser; -import static dev.steady.user.fixture.UserFixtures.createStack; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteady; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -80,9 +79,9 @@ class NotificationServiceTest { @BeforeEach void setUp() { - this.position = positionRepository.save(createPosition()); - this.leader = userRepository.save(createFirstUser(position)); - this.stack = stackRepository.save(createStack()); + this.position = positionRepository.save(generatePosition()); + this.leader = userRepository.save(generateUser(position)); + this.stack = stackRepository.save(generateStack()); } @AfterEach @@ -100,7 +99,7 @@ void tearDown() { @DisplayName("새로운 신청서에 대한 알림을 생성할 수 있다.") void createNewApplicationNotificationTest() { // given - var steady = steadyRepository.save(createSteady(leader, stack)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); var freshApplicationNoti = new FreshApplicationNotificationStrategy(steady); // when @@ -118,8 +117,8 @@ void createNewApplicationNotificationTest() { @DisplayName("신청서 결과에 대한 알림을 생성할 수 있다.") void createAcceptedApplicationNotificationTest() { // given - var steady = steadyRepository.save(createSteady(leader, stack)); - var user = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var user = userRepository.save(generateUser(position)); var application = createApplication(user, steady); application.updateStatus(ApplicationStatus.ACCEPTED, leader); var applicationResultNoti = new ApplicationResultNotificationStrategy(application); @@ -139,8 +138,8 @@ void createAcceptedApplicationNotificationTest() { @DisplayName("새로운 신청서가 등록되면 리더에게 새로운 신청 알림이 생성된다.") void createNotificationWhenCreateApplicationTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var user = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var user = userRepository.save(generateUser(position)); var surveyResultRequests = createSurveyResultRequests(); var userInfo = createUserInfo(user.getId()); @@ -159,8 +158,8 @@ void createNotificationWhenCreateApplicationTest() { @DisplayName("신청서가 거절 혹은 수락되면 유저에게 새로운 신청서 결과 알림이 생성된다.") void createNotificationWhenApplicationGotResultTest() { //given - var steady = steadyRepository.save(createSteady(leader, stack)); - var user = userRepository.save(createSecondUser(position)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + var user = userRepository.save(generateUser(position)); var application = applicationRepository.save(createApplication(user, steady)); var userInfo = createUserInfo(leader.getId()); var request = new ApplicationStatusUpdateRequest(ACCEPTED); @@ -180,10 +179,10 @@ void createNotificationWhenApplicationGotResultTest() { @DisplayName("전체 알림을 가져올 수 있다.") void getNotificationsTest() { // given - var user = userRepository.save(createSecondUser(position)); - var userInfo = createUserInfo(user.getId()); - notificationRepository.save(createFreshApplicationNoti(user)); - notificationRepository.save(createApplicationResultNoti(user)); + var userInfo = createUserInfo(leader.getId()); + steadyRepository.save(createSteady(leader, List.of(stack))); + notificationRepository.save(createFreshApplicationNoti(leader)); + notificationRepository.save(createApplicationResultNoti(leader)); // when NotificationsResponse notifications = notificationService.getNotifications(userInfo); @@ -197,9 +196,8 @@ void getNotificationsTest() { @DisplayName("알림을 읽음 상태로 변경할 수 있다.") void readNotificaitonTest() { // given - var user = userRepository.save(createSecondUser(position)); - var userInfo = createUserInfo(user.getId()); - var notification = notificationRepository.save(createFreshApplicationNoti(user)); + var userInfo = createUserInfo(leader.getId()); + var notification = notificationRepository.save(createFreshApplicationNoti(leader)); // when notificationService.readNotification(notification.getId(), userInfo); @@ -213,7 +211,7 @@ void readNotificaitonTest() { @DisplayName("모든 알림을 읽음 상태로 변경할 수 있다.") void readNotificaitonsTest() { // given - var user = userRepository.save(createSecondUser(position)); + var user = userRepository.save(generateUser(position)); var userInfo = createUserInfo(user.getId()); notificationRepository.save(createFreshApplicationNoti(user)); notificationRepository.save(createFreshApplicationNoti(user)); @@ -230,9 +228,8 @@ void readNotificaitonsTest() { @DisplayName("알림을 삭제할 수 있다.") void deleteNotificaitonTest() { // given - var user = userRepository.save(createSecondUser(position)); - var userInfo = createUserInfo(user.getId()); - Notification notification = notificationRepository.save(createFreshApplicationNoti(user)); + var userInfo = createUserInfo(leader.getId()); + Notification notification = notificationRepository.save(createFreshApplicationNoti(leader)); // when notificationService.deleteNotification(notification.getId(), userInfo); @@ -246,16 +243,15 @@ void deleteNotificaitonTest() { @DisplayName("모든 알림을 삭제할 수 있다.") void deleteNotificaitonsTest() { // given - var user = userRepository.save(createSecondUser(position)); - var userInfo = createUserInfo(user.getId()); - notificationRepository.save(createFreshApplicationNoti(user)); - notificationRepository.save(createFreshApplicationNoti(user)); + var userInfo = createUserInfo(leader.getId()); + notificationRepository.save(createFreshApplicationNoti(leader)); + notificationRepository.save(createFreshApplicationNoti(leader)); // when notificationService.deleteAll(userInfo); // then - assertThat(notificationRepository.findByReceiverId(user.getId())).isEmpty(); + assertThat(notificationRepository.findByReceiverId(leader.getId())).isEmpty(); } } diff --git a/src/test/java/dev/steady/review/fixture/ReviewFixture.java b/src/test/java/dev/steady/review/fixture/ReviewFixture.java index 68f3446..c89cae7 100644 --- a/src/test/java/dev/steady/review/fixture/ReviewFixture.java +++ b/src/test/java/dev/steady/review/fixture/ReviewFixture.java @@ -22,7 +22,7 @@ import java.time.LocalDateTime; import java.util.List; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyEntity; public class ReviewFixture { @@ -101,7 +101,7 @@ public static ReviewMyResponse createReviewMyResponse() { } public static ReviewInfoResponse createReviewInfoResponse() { - Steady steady = createSteady(); + Steady steady = createSteadyEntity(); LocalDate finishedAt = LocalDate.of(2023, 12, 2); ReviewSteadyResponse reviewSteadyResponse = ReviewSteadyResponse.builder() .steadyId(steady.getId()) diff --git a/src/test/java/dev/steady/review/service/ReviewServiceTest.java b/src/test/java/dev/steady/review/service/ReviewServiceTest.java index 36dbb7e..bf96908 100644 --- a/src/test/java/dev/steady/review/service/ReviewServiceTest.java +++ b/src/test/java/dev/steady/review/service/ReviewServiceTest.java @@ -40,12 +40,10 @@ import static dev.steady.review.fixture.ReviewFixture.createUserCard; import static dev.steady.steady.domain.Participant.createMember; import static dev.steady.steady.domain.SteadyStatus.FINISHED; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createSecondUser; -import static dev.steady.user.fixture.UserFixtures.createStack; -import static dev.steady.user.fixture.UserFixtures.createThirdUser; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyWithStatus; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -79,13 +77,13 @@ class ReviewServiceTest { @BeforeEach void setUp() { - var position = positionRepository.save(createPosition()); - this.leader = userRepository.save(createFirstUser(position)); - this.reviewerUser = userRepository.save(createSecondUser(position)); - this.revieweeUser = userRepository.save(createThirdUser(position)); + var position = positionRepository.save(generatePosition()); + this.leader = userRepository.save(generateUser(position)); + this.reviewerUser = userRepository.save(generateUser(position)); + this.revieweeUser = userRepository.save(generateUser(position)); this.stacks = stackRepository.saveAll( IntStream.range(0, 3) - .mapToObj(i -> createStack()) + .mapToObj(i -> generateStack()) .toList() ); } @@ -108,7 +106,7 @@ void createReviewTest() { // given var userInfo = createUserInfo(reviewerUser.getId()); - var steady = createSteady(leader, stacks, FINISHED); + var steady = createSteadyWithStatus(leader, stacks, FINISHED); ReflectionTestUtils.setField(steady, "finishedAt", LocalDate.now()); var savedSteady = steadyRepository.save(steady); @@ -137,7 +135,7 @@ void createReviewTest() { void createReviewAfterReviewEnabledPeriodTest() { // given var userInfo = createUserInfo(reviewerUser.getId()); - var steady = createSteady(leader, stacks, FINISHED); + var steady = createSteadyWithStatus(leader, stacks, FINISHED); var finishedAt = LocalDate.now().minusMonths(3); ReflectionTestUtils.setField(steady, "finishedAt", finishedAt); var savedSteady = steadyRepository.save(steady); @@ -164,7 +162,7 @@ void createUserCardsTest() { .toList(); List savedCards = cardRepository.saveAll(cards); - var steady = steadyRepository.save(createSteady(reviewerUser, stacks, FINISHED)); + var steady = steadyRepository.save(createSteadyWithStatus(reviewerUser, stacks, FINISHED)); var reviewee = participantRepository.save(createMember(revieweeUser, steady)); // when @@ -189,7 +187,7 @@ void createUserCardsTest() { void switchReviewIsPublicTest() { // given var userInfo = createUserInfo(revieweeUser.getId()); - var steady = steadyRepository.save(createSteady(leader, stacks, FINISHED)); + var steady = steadyRepository.save(createSteadyWithStatus(leader, stacks, FINISHED)); var reviewer = participantRepository.save(createMember(reviewerUser, steady)); var reviewee = participantRepository.save(createMember(revieweeUser, steady)); var review = reviewRepository.save(createReview(reviewer, reviewee, steady)); @@ -207,7 +205,7 @@ void switchReviewIsPublicTest() { void getMyReviewsTest() { // given var userInfo = createUserInfo(revieweeUser.getId()); - var steady = steadyRepository.save(createSteady(leader, stacks, FINISHED)); + var steady = steadyRepository.save(createSteadyWithStatus(leader, stacks, FINISHED)); var reviewer = participantRepository.save(createMember(reviewerUser, steady)); var reviewee = participantRepository.save(createMember(revieweeUser, steady)); var review = reviewRepository.save(createReview(reviewer, reviewee, steady)); @@ -233,7 +231,7 @@ void getReviewInfoTest() { // given var userInfo = createUserInfo(reviewerUser.getId()); - var steady = createSteady(leader, stacks, FINISHED); + var steady = createSteadyWithStatus(leader, stacks, FINISHED); var finishedAt = LocalDate.now(); var reviewDeadline = finishedAt.plusMonths(2L); diff --git a/src/test/java/dev/steady/steady/controller/SteadyControllerTest.java b/src/test/java/dev/steady/steady/controller/SteadyControllerTest.java index 6e9b029..2bb2c0a 100644 --- a/src/test/java/dev/steady/steady/controller/SteadyControllerTest.java +++ b/src/test/java/dev/steady/steady/controller/SteadyControllerTest.java @@ -8,7 +8,6 @@ import dev.steady.steady.dto.FilterConditionDto; import dev.steady.steady.dto.request.SteadyPageRequest; import dev.steady.steady.dto.request.SteadyQuestionUpdateRequest; -import dev.steady.steady.dto.request.SteadySearchRequest; import dev.steady.steady.dto.response.MySteadyResponse; import dev.steady.steady.dto.response.ParticipantsResponse; import dev.steady.steady.dto.response.SteadyDetailResponse; @@ -16,7 +15,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.data.domain.Pageable; -import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -26,15 +24,16 @@ import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.resourceDetails; import static dev.steady.global.auth.AuthFixture.createUserInfo; import static dev.steady.steady.domain.SteadyStatus.RECRUITING; -import static dev.steady.steady.fixture.SteadyFixtures.createMySteadyResponse; -import static dev.steady.steady.fixture.SteadyFixtures.createParticipantsResponse; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyPageResponse; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyPosition; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyQuestionsResponse; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyRequest; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyUpdateRequest; -import static dev.steady.user.fixture.UserFixtures.createPosition; +import static dev.steady.steady.fixture.SteadyFixturesV2.createDefaultSteadySearchRequest; +import static dev.steady.steady.fixture.SteadyFixturesV2.createMySteadyResponse; +import static dev.steady.steady.fixture.SteadyFixturesV2.createParticipantsResponse; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyEntity; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyPageResponse; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyPosition; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyQuestionsResponse; +import static dev.steady.steady.fixture.SteadyFixturesV2.generateSteadyCreateRequest; +import static dev.steady.steady.fixture.SteadyFixturesV2.generateSteadyUpdateRequest; +import static dev.steady.user.fixture.UserFixturesV2.generatePositionEntity; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -67,12 +66,10 @@ class SteadyControllerTest extends ControllerTestConfig { void createSteadyTest() throws Exception { // given var steadyId = 1L; - var stackId = 1L; - var positionId = 1L; var userId = 1L; var authentication = new Authentication(userId); var userInfo = createUserInfo(userId); - var steadyRequest = createSteadyRequest(stackId, positionId); + var steadyRequest = generateSteadyCreateRequest(1L, 1L); given(jwtResolver.getAuthentication(TOKEN)).willReturn(authentication); given(steadyService.create(steadyRequest, userInfo)).willReturn(steadyId); @@ -155,25 +152,12 @@ void findMySteadiesTest() throws Exception { @DisplayName("검색 조건에 따른 전체 조회 결과를 반환한다.") void getSteadiesByConditionTest() throws Exception { // given - var searchRequest = new SteadySearchRequest( - null, - null, - null, - null, - null, - null, - null, - null, - null, - "false", - null); - + var searchRequest = createDefaultSteadySearchRequest(); MultiValueMap params = new LinkedMultiValueMap<>() {{ + add("steadyType", null); add("page", null); add("direction", null); add("criteria", null); - add("cursor", null); - add("steadyType", null); add("steadyMode", null); add("stack", null); add("position", null); @@ -184,7 +168,7 @@ void getSteadiesByConditionTest() throws Exception { var pageable = searchRequest.toPageable(); var condition = FilterConditionDto.from(searchRequest); - var steady = createSteady(); + var steady = createSteadyEntity(); var response = createSteadyPageResponse(steady, pageable); given(steadyService.getSteadies(eq(new UserInfo(null)), any(FilterConditionDto.class), eq(pageable))).willReturn(response); @@ -245,11 +229,11 @@ void getDetailSteadyTest() throws Exception { var authentication = new Authentication(userId); var userInfo = createUserInfo(userId); - var steady = createSteady(); - var position = createPosition(); + var position = generatePositionEntity(); + var steady = createSteadyEntity(); var steadyPosition = createSteadyPosition(steady, position); - ReflectionTestUtils.setField(position, "id", 1L); - var response = SteadyDetailResponse.of(steady, + var response = SteadyDetailResponse.of( + steady, List.of(steadyPosition), true, 1L, @@ -353,11 +337,9 @@ void updateSteadyTest() throws Exception { // given var steadyId = 1L; var userId = 1L; - var stackId = 1L; - var positionId = 1L; var authentication = new Authentication(userId); var userInfo = createUserInfo(userId); - var request = createSteadyUpdateRequest(stackId, positionId); + var request = generateSteadyUpdateRequest(1L, 1L); given(jwtResolver.getAuthentication(TOKEN)).willReturn(authentication); willDoNothing().given(steadyService).updateSteady(steadyId, request, userInfo); diff --git a/src/test/java/dev/steady/steady/fixture/SteadyFixtures.java b/src/test/java/dev/steady/steady/fixture/SteadyFixtures.java deleted file mode 100644 index cdf612a..0000000 --- a/src/test/java/dev/steady/steady/fixture/SteadyFixtures.java +++ /dev/null @@ -1,192 +0,0 @@ -package dev.steady.steady.fixture; - - -import dev.steady.application.dto.response.SliceResponse; -import dev.steady.steady.domain.ScheduledPeriod; -import dev.steady.steady.domain.Steady; -import dev.steady.steady.domain.SteadyMode; -import dev.steady.steady.domain.SteadyPosition; -import dev.steady.steady.domain.SteadyQuestion; -import dev.steady.steady.domain.SteadyStack; -import dev.steady.steady.domain.SteadyStatus; -import dev.steady.steady.domain.SteadyType; -import dev.steady.steady.dto.request.SteadyCreateRequest; -import dev.steady.steady.dto.request.SteadyUpdateRequest; -import dev.steady.steady.dto.response.MySteadyResponse; -import dev.steady.steady.dto.response.PageResponse; -import dev.steady.steady.dto.response.ParticipantResponse; -import dev.steady.steady.dto.response.ParticipantsResponse; -import dev.steady.steady.dto.response.SteadyQueryResponse; -import dev.steady.steady.dto.response.SteadyQuestionResponse; -import dev.steady.steady.dto.response.SteadyQuestionsResponse; -import dev.steady.user.domain.Position; -import dev.steady.user.domain.Stack; -import dev.steady.user.domain.User; -import dev.steady.user.fixture.UserFixtures; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; -import org.springframework.test.util.ReflectionTestUtils; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.List; -import java.util.stream.IntStream; - -import static dev.steady.steady.domain.SteadyMode.OFFLINE; -import static dev.steady.steady.domain.SteadyMode.ONLINE; -import static dev.steady.steady.domain.SteadyType.PROJECT; -import static dev.steady.steady.domain.SteadyType.STUDY; - -public class SteadyFixtures { - - public static SteadyCreateRequest createSteadyRequest(Long stackId, Long positionId) { - return SteadyCreateRequest.builder() - .name("테스트 스테디") - .bio("무슨 스터디") - .contact("email") - .type(STUDY) - .participantLimit(6) - .steadyMode(ONLINE) - .scheduledPeriod("ONE_WEEK") - .deadline(LocalDate.now().plusDays(7)) - .title("스테디원 모집합니다") - .content("많관부") - .positions(List.of(positionId)) - .stacks(List.of(stackId)) - .questions(List.of("1번 질문", "2번 질문", "3번 질문")) - .build(); - } - - public static SteadyCreateRequest createAnotherSteadyRequest(Long stackId, Long positionId) { - return SteadyCreateRequest.builder() - .name("테스트 스테디") - .bio("무슨 스터디") - .contact("email") - .type(PROJECT) - .participantLimit(6) - .steadyMode(OFFLINE) - .scheduledPeriod("TWO_WEEK") - .deadline(LocalDate.now().plusDays(14)) - .title("스테디원 모집합니다") - .content("많관부") - .positions(List.of(positionId)) - .stacks(List.of(stackId)) - .questions(List.of("1번 질문", "2번 질문", "3번 질문")) - .build(); - } - - public static SteadyUpdateRequest createSteadyUpdateRequest(Long stackId, Long positionId) { - return SteadyUpdateRequest.builder() - .name("업데이트 스테디") - .bio("업데이트 적용한 스터디") - .contact("email") - .type(SteadyType.PROJECT) - .status(SteadyStatus.CLOSED) - .participantLimit(5) - .steadyMode(SteadyMode.BOTH) - .scheduledPeriod("TWO_WEEK") - .deadline(LocalDate.now().plusDays(14)) - .title("스테디가 진행중입니다.") - .content("앞으로 화이팅!") - .positions(List.of(positionId)) - .stacks(List.of(stackId)) - .build(); - } - - public static Steady createSteady(User user, Stack stack) { - return Steady.builder() - .name("스테디") - .bio("boi") - .contact("email") - .type(STUDY) - .participantLimit(6) - .scheduledPeriod(ScheduledPeriod.FIVE_MONTH) - .deadline(LocalDate.of(2025, 1, 2)) - .title("title") - .content("content") - .user(user) - .steadyMode(ONLINE) - .build(); - } - - public static SteadyStack createSteadyStack(Steady steady, Stack stack) { - return new SteadyStack(stack, steady); - } - - public static SteadyPosition createSteadyPosition(Steady steady, Position position) { - return SteadyPosition.builder().steady(steady).position(position).build(); - } - - public static List createSteadyQuestion(Steady steady, List questions) { - return IntStream.range(0, questions.size()) - .mapToObj(index -> dev.steady.steady.domain.SteadyQuestion.builder() - .content(questions.get(index)) - .sequence(index + 1) - .steady(steady) - .build()) - .toList(); - } - - public static Steady createSteady() { - var user = UserFixtures.createFirstUser(UserFixtures.createPosition()); - var stack = UserFixtures.createStack(); - var steady = createSteadyRequest(1L, 1L).toEntity(user); - ReflectionTestUtils.setField(user, "id", 1L); - ReflectionTestUtils.setField(stack, "id", 1L); - ReflectionTestUtils.setField(steady, "id", 1L); - ReflectionTestUtils.setField(steady, "createdAt", LocalDateTime.of(2023, 12, 7, 11, 11)); - return steady; - } - - public static Steady createSteady(User user, List stacks, SteadyStatus status) { - Steady steady = Steady.builder() - .name("스테디 제목") - .bio("Bio") - .contact("email") - .type(STUDY) - .participantLimit(5) - .steadyMode(SteadyMode.BOTH) - .scheduledPeriod(ScheduledPeriod.FIVE_MONTH) - .deadline(LocalDate.of(2023, 12, 20)) - .title("게시글 제목") - .content("내용") - .user(user) - .build(); - ReflectionTestUtils.setField(steady, "status", status); - return steady; - } - - public static PageResponse createSteadyPageResponse(Steady steady, Pageable pageable) { - Page steadies = new PageImpl<>(List.of(steady), pageable, 1); - return PageResponse.from(steadies.map(SteadyQueryResponse::from)); - } - - public static ParticipantsResponse createParticipantsResponse() { - return new ParticipantsResponse(List.of( - new ParticipantResponse(1L, "weonest", "url1", true), - new ParticipantResponse(2L, "nayjk", "url2", false) - )); - } - - public static SteadyQuestionsResponse createSteadyQuestionsResponse() { - return new SteadyQuestionsResponse( - "스터디 제목", - List.of( - new SteadyQuestionResponse(1L, "누구세요?", 1), - new SteadyQuestionResponse(2L, "뭐세요?", 2) - )); - } - - public static SliceResponse createMySteadyResponse() { - return new SliceResponse<>( - List.of( - new MySteadyResponse(1L, "스테디 제목", "email", true, LocalDateTime.of(2023, 12, 31, 11, 10)), - new MySteadyResponse(2L, "스테디 제목2", "email", false, LocalDateTime.of(2023, 12, 31, 11, 10)) - ), - 2, - false - ); - } - -} diff --git a/src/test/java/dev/steady/steady/infrastructure/SteadySearchRepositoryImplTest.java b/src/test/java/dev/steady/steady/infrastructure/SteadySearchRepositoryImplTest.java index 0b8fb3a..7a2f1f9 100644 --- a/src/test/java/dev/steady/steady/infrastructure/SteadySearchRepositoryImplTest.java +++ b/src/test/java/dev/steady/steady/infrastructure/SteadySearchRepositoryImplTest.java @@ -2,17 +2,19 @@ import dev.steady.global.config.JpaConfig; import dev.steady.global.config.QueryDslConfig; -import dev.steady.steady.domain.repository.ParticipantRepository; import dev.steady.steady.domain.repository.SteadyPositionRepository; import dev.steady.steady.domain.repository.SteadyQuestionRepository; import dev.steady.steady.domain.repository.SteadyRepository; import dev.steady.steady.dto.FilterConditionDto; -import dev.steady.steady.dto.request.SteadySearchRequest; import dev.steady.steady.dto.response.MySteadyQueryResponse; +import dev.steady.user.domain.Position; +import dev.steady.user.domain.Stack; +import dev.steady.user.domain.User; import dev.steady.user.domain.repository.PositionRepository; import dev.steady.user.domain.repository.StackRepository; import dev.steady.user.domain.repository.UserRepository; import jakarta.persistence.EntityManager; +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; @@ -27,13 +29,15 @@ import static dev.steady.steady.domain.SteadyStatus.CLOSED; import static dev.steady.steady.domain.SteadyStatus.FINISHED; import static dev.steady.steady.domain.SteadyStatus.RECRUITING; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyPosition; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyQuestion; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyRequest; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createStack; +import static dev.steady.steady.fixture.SteadyFixturesV2.createDefaultSteadySearchRequest; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteady; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyPosition; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyQuestion; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyWithStatus; +import static dev.steady.steady.fixture.SteadyFixturesV2.createUnsatisfiedSteadySearchRequest; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -65,38 +69,29 @@ class SteadySearchRepositoryImplTest { @Autowired private SteadyQuestionRepository steadyQuestionRepository; - @Autowired - private ParticipantRepository participantRepository; + private Position position; + private Stack stack; + private User leader; + + @BeforeEach + void setUp() { + position = positionRepository.save(generatePosition()); + stack = stackRepository.save(generateStack()); + leader = userRepository.save(generateUser(position)); + } @Test @DisplayName("검색 조건에 해당하는 스테디를 조회할 수 있다.") void findAllByConditionTest() { // given - var position = positionRepository.save(createPosition()); - var user = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); - var steady = steadyRepository.save(steadyRequest.toEntity(user)); - var steadyPosition = createSteadyPosition(steady, position); - steadyPositionRepository.save(steadyPosition); - var steadyQuestion = createSteadyQuestion(steady, steadyRequest.questions()); - steadyQuestionRepository.saveAll(steadyQuestion); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + steadyPositionRepository.save(createSteadyPosition(steady, position)); + steadyQuestionRepository.saveAll(createSteadyQuestion(steady, 3)); entityManager.flush(); entityManager.clear(); // when - var request = new SteadySearchRequest( - null, - "DESC", - null, - null, - "study", - "online", - "Java", - "백엔드", - "recruiting", - "false", - "스테디"); + var request = createDefaultSteadySearchRequest(); var pageable = request.toPageable(); var condition = FilterConditionDto.from(request); @@ -115,31 +110,14 @@ void findAllByConditionTest() { @DisplayName("검색 조건에 해당하지 않으면 스테디를 조회할 수 없다.") void findAllByConditionNotInTest() { // given - var position = positionRepository.save(createPosition()); - var user = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); - var steady = steadyRepository.save(steadyRequest.toEntity(user)); - var steadyPosition = createSteadyPosition(steady, position); - steadyPositionRepository.save(steadyPosition); - var steadyQuestion = createSteadyQuestion(steady, steadyRequest.questions()); - steadyQuestionRepository.saveAll(steadyQuestion); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + steadyPositionRepository.save(createSteadyPosition(steady, position)); + steadyQuestionRepository.saveAll(createSteadyQuestion(steady, 3)); entityManager.flush(); entityManager.clear(); // when - var request = new SteadySearchRequest( - null, - null, - null, - null, - "study", - "both", - "Java", - "데브옵스", - "finished", - "false", - "말도 안 되는 검색 조건!"); + var request = createUnsatisfiedSteadySearchRequest(); var pageable = request.toPageable(); var condition = FilterConditionDto.from(request); @@ -153,31 +131,16 @@ void findAllByConditionNotInTest() { @DisplayName("기본 조건은 전체 조회 결과를 반환한다.") void findAllByBasicConditionTest() { // given - var position = positionRepository.save(createPosition()); - var user = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); - var steady = steadyRepository.save(steadyRequest.toEntity(user)); - var steadyPosition = createSteadyPosition(steady, position); - steadyPositionRepository.save(steadyPosition); - var steadyQuestion = createSteadyQuestion(steady, steadyRequest.questions()); - steadyQuestionRepository.saveAll(steadyQuestion); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + steadyPositionRepository.save(createSteadyPosition(steady, position)); + steadyQuestionRepository.saveAll(createSteadyQuestion(steady, 3)); entityManager.flush(); entityManager.clear(); + // when - var request = new SteadySearchRequest( - null, - null, - null, - null, - null, - null, - null, - null, - null, - "false", - null); + var request = createDefaultSteadySearchRequest(); + var pageable = request.toPageable(); var condition = FilterConditionDto.from(request); var response = queryDslRepository.findAllByFilterCondition(null, condition, pageable); @@ -191,16 +154,14 @@ void findAllByBasicConditionTest() { @Test void findMyAllSteadies() { //given - var position = positionRepository.save(createPosition()); - var user = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var steady = createSteady(user, List.of(stack), RECRUITING); - var secondSteady = createSteady(user, List.of(stack), CLOSED); - var thirdSteady = createSteady(user, List.of(stack), FINISHED); - var steadies = steadyRepository.saveAll(List.of(steady, secondSteady, thirdSteady)); + var firstSteady = createSteadyWithStatus(leader, List.of(stack), RECRUITING); + var secondSteady = createSteadyWithStatus(leader, List.of(stack), CLOSED); + var thirdSteady = createSteadyWithStatus(leader, List.of(stack), FINISHED); + var steadies = steadyRepository.saveAll(List.of(firstSteady, secondSteady, thirdSteady)); + //when PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "createdAt"); - Slice mySteadies = queryDslRepository.findMySteadies(null, user, pageRequest); + Slice mySteadies = queryDslRepository.findMySteadies(null, leader, pageRequest); //then assertThat(mySteadies.hasNext()).isFalse(); assertThat(mySteadies.getNumberOfElements()).isEqualTo(steadies.size()); @@ -210,16 +171,13 @@ void findMyAllSteadies() { @Test void findMyFinishedSteadies() { //given - var position = positionRepository.save(createPosition()); - var user = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var steady = createSteady(user, List.of(stack), RECRUITING); - var secondSteady = createSteady(user, List.of(stack), CLOSED); - var thirdSteady = createSteady(user, List.of(stack), FINISHED); - var steadies = steadyRepository.saveAll(List.of(steady, secondSteady, thirdSteady)); + var firstSteady = createSteadyWithStatus(leader, List.of(stack), RECRUITING); + var secondSteady = createSteadyWithStatus(leader, List.of(stack), CLOSED); + var thirdSteady = createSteadyWithStatus(leader, List.of(stack), FINISHED); + steadyRepository.saveAll(List.of(firstSteady, secondSteady, thirdSteady)); //when PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "createdAt"); - Slice mySteadies = queryDslRepository.findMySteadies(FINISHED, user, pageRequest); + Slice mySteadies = queryDslRepository.findMySteadies(FINISHED, leader, pageRequest); //then assertThat(mySteadies.hasNext()).isFalse(); assertThat(mySteadies.getNumberOfElements()).isOne(); @@ -229,16 +187,13 @@ void findMyFinishedSteadies() { @Test void findMyNotFinishedSteadies() { //given - var position = positionRepository.save(createPosition()); - var user = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var steady = createSteady(user, List.of(stack), RECRUITING); - var secondSteady = createSteady(user, List.of(stack), CLOSED); - var thirdSteady = createSteady(user, List.of(stack), FINISHED); - var steadies = steadyRepository.saveAll(List.of(steady, secondSteady, thirdSteady)); + var firstSteady = createSteadyWithStatus(leader, List.of(stack), RECRUITING); + var secondSteady = createSteadyWithStatus(leader, List.of(stack), CLOSED); + var thirdSteady = createSteadyWithStatus(leader, List.of(stack), FINISHED); + steadyRepository.saveAll(List.of(firstSteady, secondSteady, thirdSteady)); //when PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "createdAt"); - Slice mySteadies = queryDslRepository.findMySteadies(RECRUITING, user, pageRequest); + Slice mySteadies = queryDslRepository.findMySteadies(RECRUITING, leader, pageRequest); //then assertThat(mySteadies.hasNext()).isFalse(); assertThat(mySteadies.getNumberOfElements()).isEqualTo(2); diff --git a/src/test/java/dev/steady/steady/service/SteadyLikeServiceTest.java b/src/test/java/dev/steady/steady/service/SteadyLikeServiceTest.java index a3e742e..ee2bcf4 100644 --- a/src/test/java/dev/steady/steady/service/SteadyLikeServiceTest.java +++ b/src/test/java/dev/steady/steady/service/SteadyLikeServiceTest.java @@ -18,10 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createStack; +import java.util.List; + +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteady; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -43,12 +45,12 @@ class SteadyLikeServiceTest { private StackRepository stackRepository; private Position position; - private User user; + private User leader; @BeforeEach void setUp() { - this.position = positionRepository.save(createPosition()); - this.user = userRepository.save(createFirstUser(position)); + this.position = positionRepository.save(generatePosition()); + this.leader = userRepository.save(generateUser(position)); } @AfterEach @@ -64,11 +66,11 @@ void tearDown() { @Test void updateSteadyLikeTest() { //given - Stack stack = stackRepository.save(createStack()); - Steady steady = steadyRepository.save(createSteady(user, stack)); + Stack stack = stackRepository.save(generateStack()); + Steady steady = steadyRepository.save(createSteady(leader, List.of(stack))); //when - SteadyLikeResponse response = steadyLikeService.updateSteadyLike(steady.getId(), new UserInfo(user.getId())); + SteadyLikeResponse response = steadyLikeService.updateSteadyLike(steady.getId(), new UserInfo(leader.getId())); //then assertAll( @@ -81,12 +83,12 @@ void updateSteadyLikeTest() { @Test void updateSteadyLikeToggleTest() { //given - Stack stack = stackRepository.save(createStack()); - Steady steady = steadyRepository.save(createSteady(user, stack)); + Stack stack = stackRepository.save(generateStack()); + Steady steady = steadyRepository.save(createSteady(leader, List.of(stack))); //when - steadyLikeService.updateSteadyLike(steady.getId(), new UserInfo(user.getId())); - SteadyLikeResponse response = steadyLikeService.updateSteadyLike(steady.getId(), new UserInfo(user.getId())); + steadyLikeService.updateSteadyLike(steady.getId(), new UserInfo(leader.getId())); + SteadyLikeResponse response = steadyLikeService.updateSteadyLike(steady.getId(), new UserInfo(leader.getId())); //then assertAll( diff --git a/src/test/java/dev/steady/steady/service/SteadyServiceTest.java b/src/test/java/dev/steady/steady/service/SteadyServiceTest.java index ff7ce75..60ac47e 100644 --- a/src/test/java/dev/steady/steady/service/SteadyServiceTest.java +++ b/src/test/java/dev/steady/steady/service/SteadyServiceTest.java @@ -27,12 +27,15 @@ import dev.steady.steady.dto.response.SteadyDetailResponse; import dev.steady.steady.dto.response.SteadyQueryResponse; import dev.steady.steady.dto.response.SteadyQuestionsResponse; +import dev.steady.user.domain.Position; +import dev.steady.user.domain.Stack; import dev.steady.user.domain.User; import dev.steady.user.domain.repository.PositionRepository; import dev.steady.user.domain.repository.StackRepository; import dev.steady.user.domain.repository.UserRepository; import jakarta.persistence.EntityManager; import org.junit.jupiter.api.Assertions; +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; @@ -49,17 +52,16 @@ import static dev.steady.steady.domain.SteadyStatus.CLOSED; import static dev.steady.steady.domain.SteadyStatus.FINISHED; import static dev.steady.steady.domain.SteadyStatus.RECRUITING; -import static dev.steady.steady.fixture.SteadyFixtures.createAnotherSteadyRequest; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyQuestion; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyRequest; -import static dev.steady.steady.fixture.SteadyFixtures.createSteadyUpdateRequest; -import static dev.steady.user.fixture.UserFixtures.createAnotherPosition; -import static dev.steady.user.fixture.UserFixtures.createAnotherStack; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createSecondUser; -import static dev.steady.user.fixture.UserFixtures.createStack; +import static dev.steady.steady.fixture.SteadyFixturesV2.createDefaultSteadySearchRequest; +import static dev.steady.steady.fixture.SteadyFixturesV2.createOrderByDeadLineSteadySearchRequest; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteady; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyQuestion; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyWithStatus; +import static dev.steady.steady.fixture.SteadyFixturesV2.generateSteadyCreateRequest; +import static dev.steady.steady.fixture.SteadyFixturesV2.generateSteadyUpdateRequest; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -98,23 +100,31 @@ class SteadyServiceTest { @Autowired private SteadyPositionRepository steadyPositionRepository; + private Position position; + private Stack stack; + private User leader; + + @BeforeEach + void setUp() { + position = positionRepository.save(generatePosition()); + stack = stackRepository.save(generateStack()); + leader = userRepository.save(generateUser(position)); + } + @Test @DisplayName("스터디 생성 요청을 통해 스테디와 스테디 관련 정보를 생성할 수 있다.") void createSteadyTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); // when - SteadyCreateRequest steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + SteadyCreateRequest steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); Long steadyId = steadyService.create(steadyRequest, userInfo); entityManager.flush(); entityManager.clear(); // then - Steady steady = steadyRepository.findById(steadyId).get(); + Steady steady = steadyRepository.getSteady(steadyId); List participants = participantRepository.findBySteadyId(steadyId); List steadyStacks = steadyStackRepository.findBySteadyId(steadyId); List steadyQuestions = steadyQuestionRepository.findBySteadyId(steadyId); @@ -129,33 +139,20 @@ void createSteadyTest() { } @Test - @DisplayName("스테디 검색 조회 요청을 통해 페이징 처리된 응답을 반환할 수 있다.") + @DisplayName("스테디 페이징 요청을 통해 끌어올린 시간을 기준으로 내림차순 정렬된 응답을 반환할 수 있다.") void getSteadiesSearchTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); - var anotherSteadyRequest = createAnotherSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); + var anotherSteadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); steadyService.create(steadyRequest, userInfo); steadyService.create(anotherSteadyRequest, userInfo); entityManager.flush(); entityManager.clear(); // when - SteadySearchRequest searchRequest = new SteadySearchRequest(null, - null, - null, - null, - null, - null, - null, - null, - null, - "false", - null); + SteadySearchRequest searchRequest = createDefaultSteadySearchRequest(); FilterConditionDto condition = FilterConditionDto.from(searchRequest); Pageable pageable = searchRequest.toPageable(); PageResponse response = steadyService.getSteadies(userInfo, condition, pageable); @@ -173,31 +170,17 @@ void getSteadiesSearchTest() { @DisplayName("마감임박순 조건을 통해 페이징 처리된 응답을 반환할 수 있다.") void getSteadiesSearchOrderByDeadlineTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); - var anotherSteadyRequest = createAnotherSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); + var anotherSteadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); steadyService.create(steadyRequest, userInfo); steadyService.create(anotherSteadyRequest, userInfo); entityManager.flush(); entityManager.clear(); // when - SteadySearchRequest searchRequest = new SteadySearchRequest( - null, - "asc", - "deadline", - null, - null, - null, - null, - null, - null, - "false", - null); + SteadySearchRequest searchRequest = createOrderByDeadLineSteadySearchRequest(); FilterConditionDto condition = FilterConditionDto.from(searchRequest); Pageable pageable = searchRequest.toPageable(); PageResponse response = steadyService.getSteadies(userInfo, condition, pageable); @@ -215,12 +198,9 @@ void getSteadiesSearchOrderByDeadlineTest() { @DisplayName("스테디 식별자를 통해 스테디 상세 조회를 할 수 있다.") void getDetailSteadyTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); entityManager.flush(); entityManager.clear(); @@ -244,13 +224,10 @@ void getDetailSteadyTest() { @DisplayName("리더가 아닌 사용자도 스테디 식별자를 통해 스테디 상세 조회를 할 수 있다.") void getDetailSteadyNotLeaderTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var otherUser = userRepository.save(createSecondUser(position)); - var userInfo = createUserInfo(otherUser.getId()); + var anotherUser = userRepository.save(generateUser(position)); + var userInfo = createUserInfo(anotherUser.getId()); - var steady = steadyRepository.save(createSteady(leader, stack)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); var steadyId = steady.getId(); entityManager.flush(); entityManager.clear(); @@ -274,13 +251,10 @@ void getDetailSteadyNotLeaderTest() { @DisplayName("리더가 아닌 사용자가 게시물을 조회하면 조회수가 상승한다.") void getDetailSteadyViewCountIncreaseTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var otherUser = userRepository.save(createSecondUser(position)); + var otherUser = userRepository.save(generateUser(position)); var userInfo = createUserInfo(otherUser.getId()); - var steady = steadyRepository.save(createSteady(leader, stack)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); var steadyId = steady.getId(); entityManager.flush(); entityManager.clear(); @@ -296,13 +270,10 @@ void getDetailSteadyViewCountIncreaseTest() { @DisplayName("게시물을 조회한지 3시간이 지나지 않았을때 재조회하면 조회수가 상승하지 않는다.") void getDetailSteadyViewCountNotIncreaseTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var otherUser = userRepository.save(createSecondUser(position)); + var otherUser = userRepository.save(generateUser(position)); var userInfo = createUserInfo(otherUser.getId()); - var steady = steadyRepository.save(createSteady(leader, stack)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); var steadyId = steady.getId(); entityManager.flush(); entityManager.clear(); @@ -319,12 +290,9 @@ void getDetailSteadyViewCountNotIncreaseTest() { @DisplayName("로그인 하지 않은 사용자도 스테디 식별자를 통해 스테디 상세 조회를 할 수 있다.") void getDetailSteadyNotLoginUserTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = new UserInfo(null); - var steady = steadyRepository.save(createSteady(leader, stack)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); var steadyId = steady.getId(); entityManager.flush(); entityManager.clear(); @@ -348,13 +316,9 @@ void getDetailSteadyNotLoginUserTest() { @DisplayName("스테디 식별자를 통해 스테디 질문을 조회할 수 있다.") void getSteadyQuestionsTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - - Steady steady = steadyRepository.save(createSteady(leader, stack)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); List questions = List.of("질문1", "질문2"); - steadyQuestionRepository.saveAll(createSteadyQuestion(steady, questions)); + steadyQuestionRepository.saveAll(createSteadyQuestion(steady, questions.size())); entityManager.flush(); entityManager.clear(); @@ -372,14 +336,10 @@ void getSteadyQuestionsTest() { @DisplayName("스테디 식별자를 통해 참여자 전체 조회를 할 수 있다.") void getSteadyParticipantsTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - - var steady = steadyRepository.save(createSteady(leader, stack)); + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); var steadyId = steady.getId(); - var anotherUser = userRepository.save(createSecondUser(position)); + var anotherUser = userRepository.save(generateUser(position)); steady.addParticipantByLeader(leader, anotherUser); entityManager.flush(); entityManager.clear(); @@ -398,21 +358,18 @@ void getSteadyParticipantsTest() { @DisplayName("스테디 수정 요청을 통해 스테디 정보를 수정할 수 있다.") void steadyUpdateTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); - var anotherStack = stackRepository.save(createAnotherStack()); - var anotherPosition = positionRepository.save(createAnotherPosition()); + var anotherStack = stackRepository.save(generateStack()); + var anotherPosition = positionRepository.save(generatePosition()); entityManager.flush(); entityManager.clear(); // when - SteadyUpdateRequest steadyUpdateRequest = createSteadyUpdateRequest(anotherStack.getId(), anotherPosition.getId()); + SteadyUpdateRequest steadyUpdateRequest = generateSteadyUpdateRequest(anotherStack.getId(), anotherPosition.getId()); steadyService.updateSteady(steadyId, steadyUpdateRequest, userInfo); entityManager.flush(); entityManager.clear(); @@ -428,7 +385,7 @@ void steadyUpdateTest() { () -> assertThat(updatedSteady.getStatus()).isEqualTo(steadyUpdateRequest.status()), () -> assertThat(updatedSteady.getParticipantLimit()).isEqualTo(steadyUpdateRequest.participantLimit()), () -> assertThat(updatedSteady.getSteadyMode()).isEqualTo(steadyUpdateRequest.steadyMode()), - () -> assertThat(String.valueOf(updatedSteady.getScheduledPeriod())).isEqualTo(steadyUpdateRequest.scheduledPeriod()), + () -> assertThat(updatedSteady.getScheduledPeriod()).isEqualTo(steadyUpdateRequest.scheduledPeriod()), () -> assertThat(updatedSteady.getDeadline()).isEqualTo(steadyUpdateRequest.deadline()), () -> assertThat(updatedSteady.getTitle()).isEqualTo(steadyUpdateRequest.title()), () -> assertThat(updatedSteady.getContent()).isEqualTo(steadyUpdateRequest.content()), @@ -443,23 +400,20 @@ void steadyUpdateTest() { @DisplayName("리더가 아닌 유저가 수정 요청을 보내면 에러를 반환한다.") void updateSteadyByAnotherUserTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); - var anotherPosition = positionRepository.save(createAnotherPosition()); - var anotherStack = stackRepository.save(createAnotherStack()); + var anotherPosition = positionRepository.save(generatePosition()); + var anotherStack = stackRepository.save(generateStack()); entityManager.flush(); entityManager.clear(); // when & then - User anotherUser = userRepository.save(createSecondUser(anotherPosition)); + User anotherUser = userRepository.save(generateUser(anotherPosition)); UserInfo anotherUserInfo = createUserInfo(anotherUser.getId()); - SteadyUpdateRequest steadyUpdateRequest = createSteadyUpdateRequest(anotherStack.getId(), anotherPosition.getId()); + SteadyUpdateRequest steadyUpdateRequest = generateSteadyUpdateRequest(anotherStack.getId(), anotherPosition.getId()); assertThatThrownBy(() -> steadyService.updateSteady(steadyId, steadyUpdateRequest, anotherUserInfo)) .isInstanceOf(ForbiddenException.class); } @@ -468,12 +422,9 @@ void updateSteadyByAnotherUserTest() { @DisplayName("스테디 질문 수정 요청을 통해 스테디 질문을 수정할 수 있다.") void updateSteadyQuestionsTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); // when @@ -496,13 +447,10 @@ void updateSteadyQuestionsTest() { @DisplayName("스테디 리더가 참여자를 추방할 수 있다.") void expelParticipantTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var member = userRepository.save(createSecondUser(position)); - var stack = stackRepository.save(createStack()); + var member = userRepository.save(generateUser(position)); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); var steady = steadyRepository.getSteady(steadyId); steady.addParticipantByLeader(leader, member); @@ -519,12 +467,9 @@ void expelParticipantTest() { @DisplayName("스테디 리더가 끌어올리기 요청을 통해 스테디를 끌어올릴 수 있다.") void promoteSteadyTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); entityManager.flush(); entityManager.clear(); @@ -546,18 +491,15 @@ void promoteSteadyTest() { @DisplayName("리더가 아닌 유저가 끌어올리기 요청을 보내면 에러를 반환한다.") void promoteSteadyByAnotherUserTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); entityManager.flush(); entityManager.clear(); // when & then - User anotherUser = userRepository.save(createSecondUser(position)); + User anotherUser = userRepository.save(generateUser(position)); var anotherUserInfo = createUserInfo(anotherUser.getId()); assertThatThrownBy(() -> steadyService.promoteSteady(steadyId, anotherUserInfo)) .isInstanceOf(ForbiddenException.class); @@ -567,12 +509,9 @@ void promoteSteadyByAnotherUserTest() { @DisplayName("스테디 리더가 스테디를 종료 상태로 변경할 수 있다.") void finishSteadyTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); entityManager.flush(); entityManager.clear(); @@ -592,15 +531,12 @@ void finishSteadyTest() { @DisplayName("리더가 아닌 유저가 스테디 종료를 요청하면 에러를 반환한다.") void finishSteadyByAnotherUserTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); - var anotherUser = userRepository.save(createSecondUser(position)); + var anotherUser = userRepository.save(generateUser(position)); var anotherUserInfo = createUserInfo(anotherUser.getId()); entityManager.flush(); entityManager.clear(); @@ -614,12 +550,9 @@ void finishSteadyByAnotherUserTest() { @DisplayName("스테디 참여자가 리더뿐이며 리더가 삭제 요청을 보내면 스테디를 삭제할 수 있다.") void deleteSteadyTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); entityManager.flush(); entityManager.clear(); @@ -649,16 +582,13 @@ void deleteSteadyTest() { @DisplayName("리더를 제외한 참여자가 존재하는 경우 스테디를 삭제할 수 없다.") void deleteSteadyWhenParticipantIsExistTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); var steady = steadyRepository.findById(steadyId).get(); - var anotherUser = userRepository.save(createSecondUser(position)); + var anotherUser = userRepository.save(generateUser(position)); // when steady.addParticipantByLeader(leader, anotherUser); @@ -674,15 +604,12 @@ void deleteSteadyWhenParticipantIsExistTest() { @DisplayName("리더가 아닌 유저가 스테디 삭제 요청을 보내면 에러를 반환한다.") void deleteSteadyByAnotherUserTest() { // given - var position = positionRepository.save(createPosition()); - var leader = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); var userInfo = createUserInfo(leader.getId()); - var steadyRequest = createSteadyRequest(stack.getId(), position.getId()); + var steadyRequest = generateSteadyCreateRequest(stack.getId(), position.getId()); var steadyId = steadyService.create(steadyRequest, userInfo); - var anotherUser = userRepository.save(createSecondUser(position)); + var anotherUser = userRepository.save(generateUser(position)); var anotherUserInfo = createUserInfo(anotherUser.getId()); entityManager.flush(); entityManager.clear(); @@ -696,16 +623,13 @@ void deleteSteadyByAnotherUserTest() { @Test void findMySteadiesTest() { //given - var position = positionRepository.save(createPosition()); - var user = userRepository.save(createFirstUser(position)); - var stack = stackRepository.save(createStack()); - var steady = createSteady(user, List.of(stack), RECRUITING); - var secondSteady = createSteady(user, List.of(stack), CLOSED); - var thirdSteady = createSteady(user, List.of(stack), FINISHED); - var steadies = steadyRepository.saveAll(List.of(steady, secondSteady, thirdSteady)); + var steady = createSteadyWithStatus(leader, List.of(stack), RECRUITING); + var secondSteady = createSteadyWithStatus(leader, List.of(stack), CLOSED); + var thirdSteady = createSteadyWithStatus(leader, List.of(stack), FINISHED); + steadyRepository.saveAll(List.of(steady, secondSteady, thirdSteady)); //when PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "createdAt"); - UserInfo userInfo = new UserInfo(user.getId()); + UserInfo userInfo = new UserInfo(leader.getId()); SliceResponse response = steadyService.findMySteadies(RECRUITING, userInfo, pageRequest); //then Assertions.assertAll( diff --git a/src/test/java/dev/steady/template/domain/TemplateTest.java b/src/test/java/dev/steady/template/domain/TemplateTest.java index 21b1f66..6804337 100644 --- a/src/test/java/dev/steady/template/domain/TemplateTest.java +++ b/src/test/java/dev/steady/template/domain/TemplateTest.java @@ -2,13 +2,13 @@ import dev.steady.global.exception.ForbiddenException; import dev.steady.user.domain.User; -import dev.steady.user.fixture.UserFixtures; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.test.util.ReflectionTestUtils; import static dev.steady.template.fixture.TemplateFixture.createTemplate; -import static dev.steady.user.fixture.UserFixtures.createSecondUser; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThatThrownBy; class TemplateTest { @@ -16,12 +16,12 @@ class TemplateTest { @DisplayName("템플릿의 생성자가 아니면 예외가 발생한다.") @Test void validateOwnerTest() { - var position = UserFixtures.createPosition(); - User user = UserFixtures.createFirstUser(position); + var position = generatePosition(); + User user = generateUser(position); ReflectionTestUtils.setField(user, "id", 1L); Template template = createTemplate(user); - assertThatThrownBy(() -> template.validateOwner(createSecondUser(position))) + assertThatThrownBy(() -> template.validateOwner(generateUser(position))) .isInstanceOf(ForbiddenException.class); } diff --git a/src/test/java/dev/steady/template/domain/repository/TemplateRepositoryTest.java b/src/test/java/dev/steady/template/domain/repository/TemplateRepositoryTest.java index 9b65179..085ec30 100644 --- a/src/test/java/dev/steady/template/domain/repository/TemplateRepositoryTest.java +++ b/src/test/java/dev/steady/template/domain/repository/TemplateRepositoryTest.java @@ -5,7 +5,6 @@ import dev.steady.template.domain.Template; import dev.steady.user.domain.repository.PositionRepository; import dev.steady.user.domain.repository.UserRepository; -import dev.steady.user.fixture.UserFixtures; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +14,8 @@ import java.util.List; import static dev.steady.template.fixture.TemplateFixture.createTemplate; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest @@ -33,11 +34,11 @@ class TemplateRepositoryTest { @DisplayName("템플릿을 생성한 유저의 ID로 조회할 수 있다.") @Test void findTemplateUserIdTest() { - var position = positionRepository.save(UserFixtures.createPosition()); - var user1 = UserFixtures.createFirstUser(position); + var position = positionRepository.save(generatePosition()); + var user1 = generateUser(position); var savedUser1 = userRepository.save(user1); - var user2 = UserFixtures.createSecondUser(position); + var user2 = generateUser(position); var savedUser2 = userRepository.save(user2); var template1 = createTemplate(savedUser1); diff --git a/src/test/java/dev/steady/template/service/TemplateServiceTest.java b/src/test/java/dev/steady/template/service/TemplateServiceTest.java index ea9176c..198def7 100644 --- a/src/test/java/dev/steady/template/service/TemplateServiceTest.java +++ b/src/test/java/dev/steady/template/service/TemplateServiceTest.java @@ -25,9 +25,8 @@ import static dev.steady.global.auth.AuthFixture.createUserInfo; import static dev.steady.template.fixture.TemplateFixture.createAnotherTemplate; import static dev.steady.template.fixture.TemplateFixture.createTemplate; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createSecondUser; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -58,8 +57,8 @@ class TemplateServiceTest { @BeforeEach void setUp() { - this.position = positionRepository.save(createPosition()); - this.user = userRepository.save(createFirstUser(position)); + this.position = positionRepository.save(generatePosition()); + this.user = userRepository.save(generateUser(position)); } @AfterEach @@ -122,7 +121,7 @@ void getDetailTemplateTest() { @DisplayName("템플릿 식별자를 통해 템플릿을 상세조회할 때 작성자가 아니라면 예외가 발생한다.") @Test void getDetailTemplateFailTest() { - var anotherUser = userRepository.save(createSecondUser(position)); + var anotherUser = userRepository.save(generateUser(position)); var template = createTemplate(user); var savedTemplate = templateRepository.save(template); var userInfo = createUserInfo(anotherUser.getId()); @@ -171,7 +170,7 @@ void deleteTemplateTest() { @Test void deleteTemplateFailTest() { //given - var otherUser = createSecondUser(position); + var otherUser = generateUser(position); var savedUser2 = userRepository.save(otherUser); var template = createTemplate(user); var savedTemplate = templateRepository.save(template); diff --git a/src/test/java/dev/steady/user/controller/PositionControllerTest.java b/src/test/java/dev/steady/user/controller/PositionControllerTest.java index 45a768d..2c48c1e 100644 --- a/src/test/java/dev/steady/user/controller/PositionControllerTest.java +++ b/src/test/java/dev/steady/user/controller/PositionControllerTest.java @@ -7,7 +7,7 @@ import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.resourceDetails; -import static dev.steady.user.fixture.UserFixtures.createPositionResponses; +import static dev.steady.user.fixture.UserFixturesV2.createPositionResponses; import static org.mockito.BDDMockito.given; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; diff --git a/src/test/java/dev/steady/user/controller/StackControllerTest.java b/src/test/java/dev/steady/user/controller/StackControllerTest.java index ea13d01..2a0ecec 100644 --- a/src/test/java/dev/steady/user/controller/StackControllerTest.java +++ b/src/test/java/dev/steady/user/controller/StackControllerTest.java @@ -7,7 +7,7 @@ import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.resourceDetails; -import static dev.steady.user.fixture.UserFixtures.createStackResponses; +import static dev.steady.user.fixture.UserFixturesV2.createStackResponses; import static org.mockito.BDDMockito.given; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; diff --git a/src/test/java/dev/steady/user/controller/UserControllerTest.java b/src/test/java/dev/steady/user/controller/UserControllerTest.java index 6c68a04..81b2928 100644 --- a/src/test/java/dev/steady/user/controller/UserControllerTest.java +++ b/src/test/java/dev/steady/user/controller/UserControllerTest.java @@ -16,11 +16,11 @@ import static dev.steady.auth.domain.Platform.KAKAO; import static dev.steady.auth.fixture.OAuthFixture.createAuthCodeRequestUrl; import static dev.steady.global.auth.AuthFixture.createUserInfo; -import static dev.steady.user.fixture.UserFixtures.createProfileUploadUrlResponse; -import static dev.steady.user.fixture.UserFixtures.createUserCreateRequest; -import static dev.steady.user.fixture.UserFixtures.createUserMyDetailResponse; -import static dev.steady.user.fixture.UserFixtures.createUserOtherDetailResponse; -import static dev.steady.user.fixture.UserFixtures.createUserUpdateRequest; +import static dev.steady.user.fixture.UserFixturesV2.createProfileUploadUrlResponse; +import static dev.steady.user.fixture.UserFixturesV2.createUserCreateRequest; +import static dev.steady.user.fixture.UserFixturesV2.createUserMyDetailResponse; +import static dev.steady.user.fixture.UserFixturesV2.createUserOtherDetailResponse; +import static dev.steady.user.fixture.UserFixturesV2.createUserUpdateRequest; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willDoNothing; import static org.mockito.Mockito.when; diff --git a/src/test/java/dev/steady/user/fixture/UserFixtures.java b/src/test/java/dev/steady/user/fixture/UserFixtures.java deleted file mode 100644 index 29ee043..0000000 --- a/src/test/java/dev/steady/user/fixture/UserFixtures.java +++ /dev/null @@ -1,184 +0,0 @@ -package dev.steady.user.fixture; - -import dev.steady.auth.domain.Platform; -import dev.steady.review.dto.response.UserCardResponse; -import dev.steady.user.domain.Position; -import dev.steady.user.domain.Stack; -import dev.steady.user.domain.User; -import dev.steady.user.dto.request.UserCreateRequest; -import dev.steady.user.dto.request.UserUpdateRequest; -import dev.steady.user.dto.response.PositionResponse; -import dev.steady.user.dto.response.PositionsResponse; -import dev.steady.user.dto.response.PutObjectUrlResponse; -import dev.steady.user.dto.response.StackResponse; -import dev.steady.user.dto.response.StacksResponse; -import dev.steady.user.dto.response.UserDetailResponse; -import dev.steady.user.dto.response.UserMyDetailResponse; -import dev.steady.user.dto.response.UserOtherDetailResponse; -import org.springframework.web.util.UriComponentsBuilder; - -import java.util.List; - -import static dev.steady.review.fixture.ReviewFixture.createUserCardResponses; - -public class UserFixtures { - - public static Position createPosition() { - return Position.builder() - .name("백엔드") - .build(); - } - - public static Position createAnotherPosition() { - return Position.builder() - .name("프론트엔드") - .build(); - } - - public static List createPositions() { - return List.of(createPosition(), createAnotherPosition()); - } - - public static Stack createStack() { - return Stack.builder() - .name("Java") - .imageUrl("www") - .build(); - } - - public static Stack createAnotherStack() { - return Stack.builder() - .name("JavaScript") - .imageUrl("www") - .build(); - } - - public static List createStacks() { - return List.of(createStack(), createAnotherStack()); - } - - public static User createFirstUser(Position position) { - return User.builder() - .profileImage("123") - .nickname("weonest") - .bio("나에요") - .position(position) - .build(); - } - - public static User createSecondUser(Position position) { - User user = User.builder() - .profileImage("1234") - .nickname("Jun") - .bio("저에요") - .position(position) - .build(); - return user; - } - - public static User createThirdUser(Position position) { - User user = User.builder() - .profileImage("1234") - .nickname("Young") - .bio("저에요") - .position(position) - .build(); - return user; - } - - public static UserCreateRequest createUserCreateRequest() { - return new UserCreateRequest( - 1L, - "닉네임", - 1L, - List.of(1L, 2L) - ); - } - - public static StacksResponse createStackResponses() { - return new StacksResponse(List.of( - new StackResponse(1L, "Java", "www.java.com"), - new StackResponse(2L, "JavaScript", "www.javascript.com") - )); - } - - public static PositionsResponse createPositionResponses() { - return new PositionsResponse(List.of( - new PositionResponse(1L, "백엔드"), - new PositionResponse(2L, "프론트엔드") - )); - } - - public static UserUpdateRequest createUserUpdateRequest(Long positionId, List stacksId) { - return new UserUpdateRequest( - "new_image.jpg", - "newNickname", - "newBio", - positionId, - stacksId - ); - } - - public static UserMyDetailResponse createUserMyDetailResponse(Platform platform) { - return UserMyDetailResponse.builder() - .platform(platform) - .userId(1L) - .nickname("꼬부기") - .profileImage("profile.png") - .bio("안녕하세요") - .position(new PositionResponse(1L, "백엔드")) - .stacks(List.of( - new StackResponse(1L, "Java", "java.jpg"), - new StackResponse(2L, "JavaScript", "javascript.jpeg"))) - .build(); - } - - public static UserOtherDetailResponse createUserOtherDetailResponse() { - UserDetailResponse userDetailResponse = UserDetailResponse.builder() - .userId(2L) - .nickname("쿠키") - .profileImage("default_profile_image.png") - .bio("개발해요") - .position(new PositionResponse(1L, "프론트엔드")) - .stacks(List.of( - new StackResponse(1L, "React", "react.jpg"), - new StackResponse(2L, "JavaScript", "javascript.jpeg"))) - .build(); - - List userCardResponses = createUserCardResponses(); - List reviewComments = List.of( - "항상 성실하게 참여하는 모습 보기 좋습니다." - ); - - return UserOtherDetailResponse.of( - userDetailResponse, - userCardResponses, - reviewComments - ); - } - - public static UserUpdateRequest createUserUpdateRequest() { - return new UserUpdateRequest( - "new_image.jpeg", - "새로운 꼬부기", - "프로필 수정했어요.", - 1L, - List.of(1L, 2L) - ); - } - - public static PutObjectUrlResponse createProfileUploadUrlResponse() { - String presignedUrl = UriComponentsBuilder - .fromUriString("bucket-name.s3.region.amazonaws.com/path/{fileName}") - .queryParam("X-Amz-Algorithm", "{Algorithm}") - .queryParam("X-Amz-Date", "{Date}") - .queryParam("X-Amz-SignedHeaders", "{SignedHeaders}") - .queryParam("X-Amz-Credential", "{Credential}") - .queryParam("X-Amz-Expires", "{Expires}") - .queryParam("X-Amz-Signature", "{Signature}") - .build().toString(); - String objectUrl = "https:{bucket_name}.s3.{region}.com/{key}"; - return PutObjectUrlResponse.of(presignedUrl, objectUrl); - } - -} diff --git a/src/test/java/dev/steady/user/service/PositionServiceTest.java b/src/test/java/dev/steady/user/service/PositionServiceTest.java index 2d00e5c..c0744b9 100644 --- a/src/test/java/dev/steady/user/service/PositionServiceTest.java +++ b/src/test/java/dev/steady/user/service/PositionServiceTest.java @@ -10,7 +10,7 @@ import java.util.List; -import static dev.steady.user.fixture.UserFixtures.createPositions; +import static dev.steady.user.fixture.UserFixturesV2.createPositions; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest diff --git a/src/test/java/dev/steady/user/service/StackServiceTest.java b/src/test/java/dev/steady/user/service/StackServiceTest.java index 68adabd..514a6e6 100644 --- a/src/test/java/dev/steady/user/service/StackServiceTest.java +++ b/src/test/java/dev/steady/user/service/StackServiceTest.java @@ -10,7 +10,7 @@ import java.util.List; -import static dev.steady.user.fixture.UserFixtures.createStacks; +import static dev.steady.user.fixture.UserFixturesV2.generateStacks; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @@ -26,7 +26,7 @@ class StackServiceTest { @DisplayName("모든 스택을 가져올 수 있다.") void getStacksTest() { // given - List stacks = createStacks(); + List stacks = generateStacks(); stackRepository.saveAll(stacks); // when diff --git a/src/test/java/dev/steady/user/service/UserServiceTest.java b/src/test/java/dev/steady/user/service/UserServiceTest.java index 3c4d3b8..97f5ab3 100644 --- a/src/test/java/dev/steady/user/service/UserServiceTest.java +++ b/src/test/java/dev/steady/user/service/UserServiceTest.java @@ -38,13 +38,13 @@ import static dev.steady.review.fixture.ReviewFixture.createUserCard; import static dev.steady.steady.domain.Participant.createLeader; import static dev.steady.steady.domain.Participant.createMember; +import static dev.steady.steady.domain.SteadyStatus.FINISHED; import static dev.steady.steady.domain.SteadyStatus.RECRUITING; -import static dev.steady.steady.fixture.SteadyFixtures.createSteady; -import static dev.steady.user.fixture.UserFixtures.createFirstUser; -import static dev.steady.user.fixture.UserFixtures.createPosition; -import static dev.steady.user.fixture.UserFixtures.createSecondUser; -import static dev.steady.user.fixture.UserFixtures.createStack; -import static dev.steady.user.fixture.UserFixtures.createUserUpdateRequest; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyWithStatus; +import static dev.steady.user.fixture.UserFixturesV2.createUserUpdateRequest; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -92,10 +92,10 @@ class UserServiceTest { @BeforeEach void setUp() { - this.position = positionRepository.save(createPosition()); + this.position = positionRepository.save(generatePosition()); this.stacks = stackRepository.saveAll( IntStream.range(0, 3) - .mapToObj(i -> createStack()) + .mapToObj(i -> generateStack()) .toList() ); } @@ -141,7 +141,7 @@ void createUser() { @DisplayName("내 프로필을 조회할 수 있다.") void getMyUserDetail() { // given - var savedUser = userRepository.save(createFirstUser(position)); + var savedUser = userRepository.save(generateUser(position)); var userInfo = createUserInfo(savedUser.getId()); var account = createAccount(savedUser); var savedAccount = accountRepository.save(account); @@ -165,9 +165,9 @@ void getMyUserDetail() { @DisplayName("인증된 사용자의 정보를 수정할 수 있다.") void updateUser() { // given - var savedUser = userRepository.save(createFirstUser(position)); + var savedUser = userRepository.save(generateUser(position)); var userInfo = createUserInfo(savedUser.getId()); - var newPosition = positionRepository.save(createPosition()); + var newPosition = positionRepository.save(generatePosition()); var stacksId = stacks.stream().map(Stack::getId).toList(); var request = createUserUpdateRequest(newPosition.getId(), stacksId); @@ -191,9 +191,9 @@ void updateUser() { @DisplayName("다른 사용자의 정보와 카드, 리뷰 코멘트를 조회할 수 있다. ") void getOtherUserDetail() { // given - var reviewerUser = userRepository.save(createFirstUser(position)); - var revieweeUser = userRepository.save(createSecondUser(position)); - var savedSteady = steadyRepository.save(createSteady(reviewerUser, stacks, RECRUITING)); + var reviewerUser = userRepository.save(generateUser(position)); + var revieweeUser = userRepository.save(generateUser(position)); + var savedSteady = steadyRepository.save(createSteadyWithStatus(reviewerUser, stacks, FINISHED)); var reviewer = participantRepository.save(createLeader(reviewerUser, savedSteady)); var reviewee = participantRepository.save(createMember(revieweeUser, savedSteady)); @@ -234,8 +234,8 @@ void withdrawUserTesT() { var userInfo = createUserInfo(user.getId()); - var leader = userRepository.save(createFirstUser(position)); - var steady = steadyRepository.save(createSteady(leader, stacks, RECRUITING)); + var leader = userRepository.save(generateUser(position)); + var steady = steadyRepository.save(createSteadyWithStatus(leader, stacks, RECRUITING)); var reviewer = participantRepository.save(createLeader(leader, steady)); var reviewee = participantRepository.save(createMember(user, steady)); From d4b315778b4a04b530ff478f3fbb9ec6ad497dba Mon Sep 17 00:00:00 2001 From: weonest Date: Wed, 27 Dec 2023 21:09:29 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:bug:=20=EA=B9=83=20=ED=98=95=EC=83=81=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EC=8B=A4=ED=8C=A8=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/DuplicateException.java | 9 + .../steady/fixture/SteadyFixturesV2.java | 199 +++++++++++++++++ .../SteadyQueryRepositoryImplTest.java | 202 ++++++++++++++++++ .../steady/user/fixture/UserFixturesV2.java | 177 +++++++++++++++ 4 files changed, 587 insertions(+) create mode 100644 src/main/java/dev/steady/global/exception/DuplicateException.java create mode 100644 src/test/java/dev/steady/steady/fixture/SteadyFixturesV2.java create mode 100644 src/test/java/dev/steady/steady/infrastructure/SteadyQueryRepositoryImplTest.java create mode 100644 src/test/java/dev/steady/user/fixture/UserFixturesV2.java diff --git a/src/main/java/dev/steady/global/exception/DuplicateException.java b/src/main/java/dev/steady/global/exception/DuplicateException.java new file mode 100644 index 0000000..629c294 --- /dev/null +++ b/src/main/java/dev/steady/global/exception/DuplicateException.java @@ -0,0 +1,9 @@ +package dev.steady.global.exception; + +public class DuplicateException extends BusinessException { + + public DuplicateException(ErrorCode errorCode) { + super(errorCode); + } + +} diff --git a/src/test/java/dev/steady/steady/fixture/SteadyFixturesV2.java b/src/test/java/dev/steady/steady/fixture/SteadyFixturesV2.java new file mode 100644 index 0000000..28b3e50 --- /dev/null +++ b/src/test/java/dev/steady/steady/fixture/SteadyFixturesV2.java @@ -0,0 +1,199 @@ +package dev.steady.steady.fixture; + +import dev.steady.application.dto.response.SliceResponse; +import dev.steady.steady.domain.Steady; +import dev.steady.steady.domain.SteadyPosition; +import dev.steady.steady.domain.SteadyQuestion; +import dev.steady.steady.domain.SteadyStatus; +import dev.steady.steady.dto.request.SteadyCreateRequest; +import dev.steady.steady.dto.request.SteadySearchRequest; +import dev.steady.steady.dto.request.SteadyUpdateRequest; +import dev.steady.steady.dto.response.MySteadyResponse; +import dev.steady.steady.dto.response.PageResponse; +import dev.steady.steady.dto.response.ParticipantResponse; +import dev.steady.steady.dto.response.ParticipantsResponse; +import dev.steady.steady.dto.response.SteadyQueryResponse; +import dev.steady.steady.dto.response.SteadyQuestionResponse; +import dev.steady.steady.dto.response.SteadyQuestionsResponse; +import dev.steady.user.domain.Position; +import dev.steady.user.domain.Stack; +import dev.steady.user.domain.User; +import dev.steady.user.fixture.UserFixturesV2; +import org.instancio.Instancio; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.test.util.ReflectionTestUtils; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +import static dev.steady.steady.domain.ScheduledPeriod.FIVE_MONTH; +import static dev.steady.steady.domain.SteadyMode.ONLINE; +import static dev.steady.steady.domain.SteadyType.STUDY; +import static dev.steady.user.fixture.UserFixturesV2.generateStackEntity; +import static org.instancio.Select.field; + +public class SteadyFixturesV2 { + + public static SteadyCreateRequest generateSteadyCreateRequest(Long stackId, Long positionId) { + return Instancio.of(SteadyCreateRequest.class) + .generate(field(SteadyCreateRequest::name), gen -> gen.string().prefix("스테디 이름")) + .generate(field(SteadyCreateRequest::bio), gen -> gen.string().prefix("스테디 소개")) + .generate(field(SteadyCreateRequest::title), gen -> gen.string().prefix("스테디 제목")) + .generate(field(SteadyCreateRequest::content), gen -> gen.string().prefix("모집글 내용")) + .generate(field(SteadyCreateRequest::participantLimit), gen -> gen.ints().range(2, 10)) + .generate(field(SteadyCreateRequest::deadline), gen -> gen.temporal().localDate().future()) + .set(field(SteadyCreateRequest::stacks), List.of(stackId)) + .set(field(SteadyCreateRequest::positions), List.of(positionId)) + .create(); + } + + public static SteadyUpdateRequest generateSteadyUpdateRequest(Long stackId, Long positionId) { + return Instancio.of(SteadyUpdateRequest.class) + .generate(field(SteadyUpdateRequest::name), gen -> gen.string().prefix("스테디 이름")) + .generate(field(SteadyUpdateRequest::bio), gen -> gen.string().prefix("스테디 소개")) + .generate(field(SteadyUpdateRequest::title), gen -> gen.string().prefix("스테디 제목")) + .generate(field(SteadyUpdateRequest::content), gen -> gen.string().prefix("모집글 내용")) + .generate(field(SteadyUpdateRequest::participantLimit), gen -> gen.ints().range(2, 10)) + .set(field(SteadyUpdateRequest::deadline), LocalDate.now().plusDays(7)) + .set(field(SteadyUpdateRequest::stacks), List.of(stackId)) + .set(field(SteadyUpdateRequest::positions), List.of(positionId)) + .create(); + } + + public static Steady createSteady(User leader, List stacks) { + return Steady.builder() + .name("테스트 스테디") + .bio("우리 스터디는 정말 열심히 합니다.") + .contact("geonhee33@gmail.com") + .type(STUDY) + .participantLimit(5) + .steadyMode(ONLINE) + .scheduledPeriod(FIVE_MONTH) + .deadline(LocalDate.of(2030, 1, 2)) + .title("스테디 제목") + .content("스테디 본문") + .leader(leader) + .stacks(stacks) + .build(); + } + + public static Steady createSteadyWithStatus(User leader, List stacks, SteadyStatus status) { + Steady steady = Steady.builder() + .name("테스트 스테디") + .bio("우리 스터디는 정말 열심히 합니다.") + .contact("geonhee33@gmail.com") + .type(STUDY) + .participantLimit(5) + .steadyMode(ONLINE) + .scheduledPeriod(FIVE_MONTH) + .deadline(LocalDate.of(2030, 1, 2)) + .title("스테디 제목") + .content("스테디 본문") + .leader(leader) + .stacks(stacks) + .build(); + ReflectionTestUtils.setField(steady, "status", status); + return steady; + } + + public static Steady createSteadyEntity() { + var leader = UserFixturesV2.generateUserEntity(); + var steady = createSteady(leader, List.of(generateStackEntity())); + ReflectionTestUtils.setField(steady, "id", 1L); + ReflectionTestUtils.setField(steady, "createdAt", LocalDateTime.of(2025, 12, 7, 11, 12)); + return steady; + } + + public static SteadyPosition createSteadyPosition(Steady steady, Position position) { + return SteadyPosition.builder().steady(steady).position(position).build(); + } + + public static List createSteadyQuestion(Steady steady, int size) { + return Instancio.ofList(SteadyQuestion.class) + .size(size) + .set(field(SteadyQuestion::getSteady), steady) + .generate(field(SteadyQuestion::getSteady), gen -> gen.intSeq().start(1)) + .create(); + } + + public static SteadySearchRequest createDefaultSteadySearchRequest() { + return new SteadySearchRequest( + null, + null, + null, + null, + null, + null, + null, + null, + null, + "false", + null); + } + + public static SteadySearchRequest createUnsatisfiedSteadySearchRequest() { + return new SteadySearchRequest( + null, + null, + null, + null, + null, + null, + null, + null, + null, + "false", + "말도 안 되는 검색조건입니다. 아무것도 이 조건에 걸리지 않습니다."); + } + + public static SteadySearchRequest createOrderByDeadLineSteadySearchRequest() { + return new SteadySearchRequest( + null, + "asc", + "deadline", + null, + null, + null, + null, + null, + null, + "false", + null); + } + + public static PageResponse createSteadyPageResponse(Steady steady, Pageable pageable) { + Page steadies = new PageImpl<>(List.of(steady), pageable, 1); + return PageResponse.from(steadies.map(SteadyQueryResponse::from)); + } + + public static SteadyQuestionsResponse createSteadyQuestionsResponse() { + return new SteadyQuestionsResponse( + "스터디 제목", + List.of( + new SteadyQuestionResponse(1L, "누구세요?", 1), + new SteadyQuestionResponse(2L, "뭐세요?", 2) + )); + } + + public static ParticipantsResponse createParticipantsResponse() { + return new ParticipantsResponse(List.of( + new ParticipantResponse(1L, "weonest", "url1", true), + new ParticipantResponse(2L, "nayjk", "url2", false) + )); + } + + public static SliceResponse createMySteadyResponse() { + return new SliceResponse<>( + List.of( + new MySteadyResponse(1L, "스테디 제목", "email", true, LocalDateTime.of(2023, 12, 31, 11, 10)), + new MySteadyResponse(2L, "스테디 제목2", "email", false, LocalDateTime.of(2023, 12, 31, 11, 10)) + ), + 2, + false + ); + } + +} diff --git a/src/test/java/dev/steady/steady/infrastructure/SteadyQueryRepositoryImplTest.java b/src/test/java/dev/steady/steady/infrastructure/SteadyQueryRepositoryImplTest.java new file mode 100644 index 0000000..8c6a46d --- /dev/null +++ b/src/test/java/dev/steady/steady/infrastructure/SteadyQueryRepositoryImplTest.java @@ -0,0 +1,202 @@ +package dev.steady.steady.infrastructure; + +import dev.steady.global.config.JpaConfig; +import dev.steady.global.config.QueryDslConfig; +import dev.steady.steady.domain.repository.SteadyPositionRepository; +import dev.steady.steady.domain.repository.SteadyQuestionRepository; +import dev.steady.steady.domain.repository.SteadyRepository; +import dev.steady.steady.dto.FilterConditionDto; +import dev.steady.steady.dto.response.MySteadyQueryResponse; +import dev.steady.user.domain.Position; +import dev.steady.user.domain.Stack; +import dev.steady.user.domain.User; +import dev.steady.user.domain.repository.PositionRepository; +import dev.steady.user.domain.repository.StackRepository; +import dev.steady.user.domain.repository.UserRepository; +import jakarta.persistence.EntityManager; +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.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.Sort; + +import java.util.List; + +import static dev.steady.steady.domain.SteadyStatus.CLOSED; +import static dev.steady.steady.domain.SteadyStatus.FINISHED; +import static dev.steady.steady.domain.SteadyStatus.RECRUITING; +import static dev.steady.steady.fixture.SteadyFixturesV2.createDefaultSteadySearchRequest; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteady; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyPosition; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyQuestion; +import static dev.steady.steady.fixture.SteadyFixturesV2.createSteadyWithStatus; +import static dev.steady.steady.fixture.SteadyFixturesV2.createUnsatisfiedSteadySearchRequest; +import static dev.steady.user.fixture.UserFixturesV2.generatePosition; +import static dev.steady.user.fixture.UserFixturesV2.generateStack; +import static dev.steady.user.fixture.UserFixturesV2.generateUser; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +@DataJpaTest +@Import({JpaConfig.class, QueryDslConfig.class}) +class SteadyQueryRepositoryImplTest { + + @Autowired + private EntityManager entityManager; + + @Autowired + private SteadySearchRepositoryImpl queryDslRepository; + + @Autowired + private UserRepository userRepository; + + @Autowired + private StackRepository stackRepository; + + @Autowired + private SteadyRepository steadyRepository; + + @Autowired + private PositionRepository positionRepository; + + @Autowired + private SteadyPositionRepository steadyPositionRepository; + + @Autowired + private SteadyQuestionRepository steadyQuestionRepository; + + private Position position; + private Stack stack; + private User leader; + + @BeforeEach + void setUp() { + position = positionRepository.save(generatePosition()); + stack = stackRepository.save(generateStack()); + leader = userRepository.save(generateUser(position)); + } + + @Test + @DisplayName("검색 조건에 해당하는 스테디를 조회할 수 있다.") + void findAllByConditionTest() { + // given + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + steadyPositionRepository.save(createSteadyPosition(steady, position)); + steadyQuestionRepository.saveAll(createSteadyQuestion(steady, 3)); + entityManager.flush(); + entityManager.clear(); + + // when + var request = createDefaultSteadySearchRequest(); + + var pageable = request.toPageable(); + var condition = FilterConditionDto.from(request); + var response = queryDslRepository.findAllByFilterCondition(null, condition, pageable); + var returnedSteady = response.getContent().get(0); + + // then + int expectedSize = 1; + assertAll( + () -> assertThat(response.getTotalElements()).isEqualTo(expectedSize), + () -> assertThat(returnedSteady.getId()).isEqualTo(steady.getId()) + ); + } + + @Test + @DisplayName("검색 조건에 해당하지 않으면 스테디를 조회할 수 없다.") + void findAllByConditionNotInTest() { + // given + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + steadyPositionRepository.save(createSteadyPosition(steady, position)); + steadyQuestionRepository.saveAll(createSteadyQuestion(steady, 3)); + entityManager.flush(); + entityManager.clear(); + + // when + var request = createUnsatisfiedSteadySearchRequest(); + + var pageable = request.toPageable(); + var condition = FilterConditionDto.from(request); + var response = queryDslRepository.findAllByFilterCondition(null, condition, pageable); + + // then + assertThat(response.getTotalElements()).isZero(); + } + + @Test + @DisplayName("기본 조건은 전체 조회 결과를 반환한다.") + void findAllByBasicConditionTest() { + // given + var steady = steadyRepository.save(createSteady(leader, List.of(stack))); + steadyPositionRepository.save(createSteadyPosition(steady, position)); + steadyQuestionRepository.saveAll(createSteadyQuestion(steady, 3)); + entityManager.flush(); + entityManager.clear(); + + + // when + var request = createDefaultSteadySearchRequest(); + + var pageable = request.toPageable(); + var condition = FilterConditionDto.from(request); + var response = queryDslRepository.findAllByFilterCondition(null, condition, pageable); + + // then + int expectedSize = 1; + assertThat(response.getTotalElements()).isEqualTo(expectedSize); + } + + @DisplayName("내가 참여한 전체 스테디를 조회한다.") + @Test + void findMyAllSteadies() { + //given + var firstSteady = createSteadyWithStatus(leader, List.of(stack), RECRUITING); + var secondSteady = createSteadyWithStatus(leader, List.of(stack), CLOSED); + var thirdSteady = createSteadyWithStatus(leader, List.of(stack), FINISHED); + var steadies = steadyRepository.saveAll(List.of(firstSteady, secondSteady, thirdSteady)); + + //when + PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "createdAt"); + Slice mySteadies = queryDslRepository.findMySteadies(null, leader, pageRequest); + //then + assertThat(mySteadies.hasNext()).isFalse(); + assertThat(mySteadies.getNumberOfElements()).isEqualTo(steadies.size()); + } + + @DisplayName("내가 참여했지만 종료된 스테디를 조회한다.") + @Test + void findMyFinishedSteadies() { + //given + var firstSteady = createSteadyWithStatus(leader, List.of(stack), RECRUITING); + var secondSteady = createSteadyWithStatus(leader, List.of(stack), CLOSED); + var thirdSteady = createSteadyWithStatus(leader, List.of(stack), FINISHED); + steadyRepository.saveAll(List.of(firstSteady, secondSteady, thirdSteady)); + //when + PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "createdAt"); + Slice mySteadies = queryDslRepository.findMySteadies(FINISHED, leader, pageRequest); + //then + assertThat(mySteadies.hasNext()).isFalse(); + assertThat(mySteadies.getNumberOfElements()).isOne(); + } + + @DisplayName("내가 참여해 진행중 스테디를 조회한다.") + @Test + void findMyNotFinishedSteadies() { + //given + var firstSteady = createSteadyWithStatus(leader, List.of(stack), RECRUITING); + var secondSteady = createSteadyWithStatus(leader, List.of(stack), CLOSED); + var thirdSteady = createSteadyWithStatus(leader, List.of(stack), FINISHED); + steadyRepository.saveAll(List.of(firstSteady, secondSteady, thirdSteady)); + //when + PageRequest pageRequest = PageRequest.of(0, 10, Sort.Direction.DESC, "createdAt"); + Slice mySteadies = queryDslRepository.findMySteadies(RECRUITING, leader, pageRequest); + //then + assertThat(mySteadies.hasNext()).isFalse(); + assertThat(mySteadies.getNumberOfElements()).isEqualTo(2); + } + +} diff --git a/src/test/java/dev/steady/user/fixture/UserFixturesV2.java b/src/test/java/dev/steady/user/fixture/UserFixturesV2.java new file mode 100644 index 0000000..201dae5 --- /dev/null +++ b/src/test/java/dev/steady/user/fixture/UserFixturesV2.java @@ -0,0 +1,177 @@ +package dev.steady.user.fixture; + +import dev.steady.auth.domain.Platform; +import dev.steady.review.dto.response.UserCardResponse; +import dev.steady.user.domain.Position; +import dev.steady.user.domain.Stack; +import dev.steady.user.domain.User; +import dev.steady.user.dto.request.UserCreateRequest; +import dev.steady.user.dto.request.UserUpdateRequest; +import dev.steady.user.dto.response.PositionResponse; +import dev.steady.user.dto.response.PositionsResponse; +import dev.steady.user.dto.response.PutObjectUrlResponse; +import dev.steady.user.dto.response.StackResponse; +import dev.steady.user.dto.response.StacksResponse; +import dev.steady.user.dto.response.UserDetailResponse; +import dev.steady.user.dto.response.UserMyDetailResponse; +import dev.steady.user.dto.response.UserOtherDetailResponse; +import org.instancio.Instancio; +import org.springframework.web.util.UriComponentsBuilder; + +import java.util.List; + +import static dev.steady.review.fixture.ReviewFixture.createUserCardResponses; +import static org.instancio.Select.field; + +public class UserFixturesV2 { + + private static final String DEFAULT_PROFILE_IMAGE_URL = "https://team-13-image-bucket.s3.ap-northeast-2.amazonaws.com/profile/steady_default_profile.svg"; + + public static User generateUser(Position position) { + return Instancio.of(User.class) + .ignore(field(User::getId)) + .ignore(field(User::isDeleted)) + .set(field(User::getProfileImage), DEFAULT_PROFILE_IMAGE_URL) + .set(field(User::getPosition), position) + .create(); + } + + public static User generateUserEntity() { + return Instancio.of(User.class) + .ignore(field(User::isDeleted)) + .set(field(User::getId), 1L) + .set(field(User::getProfileImage), DEFAULT_PROFILE_IMAGE_URL) + .set(field(User::getPosition), generatePositionEntity()) + .create(); + } + + public static List generateStacks() { + return List.of(generateStack(), generateStack()); + } + + public static UserCreateRequest createUserCreateRequest() { + return new UserCreateRequest( + 1L, + "닉네임", + 1L, + List.of(1L, 2L) + ); + } + + public static UserUpdateRequest createUserUpdateRequest() { + return new UserUpdateRequest( + "new_image.jpeg", + "새로운 꼬부기", + "프로필 수정했어요.", + 1L, + List.of(1L, 2L) + ); + } + + public static UserUpdateRequest createUserUpdateRequest(Long positionId, List stacksId) { + return new UserUpdateRequest( + "new_image.jpg", + "newNickname", + "newBio", + positionId, + stacksId + ); + } + + public static UserMyDetailResponse createUserMyDetailResponse(Platform platform) { + return UserMyDetailResponse.builder() + .platform(platform) + .userId(1L) + .nickname("꼬부기") + .profileImage("profile.png") + .bio("안녕하세요") + .position(new PositionResponse(1L, "백엔드")) + .stacks(List.of( + new StackResponse(1L, "Java", "java.jpg"), + new StackResponse(2L, "JavaScript", "javascript.jpeg"))) + .build(); + } + + public static UserOtherDetailResponse createUserOtherDetailResponse() { + UserDetailResponse userDetailResponse = UserDetailResponse.builder() + .userId(2L) + .nickname("쿠키") + .profileImage("default_profile_image.png") + .bio("개발해요") + .position(new PositionResponse(1L, "프론트엔드")) + .stacks(List.of( + new StackResponse(1L, "React", "react.jpg"), + new StackResponse(2L, "JavaScript", "javascript.jpeg"))) + .build(); + + List userCardResponses = createUserCardResponses(); + List reviewComments = List.of( + "항상 성실하게 참여하는 모습 보기 좋습니다." + ); + + return UserOtherDetailResponse.of( + userDetailResponse, + userCardResponses, + reviewComments + ); + } + + public static Position generatePosition() { + return Instancio.of(Position.class) + .ignore(field(Position::getId)) + .create(); + } + + public static Position generatePositionEntity() { + return Instancio.of(Position.class) + .set(field(Position::getId), 1L) + .set(field(Position::getName), "포지션") + .create(); + } + + public static List createPositions() { + return List.of(generatePosition(), generatePosition()); + } + + public static Stack generateStack() { + return Instancio.of(Stack.class) + .ignore(field(Stack::getId)) + .create(); + } + + public static Stack generateStackEntity() { + return Instancio.of(Stack.class) + .set(field(Stack::getId), 1L) + .set(field(Stack::getName), "Java") + .create(); + } + + public static StacksResponse createStackResponses() { + return new StacksResponse(List.of( + new StackResponse(1L, "Java", "www.java.com"), + new StackResponse(2L, "JavaScript", "www.javascript.com") + )); + } + + public static PositionsResponse createPositionResponses() { + return new PositionsResponse(List.of( + new PositionResponse(1L, "백엔드"), + new PositionResponse(2L, "프론트엔드") + )); + } + + public static PutObjectUrlResponse createProfileUploadUrlResponse() { + String presignedUrl = UriComponentsBuilder + .fromUriString("bucket-name.s3.region.amazonaws.com/path/{fileName}") + .queryParam("X-Amz-Algorithm", "{Algorithm}") + .queryParam("X-Amz-Date", "{Date}") + .queryParam("X-Amz-SignedHeaders", "{SignedHeaders}") + .queryParam("X-Amz-Credential", "{Credential}") + .queryParam("X-Amz-Expires", "{Expires}") + .queryParam("X-Amz-Signature", "{Signature}") + .build().toString(); + String objectUrl = "https:{bucket_name}.s3.{region}.com/{key}"; + return PutObjectUrlResponse.of(presignedUrl, objectUrl); + } + +} From 5a145f82e547639e740b956ba06cd5c24d0efa06 Mon Sep 17 00:00:00 2001 From: jun Date: Wed, 20 Dec 2023 03:20:10 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:sparkles:=20=EC=8B=A0=EC=B2=AD=EC=84=9C=20?= =?UTF-8?q?=EC=A0=9C=EC=B6=9C=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 중복제출 및 작성자 제출 검증 로직 --- .../service/ApplicationService.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/steady/application/service/ApplicationService.java b/src/main/java/dev/steady/application/service/ApplicationService.java index 7621744..a5dbfd7 100644 --- a/src/main/java/dev/steady/application/service/ApplicationService.java +++ b/src/main/java/dev/steady/application/service/ApplicationService.java @@ -14,8 +14,6 @@ import dev.steady.application.dto.response.MyApplicationSummaryResponse; import dev.steady.application.dto.response.SliceResponse; import dev.steady.global.auth.UserInfo; -import dev.steady.global.exception.DuplicateException; -import dev.steady.global.exception.ForbiddenException; import dev.steady.notification.domain.ApplicationResultNotificationStrategy; import dev.steady.notification.domain.FreshApplicationNotificationStrategy; import dev.steady.notification.domain.NotificationStrategy; @@ -36,8 +34,6 @@ import static dev.steady.application.domain.ApplicationStatus.ACCEPTED; import static dev.steady.application.domain.ApplicationStatus.WAITING; -import static dev.steady.application.exception.ApplicationErrorCode.APPLICATION_DUPLICATION; -import static dev.steady.application.exception.ApplicationErrorCode.STEADY_LEADER_SUBMISSION; @Slf4j @Service @@ -149,6 +145,30 @@ private void validateApplicationDuplication(Long steadyId, User user) { }); } + private void saveSurveyResults(Application application, List requests) { + List surveyResults = createSurveyResults(application, requests); + surveyResultRepository.saveAll(surveyResults); + } + + private Application saveApplication(User user, Steady steady) { + Application application = new Application(user, steady); + return applicationRepository.save(application); + } + + private void checkIfLeaderAndValidateDuplication(Steady steady, User user, Long steadyId) { + if (steady.isLeader(user)) { + throw new ForbiddenException(STEADY_LEADER_SUBMISSION); + } + validateApplicationDuplication(steadyId, user); + } + + private void validateApplicationDuplication(Long steadyId, User user) { + applicationRepository.findBySteadyIdAndUserIdAndStatus(steadyId, user.getId(), WAITING) + .ifPresent(application -> { + throw new DuplicateException(APPLICATION_DUPLICATION); + }); + } + private void addParticipant(Application application, User leader) { Steady steady = application.getSteady(); User user = application.getUser(); From 82d1fcd2f074d4bca2e11fd9ef9aeecd3eff431a Mon Sep 17 00:00:00 2001 From: jun Date: Wed, 20 Dec 2023 03:30:17 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:recycle:=20=EC=83=81=ED=83=9C=EC=9D=98=20?= =?UTF-8?q?=EC=83=81=EA=B4=80=EC=97=86=EC=9D=B4=20=EC=8B=A0=EC=B2=AD?= =?UTF-8?q?=EC=84=9C=EA=B0=80=20=EC=A1=B4=EC=9E=AC=ED=95=98=EB=A9=B4=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ApplicationService.java | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/main/java/dev/steady/application/service/ApplicationService.java b/src/main/java/dev/steady/application/service/ApplicationService.java index a5dbfd7..54c6fef 100644 --- a/src/main/java/dev/steady/application/service/ApplicationService.java +++ b/src/main/java/dev/steady/application/service/ApplicationService.java @@ -14,6 +14,8 @@ import dev.steady.application.dto.response.MyApplicationSummaryResponse; import dev.steady.application.dto.response.SliceResponse; import dev.steady.global.auth.UserInfo; +import dev.steady.global.exception.DuplicateException; +import dev.steady.global.exception.ForbiddenException; import dev.steady.notification.domain.ApplicationResultNotificationStrategy; import dev.steady.notification.domain.FreshApplicationNotificationStrategy; import dev.steady.notification.domain.NotificationStrategy; @@ -34,7 +36,8 @@ import static dev.steady.application.domain.ApplicationStatus.ACCEPTED; import static dev.steady.application.domain.ApplicationStatus.WAITING; - +import static dev.steady.application.exception.ApplicationErrorCode.APPLICATION_DUPLICATION; +import static dev.steady.application.exception.ApplicationErrorCode.STEADY_LEADER_SUBMISSION; @Slf4j @Service @RequiredArgsConstructor @@ -138,30 +141,6 @@ private void checkIfLeaderAndValidateDuplication(Steady steady, User user, Long validateApplicationDuplication(steadyId, user); } - private void validateApplicationDuplication(Long steadyId, User user) { - applicationRepository.findBySteadyIdAndUserId(steadyId, user.getId()) - .ifPresent(application -> { - throw new DuplicateException(APPLICATION_DUPLICATION); - }); - } - - private void saveSurveyResults(Application application, List requests) { - List surveyResults = createSurveyResults(application, requests); - surveyResultRepository.saveAll(surveyResults); - } - - private Application saveApplication(User user, Steady steady) { - Application application = new Application(user, steady); - return applicationRepository.save(application); - } - - private void checkIfLeaderAndValidateDuplication(Steady steady, User user, Long steadyId) { - if (steady.isLeader(user)) { - throw new ForbiddenException(STEADY_LEADER_SUBMISSION); - } - validateApplicationDuplication(steadyId, user); - } - private void validateApplicationDuplication(Long steadyId, User user) { applicationRepository.findBySteadyIdAndUserIdAndStatus(steadyId, user.getId(), WAITING) .ifPresent(application -> { From 803cbc6bb0c1d222a2c6142bbed2ec92a02ed798 Mon Sep 17 00:00:00 2001 From: weonest Date: Wed, 27 Dec 2023 21:19:22 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:bug:=20=EA=B9=83=20=ED=98=95=EC=83=81=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EC=8B=A4=ED=8C=A8=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/steady/application/service/ApplicationService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/steady/application/service/ApplicationService.java b/src/main/java/dev/steady/application/service/ApplicationService.java index 54c6fef..cefea44 100644 --- a/src/main/java/dev/steady/application/service/ApplicationService.java +++ b/src/main/java/dev/steady/application/service/ApplicationService.java @@ -142,7 +142,7 @@ private void checkIfLeaderAndValidateDuplication(Steady steady, User user, Long } private void validateApplicationDuplication(Long steadyId, User user) { - applicationRepository.findBySteadyIdAndUserIdAndStatus(steadyId, user.getId(), WAITING) + applicationRepository.findBySteadyIdAndUserId(steadyId, user.getId()) .ifPresent(application -> { throw new DuplicateException(APPLICATION_DUPLICATION); });