Skip to content

Commit

Permalink
codesquad-issue-team-05#80 test : issue 작성 통합,레포지토리 테스트 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
DOEKYONG committed Aug 13, 2023
1 parent 9700471 commit e980713
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<Long> 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("요청이 성공적으로 처리되었습니다.")));
}
}
Original file line number Diff line number Diff line change
@@ -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<Long> 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<Long> 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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void postMileStones() throws Exception {
.content(request));
// then
resultActions.andExpect(status().isOk())
.andExpect(status().isOk())
.andExpect(jsonPath("$.message", containsString("요청이 성공적으로 처리되었습니다.")));

}
Expand Down
14 changes: 13 additions & 1 deletion be/issue/src/test/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);




0 comments on commit e980713

Please sign in to comment.