Skip to content

Commit

Permalink
Merge pull request #169 from TrainingDiary/fix/create-session
Browse files Browse the repository at this point in the history
운동 일지를 생성할 때 회차 별 작성 문제
  • Loading branch information
guswnee00 authored Jul 27, 2024
2 parents 53f7c6f + b3db6fe commit 131a057
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface WorkoutSessionRepository extends JpaRepository<WorkoutSessionEn
Optional<WorkoutSessionEntity> findByPtContract_TrainerAndId
(TrainerEntity trainer, Long sessionId);

Optional<WorkoutSessionEntity> findByPtContract_TrainerAndSessionNumber
(TrainerEntity trainer, int sessionNumber);
Optional<WorkoutSessionEntity> findByPtContract_IdAndSessionNumber
(Long ptContractId, int sessionNumber);

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public WorkoutSessionResponseDto createWorkoutSession(WorkoutSessionCreateReques

// 세션 넘버에 대한 일지가 이미 존재하는지 확인
workoutSessionRepository
.findByPtContract_TrainerAndSessionNumber(trainer, dto.getSessionNumber())
.findByPtContract_IdAndSessionNumber(ptContract.getId(), dto.getSessionNumber())
.ifPresent(exist -> {
throw new WorkoutSessionAlreadyExistException(dto.getSessionNumber());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void testCreateWorkoutSessionSuccess() {

when(ptContractRepository.findByTrainerIdAndTraineeId(trainer.getId(), trainee.getId()))
.thenReturn(Optional.of(ptContract));
when(workoutSessionRepository.findByPtContract_TrainerAndSessionNumber(trainer, 1))
when(workoutSessionRepository.findByPtContract_IdAndSessionNumber(ptContract.getId(), 1))
.thenReturn(Optional.empty());
when(workoutTypeRepository.findById(workoutType.getId()))
.thenReturn(Optional.of(workoutType));
Expand All @@ -219,7 +219,7 @@ void testCreateWorkoutSessionSuccess() {
verify(ptContractRepository, times(1))
.findByTrainerIdAndTraineeId(trainer.getId(), trainee.getId());
verify(workoutSessionRepository, times(1))
.findByPtContract_TrainerAndSessionNumber(trainer, 1);
.findByPtContract_IdAndSessionNumber(ptContract.getId(), 1);
verify(workoutTypeRepository, times(1)).findById(workoutType.getId());
verify(workoutRepository, times(1)).save(workoutCaptor.capture());
verify(workoutSessionRepository, times(1)).save(workoutSessionCaptor.capture());
Expand Down Expand Up @@ -258,7 +258,8 @@ void testCreateWorkoutSessionFailPtContractNotFound() {
verify(ptContractRepository, times(1))
.findByTrainerIdAndTraineeId(trainer.getId(), trainee.getId());
verify(workoutSessionRepository, times(0))
.findByPtContract_TrainerAndSessionNumber(trainer, createRequestDto.getSessionNumber());
.findByPtContract_IdAndSessionNumber(ptContract.getId(),
createRequestDto.getSessionNumber());
verify(workoutTypeRepository, times(0)).findById(workoutType.getId());

ArgumentCaptor<WorkoutEntity> workoutCaptor = ArgumentCaptor.forClass(WorkoutEntity.class);
Expand All @@ -284,7 +285,8 @@ void testCreateWorkoutSessionFailureSessionAlreadyExists() {
when(ptContractRepository.findByTrainerIdAndTraineeId(trainer.getId(), trainee.getId()))
.thenReturn(Optional.of(ptContract));
when(workoutSessionRepository
.findByPtContract_TrainerAndSessionNumber(trainer, createRequestDto.getSessionNumber()))
.findByPtContract_IdAndSessionNumber(ptContract.getId(),
createRequestDto.getSessionNumber()))
.thenReturn(Optional.of(workoutSession));

assertThrows(WorkoutSessionAlreadyExistException.class,
Expand All @@ -293,7 +295,8 @@ void testCreateWorkoutSessionFailureSessionAlreadyExists() {
verify(ptContractRepository, times(1))
.findByTrainerIdAndTraineeId(trainer.getId(), trainee.getId());
verify(workoutSessionRepository, times(1))
.findByPtContract_TrainerAndSessionNumber(trainer, createRequestDto.getSessionNumber());
.findByPtContract_IdAndSessionNumber(ptContract.getId(),
createRequestDto.getSessionNumber());
verify(workoutTypeRepository, times(0)).findById(workoutType.getId());

ArgumentCaptor<WorkoutEntity> workoutCaptor = ArgumentCaptor.forClass(WorkoutEntity.class);
Expand All @@ -320,7 +323,8 @@ void testCreateWorkoutSessionFailWorkoutTypeNotFound() {
when(ptContractRepository.findByTrainerIdAndTraineeId(trainer.getId(), trainee.getId()))
.thenReturn(Optional.of(ptContract));
when(workoutSessionRepository
.findByPtContract_TrainerAndSessionNumber(trainer, createRequestDto.getSessionNumber()))
.findByPtContract_IdAndSessionNumber(ptContract.getId(),
createRequestDto.getSessionNumber()))
.thenReturn(Optional.empty());
when(workoutTypeRepository.findById(workoutType.getId()))
.thenReturn(Optional.empty());
Expand All @@ -331,7 +335,8 @@ void testCreateWorkoutSessionFailWorkoutTypeNotFound() {
verify(ptContractRepository, times(1))
.findByTrainerIdAndTraineeId(trainer.getId(), trainee.getId());
verify(workoutSessionRepository, times(1))
.findByPtContract_TrainerAndSessionNumber(trainer, createRequestDto.getSessionNumber());
.findByPtContract_IdAndSessionNumber(ptContract.getId(),
createRequestDto.getSessionNumber());
verify(workoutTypeRepository, times(1)).findById(workoutType.getId());

ArgumentCaptor<WorkoutEntity> workoutCaptor = ArgumentCaptor.forClass(WorkoutEntity.class);
Expand Down

0 comments on commit 131a057

Please sign in to comment.