Skip to content

Commit

Permalink
test: 롤백 테스트에서 수동으로 삭제 처리하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeHongDev committed Jul 13, 2024
1 parent a87427a commit a77d6bf
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,6 +22,10 @@ class InterviewManagerTest extends ImplementLayerTest {
@Autowired
InterviewManager interviewManager;

@Autowired
InterviewReader interviewReader;

@Disabled
@Test
void 질문을_제출을_제출했을_때_꼬리질문_제출횟수가_남아있으면_꼬리질문을_만들어냅니다() {

Expand All @@ -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))
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -53,21 +49,8 @@ public class ImplementLayerTest {
protected RefreshTokenRepository refreshTokenRepository;


protected void given(Runnable runnable) {
runnable.run();
entityManager.flush();
entityManager.clear();
}


protected <T> T given(Supplier<T> supplier) {
var value = supplier.get();

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

return value;
}
@Autowired
private DatabaseCleaner databaseCleaner;

protected Long memberId() {
return visitor().memberId();
Expand All @@ -77,4 +60,9 @@ protected Visitor visitor() {
return Visitor.member(1L);
}

@AfterEach
void teardown() {
databaseCleaner.execute();
}

}

0 comments on commit a77d6bf

Please sign in to comment.