forked from codesquad-issue-team-05/issue-tracker-max
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codesquad-issue-team-05#80 test : issue 작성 통합,레포지토리 테스트 완료
- Loading branch information
Showing
4 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
be/issue/src/test/java/codesquad/issueTracker/issue/Integration/IssueIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("요청이 성공적으로 처리되었습니다."))); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
be/issue/src/test/java/codesquad/issueTracker/issue/repository/IssueRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters