Skip to content

Commit

Permalink
test: 주석처리된 테스트 복원
Browse files Browse the repository at this point in the history
  • Loading branch information
woosung1223 committed Oct 23, 2023
1 parent c927345 commit 4e4af6d
Showing 1 changed file with 70 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
import harustudy.backend.participant.domain.Participant;
import harustudy.backend.participant.domain.Step;
import harustudy.backend.participant.exception.ParticipantIsNotHostException;
import harustudy.backend.participantcode.domain.GenerationStrategy;
import harustudy.backend.participantcode.domain.ParticipantCode;
import harustudy.backend.study.domain.Study;
import harustudy.backend.study.dto.CreateStudyRequest;
import harustudy.backend.study.dto.StudyResponse;
import harustudy.backend.study.exception.ParticipantCodeNotFoundException;
import harustudy.backend.study.exception.StudyNotFoundException;
import jakarta.persistence.EntityManager;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand All @@ -23,123 +29,74 @@
@Transactional
@SpringBootTest
class StudyServiceTest {
//

@Autowired
private StudyService studyService;
@Autowired
private EntityManager entityManager;
//
// @Autowired
// private GenerationStrategy generationStrategy;
//
// @Test
// void 스터디_아이디로_스터디를_조회한다() {
// // given
// Study study = new Study("study", 8, 20);
// entityManager.persist(study);
// entityManager.flush();
// entityManager.clear();
//
// // when
// StudyResponse result = studyService.findPoudy(study.getId());
//
// // then
// assertAll(
// () -> assertThat(result.studyId()).isEqualTo(study.getId()),
// () -> assertThat(result.name()).isEqualTo(study.getName()),
// () -> assertThat(result.totalCycle()).isEqualTo(study.getTotalCycle()),
// () -> assertThat(result.timePerCycle()).isEqualTo(study.getTimePerCycle())
// );
// }
//
// @Test
// void 룸_아이디로_룸_조회시_없으면_예외를_던진다() {
// // given
// Study study = new Study("study", 8, 20);
// entityManager.persist(study);
// entityManager.flush();
// entityManager.clear();
//
// // when, then
// assertThatThrownBy(() -> studyService.findPoudyWithFilter(99999L, null), null)
// .isInstanceOf(MemberNotFoundException.class);
// }
//
// @Test
// void 스터디를_생성한다() {
// // given
// CreateStudyRequest request = new CreateStudyRequest("study", 8, 40);
//
// // when
// CreateStudyResponse result = studyService.createStudy(request);
//
// // then
// assertAll(
// () -> assertThat(result.studyId()).isNotNull(),
// () -> assertThat(result.participantCode()).isNotNull()
// );
// }
//
// @Test
// void 참여코드에_해당하는_스터디를_조회한다() {
// // given
// CreateStudyRequest request = new CreateStudyRequest("study", 8, 40);
// CreateStudyResponse response = studyService.createStudy(request);
// String participantCode = response.participantCode();
//
// // when
// StudiesResponse result = studyService.findPoudyWithFilter(null,
// participantCode);
//
// // then
// assertAll(
// () -> assertThat(result.studies()).hasSize(1),
// () -> assertThat(result.studies().get(0).name()).isEqualTo(request.name()),
// () -> assertThat(result.studies().get(0).totalCycle()).isEqualTo(
// request.totalCycle()),
// () -> assertThat(result.studies().get(0).timePerCycle()).isEqualTo(
// request.timePerCycle())
// );
// }
//
// @Test
// void 참여코드에_해당하는_룸_조회시_참여코드가_없으면_예외를_던진다() {
// // given
// ParticipantCode participantCode = new ParticipantCode(generationStrategy);
// Study study = new Study("study", 8, 40, participantCode);
// entityManager.persist(participantCode);
// entityManager.persist(study);
//
// entityManager.flush();
// entityManager.clear();
//
// ParticipantCode notPersisted = new ParticipantCode(generationStrategy);
//
// // when, then
// assertThatThrownBy(
// () -> studyService.findPoudyWithFilter(null, notPersisted.getCode()))
// .isInstanceOf(ParticipantCodeNotFoundException.class);
// }
//
// @Test
// void 참여코드에_해당하는_룸_조회시_참여코드에_해당하는_룸이_없으면_예외를_던진다() {
// // given
// ParticipantCode participantCode = new ParticipantCode(generationStrategy);
// Study study = new Study("study", 8, 40, participantCode);
// entityManager.persist(participantCode);
// entityManager.persist(study);
//
// ParticipantCode notStudiesCode = new ParticipantCode(generationStrategy);
// entityManager.persist(notStudiesCode);
//
// entityManager.flush();
// entityManager.clear();
//
// // when, then
// assertThatThrownBy(
// () -> studyService.findStudyWithFilter(null, notStudiesCode.getCode()))
// .isInstanceOf(StudyNotFoundException.class);
// }
@Autowired
private GenerationStrategy generationStrategy;

@Test
void 스터디_아이디로_스터디를_조회한다() {
// given
Study study = new Study("study", 8, 20);
entityManager.persist(study);
entityManager.flush();
entityManager.clear();

// when
StudyResponse result = studyService.findStudy(study.getId());

// then
assertAll(
() -> assertThat(result.studyId()).isEqualTo(study.getId()),
() -> assertThat(result.name()).isEqualTo(study.getName()),
() -> assertThat(result.totalCycle()).isEqualTo(study.getTotalCycle()),
() -> assertThat(result.timePerCycle()).isEqualTo(study.getTimePerCycle())
);
}

@Test
void 스터디_아이디로_스터디_조회시_없으면_예외를_던진다() {
// given
Study study = new Study("study", 8, 20);
entityManager.persist(study);
entityManager.flush();
entityManager.clear();

// when, then
assertThatThrownBy(() -> studyService.findStudy(99999L))
.isInstanceOf(StudyNotFoundException.class);
}

@Test
void 참여코드에_해당하는_스터디_조회시_참여코드가_없으면_예외를_던진다() {
// given
Study study = new Study("study", 8, 40);
ParticipantCode participantCode = new ParticipantCode(study, generationStrategy);
entityManager.persist(study);
entityManager.persist(participantCode);

entityManager.flush();
entityManager.clear();

// when, then
assertThatThrownBy(
() -> studyService.findStudyWithFilter(null, "!@#!@#"))
.isInstanceOf(ParticipantCodeNotFoundException.class);
}

void 스터디를_생성한다() {
// given
CreateStudyRequest request = new CreateStudyRequest("study", 8, 40);

// when
Long studyId = studyService.createStudy(request);

// then
assertThat(studyId).isNotNull();
}

@Test
void 방장이_아니라면_스터디_단계를_넘길_수_없다() {
Expand Down

0 comments on commit 4e4af6d

Please sign in to comment.