Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] 테스트 코드 리팩토링 #730

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 버저닝 걷어내고 살렸으면 작업량이 줄어드셨을텐데... 고생 많으셨어요 😭

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
@SpringBootTest
@AutoConfigureMockMvc
@Transactional
@Disabled("무중단 배포를 위한 API 버저닝으로 인한 임시 disabled")
class AcceptanceTest {

@MockBean
Expand Down Expand Up @@ -131,7 +130,7 @@ void setUp() {
.parseSubject(로그인_정보.tokenResponse().accessToken(), tokenConfig.secretKey()));

MvcResult result = mockMvc.perform(
get("/api/studies")
get("/api/v2/studies")
.param("memberId", String.valueOf(memberId))
.header(HttpHeaders.AUTHORIZATION, 로그인_정보.createAuthorizationHeader()))
.andExpect(status().isOk())
Expand All @@ -145,7 +144,7 @@ void setUp() {
}

private LoginResponse 비회원_로그인을_진행한다() throws Exception {
MvcResult result = mockMvc.perform(post("/api/auth/guest"))
MvcResult result = mockMvc.perform(post("/api/v2/auth/guest"))
.andExpect(status().isOk())
.andReturn();

Expand All @@ -166,7 +165,7 @@ void setUp() {
"mock-picture"));

MvcResult result = mockMvc.perform(
post("/api/auth/login")
post("/api/v2/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest))
.andExpect(status().isOk())
Expand All @@ -182,7 +181,7 @@ void setUp() {
CreateStudyRequest request = new CreateStudyRequest("studyName", 1, 20);
String jsonRequest = objectMapper.writeValueAsString(request);
MvcResult result = mockMvc.perform(
post("/api/studies")
post("/api/v2/studies")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)
.header(HttpHeaders.AUTHORIZATION, 로그인_정보.createAuthorizationHeader()))
Expand All @@ -192,7 +191,7 @@ void setUp() {

String[] parsed = locationHeader.split("/");
System.out.println(locationHeader);
return Long.parseLong(parsed[3]);
return Long.parseLong(parsed[4]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 /api/v2/studies/1를 파싱하는 부분이어서 parsed[4]로 바뀐거니 다른 분들 보실때 참고하세요~
이런 부분은 정말 유지보수성이 떨어지는 코드인거 같은데 당장 뾰족한 수가 떠오르진 않네요 ㅋㅋㅋ;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Long.parseLong(parsed[4]);
return Long.parseLong(parsed[parsed.length-1]);

코테풀 때 사용하는 코드 스타일이기는 한데 지금처럼 하드 코딩하는 것보단 나을 것 같아서 제안드려봐요...!

}

private Long 스터디에_참여한다(LoginResponse 로그인_정보, Long 스터디_아이디) throws Exception {
Expand All @@ -202,7 +201,7 @@ void setUp() {
String jsonRequest = objectMapper.writeValueAsString(request);

MvcResult result = mockMvc.perform(
post("/api/studies/{studyId}/participants", 스터디_아이디)
post("/api/v2/studies/{studyId}/participants", 스터디_아이디)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)
.header(HttpHeaders.AUTHORIZATION, 로그인_정보.createAuthorizationHeader()))
Expand All @@ -220,7 +219,7 @@ void setUp() {
WritePlanRequest request = new WritePlanRequest(참여자_아이디, Map.of("plan", "test"));
String jsonRequest = objectMapper.writeValueAsString(request);

mockMvc.perform(post("/api/studies/{studyId}/contents/write-plan", 스터디_아이디)
mockMvc.perform(post("/api/v2/studies/{studyId}/contents/write-plan", 스터디_아이디)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)
.header(HttpHeaders.AUTHORIZATION, 로그인_정보.createAuthorizationHeader()))
Expand All @@ -229,7 +228,7 @@ void setUp() {

private void 스터디_상태를_다음_단계로_넘긴다(LoginResponse 로그인_정보, Long 스터디_아이디)
throws Exception {
mockMvc.perform(post("/api/studies/{studyId}/next-step", 스터디_아이디)
mockMvc.perform(post("/api/v2/studies/{studyId}/next-step", 스터디_아이디)
.header(HttpHeaders.AUTHORIZATION, 로그인_정보.createAuthorizationHeader()))
.andExpect(status().isNoContent());
}
Expand All @@ -239,7 +238,7 @@ void setUp() {
Map.of("retrospect", "test"));
String jsonRequest = objectMapper.writeValueAsString(request);

mockMvc.perform(post("/api/studies/{studyId}/contents/write-retrospect",
mockMvc.perform(post("/api/v2/studies/{studyId}/contents/write-retrospect",
스터디_아이디)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)
Expand All @@ -248,7 +247,7 @@ void setUp() {
}

private void 스터디_종료_후_결과_조회(LoginResponse 로그인_정보, Long 스터디_아이디) throws Exception {
MvcResult result = mockMvc.perform(get("/api/studies/{studyId}/participants", 스터디_아이디)
MvcResult result = mockMvc.perform(get("/api/v2/studies/{studyId}/participants", 스터디_아이디)
.accept(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, 로그인_정보.createAuthorizationHeader()))
.andExpect(status().isOk())
Expand All @@ -268,7 +267,7 @@ void setUp() {
}

private String 스터디_아이디로_참여_코드를_얻는다(LoginResponse 로그인_정보, Long 스터디_아이디) throws Exception {
MvcResult result = mockMvc.perform(get("/api/participant-codes")
MvcResult result = mockMvc.perform(get("/api/v2/participant-codes")
.param("studyId", 스터디_아이디.toString())
.accept(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, 로그인_정보.createAuthorizationHeader()))
Expand All @@ -284,7 +283,7 @@ void setUp() {
}

private void 참여_코드로_스터디_아이디를_얻는다(LoginResponse 로그인_정보, String 참여_코드) throws Exception {
MvcResult result = mockMvc.perform(get("/api/studies")
MvcResult result = mockMvc.perform(get("/api/v2/studies")
.param("participantCode", 참여_코드)
.accept(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, 로그인_정보.createAuthorizationHeader()))
Expand Down