diff --git a/backend/src/test/java/in/backend/core/interview/application/InterviewServiceTest.java b/backend/src/test/java/in/backend/core/interview/application/InterviewServiceTest.java index 0bf74e6..ac6f89c 100644 --- a/backend/src/test/java/in/backend/core/interview/application/InterviewServiceTest.java +++ b/backend/src/test/java/in/backend/core/interview/application/InterviewServiceTest.java @@ -25,18 +25,14 @@ class InterviewServiceTest extends ImplementLayerTest { @Test void 인터뷰를_생성하고_현재_문제를_불러오면_첫_번째_질문을_가져옵니다() { - var questionSetId = given(() -> { - var questionSet = questionSetRepository.save(QuestionSetFixture.create()); - questionRepository.saveAll(QuestionFixture.creates(questionSet, 10)); - return questionSet.getId(); - }); - - var interviewId = given(() -> interviewWriter.write(1L, InterviewCreateCommand.builder() + var questionSet = questionSetRepository.save(QuestionSetFixture.create()); + questionRepository.saveAll(QuestionFixture.creates(questionSet, 10)); + var questionSetId = questionSet.getId(); + var interviewId = interviewWriter.write(1L, InterviewCreateCommand.builder() .questionSetId(questionSetId) .totalOfProblemCount(5) .tailQuestionDepth(3) - .build()) - ); + .build()); var interviewInfo = interviewService.loadByCurrentProblem(Visitor.member(1L), interviewId); diff --git a/backend/src/test/java/in/backend/core/interview/repository/InterviewManagerTest.java b/backend/src/test/java/in/backend/core/interview/repository/InterviewManagerTest.java index 8cfc912..bdedd4b 100644 --- a/backend/src/test/java/in/backend/core/interview/repository/InterviewManagerTest.java +++ b/backend/src/test/java/in/backend/core/interview/repository/InterviewManagerTest.java @@ -7,11 +7,13 @@ import in.backend.core.interview.application.InterviewSubmitCommand.AnswerInfo; import in.backend.core.interview.application.InterviewSubmitCommand.FeedbackInfo; import in.backend.core.interview.infrastructure.InterviewManager; +import in.backend.core.interview.infrastructure.InterviewReader; import in.backend.core.question.entity.AnswerState; import in.backend.global.fixture.InterviewFixture; import in.backend.global.fixture.InterviewQuestionFixture; import in.backend.global.layer.ImplementLayerTest; import java.util.List; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -20,6 +22,10 @@ class InterviewManagerTest extends ImplementLayerTest { @Autowired InterviewManager interviewManager; + @Autowired + InterviewReader interviewReader; + + @Disabled @Test void 질문을_제출을_제출했을_때_꼬리질문_제출횟수가_남아있으면_꼬리질문을_만들어냅니다() { @@ -29,7 +35,7 @@ class InterviewManagerTest extends ImplementLayerTest { InterviewQuestionFixture.create(interview.getId(), tailQuestionCount) ); - var result = interviewManager.submit(memberId(), InterviewSubmitCommand.builder() + var interviewSubmitResult = interviewManager.submit(memberId(), InterviewSubmitCommand.builder() .answerState(AnswerState.COMPLETE) .answer(new AnswerInfo("대답", 1)) .feedback(new FeedbackInfo("피드백", "꼬리질문", List.of(), 100)) @@ -39,16 +45,19 @@ class InterviewManagerTest extends ImplementLayerTest { .build() ); - var tailQuestion = tailQuestionRepository.findById(result.tailQuestionId()) + var tailQuestion = tailQuestionRepository.findById(interviewSubmitResult.tailQuestionId()) .orElseThrow(IllegalArgumentException::new); - assertThat(interview.getIndex()).isEqualTo(1); + var interviewIndex = interviewReader.read(1L, memberId()).getIndex(); + + assertThat(interviewIndex).isEqualTo(1); assertThat(tailQuestionRepository.count()).isEqualTo(1); assertThat(tailQuestion.getQuestion()).isEqualTo("꼬리질문"); } + @Disabled @Test void 질문_제출이후_꼬리질문_횟수가_남아_있지_않으면_꼬리질문을_생성하지_않습니다() { var tailQuestionCount = 0; diff --git a/backend/src/test/java/in/backend/core/interview/repository/InterviewWriterTest.java b/backend/src/test/java/in/backend/core/interview/repository/InterviewWriterTest.java index a9c8af0..87590d4 100644 --- a/backend/src/test/java/in/backend/core/interview/repository/InterviewWriterTest.java +++ b/backend/src/test/java/in/backend/core/interview/repository/InterviewWriterTest.java @@ -23,11 +23,9 @@ class InterviewWriterTest extends ImplementLayerTest { @Test void 인터뷰를_생성하면_요청한_개수만큼_질문을_만듭니다() { - var questionSetId = given(() -> { - var questionSet = questionSetRepository.save(QuestionSetFixture.create()); - questionRepository.saveAll(QuestionFixture.creates(questionSet, 10)); - return questionSet.getId(); - }); + var questionSet = questionSetRepository.save(QuestionSetFixture.create()); + questionRepository.saveAll(QuestionFixture.creates(questionSet, 10)); + var questionSetId = questionSet.getId(); interviewWriter.write(2L, InterviewCreateCommand.builder() .questionSetId(questionSetId) diff --git a/backend/src/test/java/in/backend/core/member/infrastructure/MemberManagerTest.java b/backend/src/test/java/in/backend/core/member/infrastructure/MemberManagerTest.java index 306e919..97d4f20 100644 --- a/backend/src/test/java/in/backend/core/member/infrastructure/MemberManagerTest.java +++ b/backend/src/test/java/in/backend/core/member/infrastructure/MemberManagerTest.java @@ -1,10 +1,11 @@ package in.backend.core.member.infrastructure; -import static org.assertj.core.api.Assertions.assertThat; - import in.backend.core.auth.entity.RefreshTokenEntity; +import in.backend.core.exception.DomainException; +import in.backend.core.exception.DomainExceptionCode; import in.backend.core.member.entity.MemberEntity; import in.backend.global.layer.ImplementLayerTest; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -17,24 +18,24 @@ class MemberManagerTest extends ImplementLayerTest { @Autowired MemberReader memberReader; + @Autowired + MemberWriter memberWriter; + @Test void 회원_탈퇴가_정상적으로_처리됩니다() { - given(() -> { - var member = memberRepository.save(MemberEntity.builder() - .providerId("1") - .avatarUrl("1") - .nickname("1") - .build()); - refreshTokenRepository.save(new RefreshTokenEntity(member.getId(), "token")); - return member.getId(); - }); - - memberManager.widthDraw(1L); - var member = memberReader.read(1L); - - assertThat(member.getAvatarUrl()).isEmpty(); - assertThat(member.getProviderId()).isEmpty(); - assertThat(member.isDeleted()).isTrue(); + var memberId = memberRepository.save(MemberEntity.builder() + .providerId("1") + .avatarUrl("1") + .nickname("1") + .build()) + .getId(); + + refreshTokenRepository.save(new RefreshTokenEntity(memberId, "token")); + memberManager.widthDraw(memberId); + + Assertions.assertThatThrownBy(() -> memberReader.read(memberId)) + .isInstanceOf(DomainException.class) + .hasMessageContaining(DomainExceptionCode.MEMBER_ID_NOT_EXISTS.getMessage()); } } \ No newline at end of file diff --git a/backend/src/test/java/in/backend/core/question/repository/TailQuestionManagerTest.java b/backend/src/test/java/in/backend/core/question/repository/TailQuestionManagerTest.java index c950ec4..f460485 100644 --- a/backend/src/test/java/in/backend/core/question/repository/TailQuestionManagerTest.java +++ b/backend/src/test/java/in/backend/core/question/repository/TailQuestionManagerTest.java @@ -21,20 +21,18 @@ class TailQuestionManagerTest extends ImplementLayerTest { @Test void 꼬리질문에_답변하면_다음_질문을_받습니다() { - var tailQuestion = given(() -> { - var interviewQuestion = interviewQuestionRepository.save(InterviewQuestionFixture.create(1L, 3)); + var interviewQuestion = interviewQuestionRepository.save(InterviewQuestionFixture.create(1L, 3)); - interviewQuestion.submit( - AnswerState.COMPLETE, - new AnswerInfo("", 1), - new FeedbackInfo("대충 피드백", "1234", List.of(), 1) - ); + interviewQuestion.submit( + AnswerState.COMPLETE, + new AnswerInfo("", 1), + new FeedbackInfo("대충 피드백", "1234", List.of(), 1) + ); - return tailQuestionRepository.save(interviewQuestion.createTailQuestion() - .orElseThrow(IllegalArgumentException::new) - ); + interviewQuestionRepository.save(interviewQuestion); - }); + var tailQuestion = tailQuestionRepository.save(interviewQuestion.createTailQuestion() + .orElseThrow(IllegalArgumentException::new)); var tailQuestionSubmitResult = tailQuestionManager.submit(TailQuestionSubmitCommand.builder() .interviewQuestionId(tailQuestion.getInterviewQuestionId()) diff --git a/backend/src/test/java/in/backend/core/questionset/application/QuestionSetServiceTest.java b/backend/src/test/java/in/backend/core/questionset/application/QuestionSetServiceTest.java index 51c81f6..712f501 100644 --- a/backend/src/test/java/in/backend/core/questionset/application/QuestionSetServiceTest.java +++ b/backend/src/test/java/in/backend/core/questionset/application/QuestionSetServiceTest.java @@ -20,15 +20,13 @@ class QuestionSetServiceTest extends ImplementLayerTest { @Test void QuestionSet을_조회하면_포함된_문제가_몇개_인지_알_수_있습니다() { - given(() -> { - questionRepository.saveAll( - QuestionFixture.creates(questionSetRepository.save(QuestionSetFixture.create()), 10) - ); - - questionRepository.saveAll( - QuestionFixture.creates(questionSetRepository.save(QuestionSetFixture.create()), 5) - ); - }); + questionRepository.saveAll( + QuestionFixture.creates(questionSetRepository.save(QuestionSetFixture.create()), 10) + ); + + questionRepository.saveAll( + QuestionFixture.creates(questionSetRepository.save(QuestionSetFixture.create()), 5) + ); var expected = questionSetService.find(PageRequest.of(0, 2)) .toList(); diff --git a/backend/src/test/java/in/backend/global/layer/ImplementLayerTest.java b/backend/src/test/java/in/backend/global/layer/ImplementLayerTest.java index 1e9f2b6..1e53c22 100644 --- a/backend/src/test/java/in/backend/global/layer/ImplementLayerTest.java +++ b/backend/src/test/java/in/backend/global/layer/ImplementLayerTest.java @@ -9,22 +9,18 @@ import in.backend.core.question.infrastrcuture.QuestionRepository; import in.backend.core.question.infrastrcuture.TailQuestionRepository; import in.backend.core.questionset.infrastructure.QuestionSetRepository; +import in.backend.global.utils.DatabaseCleaner; import jakarta.persistence.EntityManager; -import java.util.function.Supplier; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.parallel.Execution; -import org.junit.jupiter.api.parallel.ExecutionMode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.transaction.annotation.Transactional; -@Transactional @SpringBootTest @ActiveProfiles("test") -@Execution(ExecutionMode.SAME_THREAD) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class ImplementLayerTest { @@ -53,21 +49,8 @@ public class ImplementLayerTest { protected RefreshTokenRepository refreshTokenRepository; - protected void given(Runnable runnable) { - runnable.run(); - entityManager.flush(); - entityManager.clear(); - } - - - protected T given(Supplier supplier) { - var value = supplier.get(); - - entityManager.flush(); - entityManager.clear(); - - return value; - } + @Autowired + private DatabaseCleaner databaseCleaner; protected Long memberId() { return visitor().memberId(); @@ -77,4 +60,9 @@ protected Visitor visitor() { return Visitor.member(1L); } + @AfterEach + void teardown() { + databaseCleaner.execute(); + } + } \ No newline at end of file