From b25be7c0868986b9f8cd414ba6a6ed8be92c0993 Mon Sep 17 00:00:00 2001 From: jaykayBaek Date: Wed, 29 Nov 2023 23:54:19 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EB=AC=B8=EC=9D=98=20=EB=A6=AC=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#135?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/InquiryRepositoryTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/io/oduck/api/unit/inquiry/repository/InquiryRepositoryTest.java diff --git a/src/test/java/io/oduck/api/unit/inquiry/repository/InquiryRepositoryTest.java b/src/test/java/io/oduck/api/unit/inquiry/repository/InquiryRepositoryTest.java new file mode 100644 index 00000000..7669cb5a --- /dev/null +++ b/src/test/java/io/oduck/api/unit/inquiry/repository/InquiryRepositoryTest.java @@ -0,0 +1,46 @@ +package io.oduck.api.unit.inquiry.repository; + +import static org.assertj.core.api.Assertions.*; + +import io.oduck.api.domain.inquiry.dto.InquiryReq.PostReq; +import io.oduck.api.domain.inquiry.dto.InquiryRequestHolder; +import io.oduck.api.domain.inquiry.entity.InquiryType; +import io.oduck.api.domain.member.entity.Member; +import io.oduck.api.domain.member.repository.MemberRepository; +import java.util.ArrayList; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest +@TestInstance(Lifecycle.PER_CLASS) +@ActiveProfiles("test") +public class InquiryRepositoryTest { + + @Autowired + private MemberRepository memberRepository; + + @Test + void 문의시_문의가_저장된다() { + //given + Member member = Member.builder() + .inquiries(new ArrayList<>()) + .build(); + Member target = memberRepository.save(member); + + PostReq postReq = new PostReq(InquiryType.ADD_REQUEST, "이거 왜 안 됨?", "왜"); + + //when + target.inquiry(InquiryRequestHolder.from(postReq, target)); + + //then + assertThat(target.getInquiries().isEmpty()).isFalse(); + assertThat(target.getInquiries().size()).isEqualTo(1L); + assertThat(target.getInquiries().get(0).getTitle()).isEqualTo("이거 왜 안 됨?"); + assertThat(target.getInquiries().get(0).getContent()).isEqualTo("왜"); + assertThat(target.getInquiries().get(0).getType()).isEqualTo(InquiryType.ADD_REQUEST); + } +}