From c421f367e5b847dfbc904a99bd2ebdbf787a4f58 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Sun, 26 May 2024 16:03:16 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=B6=9C=EC=84=9D=20=EC=B2=B4=ED=81=AC?= =?UTF-8?q?=20=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80(#89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/ArrowIntegrationTest.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 be/src/test/java/yeonba/be/arrow/integration/ArrowIntegrationTest.java diff --git a/be/src/test/java/yeonba/be/arrow/integration/ArrowIntegrationTest.java b/be/src/test/java/yeonba/be/arrow/integration/ArrowIntegrationTest.java new file mode 100644 index 0000000..585c2e8 --- /dev/null +++ b/be/src/test/java/yeonba/be/arrow/integration/ArrowIntegrationTest.java @@ -0,0 +1,90 @@ +package yeonba.be.arrow.integration; + + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +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; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import yeonba.be.arrow.controller.ArrowController; +import yeonba.be.exception.ExceptionAdvice; +import yeonba.be.fixture.UserFixtureFactory; +import yeonba.be.user.entity.Animal; +import yeonba.be.user.entity.Area; +import yeonba.be.user.entity.User; +import yeonba.be.user.entity.VocalRange; + + +@ActiveProfiles("test") +@TestInstance(Lifecycle.PER_CLASS) +@Transactional +@SpringBootTest +public class ArrowIntegrationTest { + + @PersistenceContext + private EntityManager em; + + @Autowired + private ExceptionAdvice exceptionAdvice; + + @Autowired + private ArrowController arrowController; + private MockMvc mockMvc; + private long userId; + + @BeforeEach + void setUp() { + mockMvc = MockMvcBuilders.standaloneSetup(arrowController) + .setControllerAdvice(exceptionAdvice) + .alwaysDo(print()) + .build(); + + VocalRange vocalRange = new VocalRange("저음"); + em.persist(vocalRange); + + Animal animal = new Animal("강아지상"); + em.persist(animal); + + Area area = new Area("서울"); + em.persist(area); + em.flush(); + + User user = UserFixtureFactory.builder() + .vocalRange(vocalRange) + .animal(animal) + .area(area) + .build().getFixture(); + em.persist(user); + em.flush(); + + userId = user.getId(); + } + + @DisplayName("출석 체크를 할 수 있다.") + @Test + void dailyCheck() throws Exception { + + // when & then + mockMvc.perform( + post("/daily-check") + .requestAttr("userId", userId) + ) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.status").value("success")) + .andExpect(jsonPath("$.message").isEmpty()) + .andExpect(jsonPath("$.data").isEmpty()); + } +}