From e9807136a60286faf83eb141fbafb06877a956c8 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 02:47:21 +0900 Subject: [PATCH] =?UTF-8?q?=20#80=20test=20:=20issue=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=20=ED=86=B5=ED=95=A9,=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Integration/IssueIntegrationTest.java | 60 +++++++++++++++++ .../issue/repository/IssueRepositoryTest.java | 66 +++++++++++++++++++ .../MilestoneIntegrationTest.java | 1 - be/issue/src/test/resources/data.sql | 14 +++- 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 be/issue/src/test/java/codesquad/issueTracker/issue/Integration/IssueIntegrationTest.java create mode 100644 be/issue/src/test/java/codesquad/issueTracker/issue/repository/IssueRepositoryTest.java diff --git a/be/issue/src/test/java/codesquad/issueTracker/issue/Integration/IssueIntegrationTest.java b/be/issue/src/test/java/codesquad/issueTracker/issue/Integration/IssueIntegrationTest.java new file mode 100644 index 000000000..089f124e3 --- /dev/null +++ b/be/issue/src/test/java/codesquad/issueTracker/issue/Integration/IssueIntegrationTest.java @@ -0,0 +1,60 @@ +package codesquad.issueTracker.issue.Integration; + +import static org.hamcrest.Matchers.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import annotation.IntegrationTest; +import codesquad.issueTracker.issue.dto.IssueWriteRequestDto; +import codesquad.issueTracker.jwt.domain.Jwt; +import codesquad.issueTracker.jwt.util.JwtProvider; + +@IntegrationTest +public class IssueIntegrationTest { + + @Autowired + private MockMvc mockMvc; + @Autowired + private JwtProvider jwtProvider; + @Autowired + private ObjectMapper objectMapper; + + private String jwtToken; + + @BeforeEach + void setUp() { + Jwt jwt = jwtProvider.createJwt(Map.of("memberId", 1L)); + jwtToken = jwt.getAccessToken(); + } + + @Test + @DisplayName("이슈 작성 통합테스트 ") + void postIssues() throws Exception { + // given + List ids = List.of(1L, 2L); + IssueWriteRequestDto requestDto = new IssueWriteRequestDto("제목", "내용", ids, ids, 1L, 1L); + String request = objectMapper.writeValueAsString(requestDto); + // when + ResultActions resultActions = + mockMvc.perform(post("/api/issues") + .header("Authorization", "Bearer " + jwtToken) + .contentType(MediaType.APPLICATION_JSON) + .content(request)); + // then + resultActions.andExpect(status().isOk()) + .andExpect(jsonPath("$.message", containsString("요청이 성공적으로 처리되었습니다."))); + } +} diff --git a/be/issue/src/test/java/codesquad/issueTracker/issue/repository/IssueRepositoryTest.java b/be/issue/src/test/java/codesquad/issueTracker/issue/repository/IssueRepositoryTest.java new file mode 100644 index 000000000..c9867fd32 --- /dev/null +++ b/be/issue/src/test/java/codesquad/issueTracker/issue/repository/IssueRepositoryTest.java @@ -0,0 +1,66 @@ +package codesquad.issueTracker.issue.repository; + +import static org.assertj.core.api.Assertions.*; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; + +import annotation.RepositoryTest; +import codesquad.issueTracker.issue.domain.Issue; + +@RepositoryTest +class IssueRepositoryTest { + + private IssueRepository issueRepository; + + @Autowired + public IssueRepositoryTest(JdbcTemplate jdbcTemplate) { + this.issueRepository = new IssueRepository(jdbcTemplate); + } + + @Test + @DisplayName("title, content, milestone_id, user_id insert 테스트") + void insert() { + // given + Issue issue = Issue.builder() + .title("제목") + .content("추가 한 내용") + .milestoneId(1L) + .userId(1L) + .build(); + // when + Long id = issueRepository.insert(issue); + // then + assertThat(id).isEqualTo(1L); + + } + + @Test + void insertLabels() { + // given + List request = List.of(1L, 2L); + // when + Long first = issueRepository.insertLabels(1L, request.get(0)); + Long second = issueRepository.insertLabels(1L, request.get(1)); + // then + assertThat(first).isEqualTo(request.get(0)); + assertThat(second).isEqualTo(request.get(1)); + } + + @Test + void insertAssignees() { + // given + List request = List.of(1L, 2L); + // when + Long first = issueRepository.insertAssignees(1L, request.get(0)); + Long second = issueRepository.insertAssignees(1L, request.get(1)); + // then + assertThat(first).isEqualTo(request.get(0)); + assertThat(second).isEqualTo(request.get(1)); + } + +} \ No newline at end of file diff --git a/be/issue/src/test/java/codesquad/issueTracker/milestone/intergration/MilestoneIntegrationTest.java b/be/issue/src/test/java/codesquad/issueTracker/milestone/intergration/MilestoneIntegrationTest.java index 9883b0e47..46168f947 100644 --- a/be/issue/src/test/java/codesquad/issueTracker/milestone/intergration/MilestoneIntegrationTest.java +++ b/be/issue/src/test/java/codesquad/issueTracker/milestone/intergration/MilestoneIntegrationTest.java @@ -53,7 +53,6 @@ void postMileStones() throws Exception { .content(request)); // then resultActions.andExpect(status().isOk()) - .andExpect(status().isOk()) .andExpect(jsonPath("$.message", containsString("요청이 성공적으로 처리되었습니다."))); } diff --git a/be/issue/src/test/resources/data.sql b/be/issue/src/test/resources/data.sql index 604b6b885..207e7e05a 100644 --- a/be/issue/src/test/resources/data.sql +++ b/be/issue/src/test/resources/data.sql @@ -24,7 +24,7 @@ VALUES (1, 2, '2번이슈', '내용2'); INSERT INTO issues (milestone_id, user_id, title, content) VALUES (2, 3, '3번이슈', '내용3'); INSERT INTO issues (milestone_id, user_id, title, content, is_closed) -VALUES (1, 1, '1번이슈', '닫힌이슈', true); +VALUES (1, 1, '4번이슈', '닫힌이슈', true); -- milestone INSERT INTO milestones (name, description, done_date) @@ -54,4 +54,16 @@ VALUES (2, 2); INSERT INTO issues_labels (issue_id, label_id) VALUES (3, 3); +-- assignees +INSERT INTO assignees (user_id, issue_id) +VALUES (1, 1); +INSERT INTO assignees (user_id, issue_id) +VALUES (2, 1); +INSERT INTO assignees (user_id, issue_id) +VALUES (1, 2); +INSERT INTO assignees (user_id, issue_id) +VALUES (3, 1); + + +