Skip to content

Commit

Permalink
test: 카테고리 조회 API 문서 테스트 추가 #207
Browse files Browse the repository at this point in the history
  • Loading branch information
jhon3242 committed Aug 19, 2024
1 parent 0bcf835 commit c34ba18
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
21 changes: 21 additions & 0 deletions backend/src/docs/asciidoc/balance.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
== 밸런스 게임

=== 카테고리 목록 조회

==== curl

include::{snippets}/balance/category/curl-request.adoc[]

==== request

include::{snippets}/balance/category/http-request.adoc[]

==== response

include::{snippets}/balance/category/http-response.adoc[]

response fields

include::{snippets}/balance/category/response-fields.adoc[]

'''
1 change: 1 addition & 0 deletions backend/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ include::exception.adoc[]
include::room.adoc[]
include::roomContent.adoc[]
include::roomBalanceVote.adoc[]
include::balance.adoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ddangkong.documentation.balance;

import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.payload.JsonFieldType.ARRAY;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import ddangkong.controller.balance.BalanceController;
import ddangkong.documentation.BaseDocumentationTest;
import ddangkong.domain.balance.content.Category;
import ddangkong.facade.balance.content.BalanceCategoriesResponse;
import ddangkong.facade.balance.content.BalanceFacade;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;

@WebMvcTest(BalanceController.class)
public class BalanceDocumentationTest extends BaseDocumentationTest {

@MockBean
private BalanceFacade balanceFacade;

@Nested
class 카테고리 {

private static final String ENDPOINT = "/api/balances/categories";

@Test
void 카테고리_목록을_조회한다() throws Exception {
// given
BalanceCategoriesResponse response = BalanceCategoriesResponse.from(Category.getCategories());
when(balanceFacade.getBalanceCategories()).thenReturn(response);

// when & then
mockMvc.perform(get(ENDPOINT))
.andExpect(status().isOk())
.andDo(document("balance/category",
responseFields(
fieldWithPath("categories").type(ARRAY).description("카테고리 목록")
)
));
}
}
}

0 comments on commit c34ba18

Please sign in to comment.