-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from HongDam-org/feat/auth-path-api-docs
[DOCS] auth and path api docs
- Loading branch information
Showing
5 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
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,15 @@ | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlightjs | ||
:toc: left | ||
:toclevels: 4 | ||
|
||
== Auth | ||
=== 리프레시 토큰 갱신 | ||
operation::post refresh token[snippets='http-request,http-response'] | ||
|
||
=== 첫 로그인 | ||
operation::post save member[snippets='http-request,http-response'] | ||
|
||
=== 저장된 멤버 로그인 | ||
operation::post login[snippets='http-request,http-response'] |
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 |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
HongDamJin | ||
|
||
include::plan.adoc[] | ||
include::auth.adoc[] | ||
include::path.adoc[] |
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,9 @@ | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlightjs | ||
:toc: left | ||
:toclevels: 4 | ||
|
||
== Path | ||
=== 경로 검색 | ||
operation::post search path[snippets='http-request,http-response'] |
120 changes: 120 additions & 0 deletions
120
backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.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,120 @@ | ||
package com.twtw.backend.domain.member.controller; | ||
|
||
import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentRequest; | ||
import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentResponse; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
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 com.twtw.backend.domain.member.dto.request.MemberSaveRequest; | ||
import com.twtw.backend.domain.member.dto.request.OAuthRequest; | ||
import com.twtw.backend.domain.member.dto.request.TokenRequest; | ||
import com.twtw.backend.domain.member.dto.response.TokenDto; | ||
import com.twtw.backend.domain.member.entity.AuthType; | ||
import com.twtw.backend.domain.member.entity.Role; | ||
import com.twtw.backend.domain.member.service.AuthService; | ||
import com.twtw.backend.support.docs.RestDocsTest; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
@DisplayName("AuthController의") | ||
@WebMvcTest(AuthController.class) | ||
class AuthControllerTest extends RestDocsTest { | ||
@MockBean private AuthService authService; | ||
|
||
@Test | ||
@DisplayName("JWT 리프레시 API가 수행되는가") | ||
void authorize() throws Exception { | ||
// given | ||
final TokenDto expected = new TokenDto("access.token.value", "refresh.token.value"); | ||
given(authService.refreshToken(any(), any())).willReturn(expected); | ||
|
||
// when | ||
final ResultActions perform = | ||
mockMvc.perform( | ||
post("/auth/refresh") | ||
.content( | ||
toRequestBody( | ||
new TokenRequest( | ||
"access.token.value", | ||
"refresh.token.value"))) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
perform.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.accessToken").isString()) | ||
.andExpect(jsonPath("$.refreshToken").isString()); | ||
|
||
// docs | ||
perform.andDo(print()) | ||
.andDo(document("post refresh token", getDocumentRequest(), getDocumentResponse())); | ||
} | ||
|
||
@Test | ||
@DisplayName("첫 로그인 API가 수행되는가") | ||
void saveMember() throws Exception { | ||
// given | ||
final TokenDto expected = new TokenDto("access.token.value", "refresh.token.value"); | ||
given(authService.saveMember(any())).willReturn(expected); | ||
|
||
// when | ||
final ResultActions perform = | ||
mockMvc.perform( | ||
post("/auth/save") | ||
.content( | ||
toRequestBody( | ||
new MemberSaveRequest( | ||
"정해진", | ||
"http://some-url-to-profile-image", | ||
"01000000000", | ||
Role.ROLE_USER, | ||
new OAuthRequest( | ||
"client-id", AuthType.APPLE)))) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
perform.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.accessToken").isString()) | ||
.andExpect(jsonPath("$.refreshToken").isString()); | ||
|
||
// docs | ||
perform.andDo(print()) | ||
.andDo(document("post save member", getDocumentRequest(), getDocumentResponse())); | ||
} | ||
|
||
@Test | ||
@DisplayName("멤버가 저장된 상태에서의 로그인 API가 수행되는가") | ||
void afterSocialLogin() throws Exception { | ||
// given | ||
final TokenDto expected = new TokenDto("access.token.value", "refresh.token.value"); | ||
given(authService.getTokenByOAuth(any())).willReturn(expected); | ||
|
||
// when | ||
final ResultActions perform = | ||
mockMvc.perform( | ||
post("/auth/login") | ||
.content( | ||
toRequestBody( | ||
new OAuthRequest("client-id", AuthType.KAKAO))) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
perform.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.accessToken").isString()) | ||
.andExpect(jsonPath("$.refreshToken").isString()); | ||
|
||
// docs | ||
perform.andDo(print()) | ||
.andDo(document("post login", getDocumentRequest(), getDocumentResponse())); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
backend/src/test/java/com/twtw/backend/domain/path/controller/PathControllerTest.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,75 @@ | ||
package com.twtw.backend.domain.path.controller; | ||
|
||
import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentRequest; | ||
import static com.twtw.backend.support.docs.ApiDocsUtils.getDocumentResponse; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
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.status; | ||
|
||
import com.twtw.backend.domain.path.dto.client.*; | ||
import com.twtw.backend.domain.path.service.PathService; | ||
import com.twtw.backend.support.docs.RestDocsTest; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@DisplayName("PathController의") | ||
@WebMvcTest(PathController.class) | ||
class PathControllerTest extends RestDocsTest { | ||
@MockBean private PathService pathService; | ||
|
||
@Test | ||
@DisplayName("경로 검색 API가 수행되는가") | ||
void searchPath() throws Exception { | ||
// given | ||
final SearchPathResponse expected = | ||
new SearchPathResponse( | ||
0, | ||
"", | ||
"", | ||
Map.of( | ||
"", | ||
new RouteUnitEnt[] { | ||
new RouteUnitEnt( | ||
new Summary(), | ||
List.of( | ||
new Double[] {0.0, 0.0}, | ||
new Double[] {0.0, 0.0})) | ||
})); | ||
|
||
given(pathService.searchPath(any())).willReturn(expected); | ||
|
||
// when | ||
final ResultActions perform = | ||
mockMvc.perform( | ||
post("/paths/search") | ||
.content( | ||
toRequestBody( | ||
new SearchPathRequest( | ||
"", | ||
"", | ||
"", | ||
SearchPathOption.TRAFAST, | ||
SearchPathFuel.DIESEL, | ||
0))) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
perform.andExpect(status().isOk()); | ||
|
||
// docs | ||
perform.andDo(print()) | ||
.andDo(document("post search path", getDocumentRequest(), getDocumentResponse())); | ||
} | ||
} |