-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
145 additions
and
8 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
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
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
2 changes: 1 addition & 1 deletion
2
...ommand/application/MemberServiceTest.java → .../unit/user/command/MemberServiceTest.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
15 changes: 15 additions & 0 deletions
15
src/test/java/com/dnd/gooding/unit/user/fixture/MemberRequestFixture.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,15 @@ | ||
package com.dnd.gooding.unit.user.fixture; | ||
|
||
import com.dnd.gooding.user.ui.dto.request.MemberRequest; | ||
|
||
public class MemberRequestFixture { | ||
|
||
public static MemberRequest create() { | ||
return MemberRequest.builder() | ||
.id("[email protected]") | ||
.name("haeyong") | ||
.emails(null) | ||
.interests(null) | ||
.build(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...y/application/MemberQueryServiceTest.java → ...it/user/query/MemberQueryServiceTest.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
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.restdocs.RestDocumentationContextProvider; | ||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; | ||
|
@@ -41,7 +42,7 @@ void member(RestDocumentationContextProvider contextProvider) throws Exception { | |
new FieldDescriptor[] { | ||
fieldWithPath("id").type(STRING).description("멤버아이디"), | ||
fieldWithPath("name").type(STRING).description("이름"), | ||
fieldWithPath("emails[].address").type(STRING).description("이메일"), | ||
fieldWithPath("emails[].address").type(STRING).description("이메일").optional(), | ||
fieldWithPath("interests[].interestCode").type(STRING).description("관심사코드"), | ||
fieldWithPath("interests[].interestName").type(STRING).description("관심사이름"), | ||
fieldWithPath("oAuthId").type(STRING).description("소셜로그인일련번호"), | ||
|
@@ -51,7 +52,9 @@ void member(RestDocumentationContextProvider contextProvider) throws Exception { | |
String id = "[email protected]"; | ||
|
||
MockMvcFactory.getRestDocsMockMvc(contextProvider, HOST_LOCAL, memberController) | ||
.perform(RestDocumentationRequestBuilders.get("/api/v1/member/{id}", id)) | ||
.perform( | ||
RestDocumentationRequestBuilders.get("/api/v1/member/{id}", id) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer gqoqmq;13o41mvcvciqermqe")) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andExpect(MockMvcResultMatchers.status().isOk()) | ||
.andDo( | ||
|
88 changes: 88 additions & 0 deletions
88
src/test/java/com/dnd/gooding/unit/user/ui/MyMemberControllerDocsTest.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,88 @@ | ||
package com.dnd.gooding.unit.user.ui; | ||
|
||
import static com.dnd.gooding.common.constants.Constant.*; | ||
import static com.dnd.gooding.documenation.DocumentUtils.*; | ||
import static org.springframework.restdocs.payload.JsonFieldType.*; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.restdocs.RestDocumentationContextProvider; | ||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; | ||
import org.springframework.restdocs.payload.FieldDescriptor; | ||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | ||
|
||
import com.dnd.gooding.annotations.RestDocsTest; | ||
import com.dnd.gooding.documenation.MockMvcFactory; | ||
import com.dnd.gooding.token.command.application.in.LogoutTokenUseCase; | ||
import com.dnd.gooding.user.command.application.in.UpdateMemberUseCase; | ||
import com.dnd.gooding.user.query.application.MemberQueryService; | ||
import com.dnd.gooding.user.ui.MyMemberController; | ||
|
||
@DisplayName("멤버API 문서화") | ||
@RestDocsTest | ||
class MyMemberControllerDocsTest { | ||
|
||
@Mock private MemberQueryService memberQueryService; | ||
@Mock private UpdateMemberUseCase updateMemberUseCase; | ||
@Mock private LogoutTokenUseCase logoutTokenUseCase; | ||
@InjectMocks | ||
private MyMemberController myMemberController; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
memberQueryService = Mockito.mock(MemberQueryService.class); | ||
updateMemberUseCase = Mockito.mock(UpdateMemberUseCase.class); | ||
logoutTokenUseCase = Mockito.mock(LogoutTokenUseCase.class); | ||
myMemberController = new MyMemberController(memberQueryService, updateMemberUseCase, logoutTokenUseCase); | ||
} | ||
|
||
@DisplayName("수정 : 멤버정보 수정") | ||
@Test | ||
void member(RestDocumentationContextProvider contextProvider) throws Exception { | ||
|
||
var commandJson = """ | ||
{ | ||
"id": "[email protected]", | ||
"name": "haeyong", | ||
"password": "123456", | ||
"emails": [{ "address" : "[email protected]" }], | ||
"interests": [{ "interestCode" : "1", "interestName" : "쇼핑"}] | ||
} | ||
"""; | ||
|
||
var requestFieldDescription = new FieldDescriptor[]{ | ||
fieldWithPath("id").type(STRING).description("멤버아이디"), | ||
fieldWithPath("name").type(STRING).description("이름"), | ||
fieldWithPath("password").type(STRING).description("비밀번호").optional(), | ||
fieldWithPath("emails[].address").type(STRING).description("이메일").optional(), | ||
fieldWithPath("interests[].interestCode").type(STRING).description("관심사코드").optional(), | ||
fieldWithPath("interests[].interestName").type(STRING).description("관심사이름").optional() | ||
}; | ||
|
||
MockMvcFactory.getRestDocsMockMvc(contextProvider, HOST_LOCAL, myMemberController) | ||
.perform(RestDocumentationRequestBuilders.post("/api/v1/my/member") | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer gqoqmq;13o41mvcvciqermqe") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(commandJson) | ||
) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andExpect(MockMvcResultMatchers.status().isNoContent()) | ||
//REST Docs 용 | ||
.andDo(MockMvcRestDocumentation.document("post-v1-my-update-member", | ||
getDocumentRequest(), | ||
getDocumentResponse(), | ||
requestFields( | ||
requestFieldDescription | ||
) | ||
)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/resources/org/springframework/restdocs/templates/asciidoctor/request-fields.snippet
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,11 @@ | ||
|=== | ||
|필드|타입|필수값|설명|형식 | ||
|
||
{{#fields}} | ||
|{{path}} | ||
|{{type}} | ||
|{{^optional}}true{{/optional}} | ||
a|{{description}} | ||
a|{{#format}}{{format}}{{/format}}{{^format}}{{/format}} | ||
{{/fields}} | ||
|=== |