|
1 | 1 | package eatda.document.store; |
2 | 2 |
|
3 | 3 |
|
| 4 | +import static org.mockito.ArgumentMatchers.anyInt; |
4 | 5 | import static org.mockito.ArgumentMatchers.anyString; |
5 | 6 | import static org.mockito.Mockito.doReturn; |
6 | 7 | import static org.mockito.Mockito.doThrow; |
7 | 8 | import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; |
8 | 9 | import static org.springframework.restdocs.payload.JsonFieldType.ARRAY; |
| 10 | +import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; |
9 | 11 | import static org.springframework.restdocs.payload.JsonFieldType.STRING; |
10 | 12 | import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; |
11 | 13 | import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; |
12 | 14 |
|
| 15 | +import eatda.controller.store.StorePreviewResponse; |
13 | 16 | import eatda.controller.store.StoreSearchResponse; |
14 | 17 | import eatda.controller.store.StoreSearchResponses; |
| 18 | +import eatda.controller.store.StoresResponse; |
15 | 19 | import eatda.document.BaseDocumentTest; |
16 | 20 | import eatda.document.RestDocsRequest; |
17 | 21 | import eatda.document.RestDocsResponse; |
|
28 | 32 |
|
29 | 33 | public class StoreDocumentTest extends BaseDocumentTest { |
30 | 34 |
|
| 35 | + @Nested |
| 36 | + class GetStores { |
| 37 | + |
| 38 | + RestDocsRequest requestDocument = request() |
| 39 | + .tag(Tag.STORE_API) |
| 40 | + .summary("음식점 목록 조회") |
| 41 | + .queryParameter( |
| 42 | + parameterWithName("size").description("조회할 음식점 개수 (최소 1, 최대 50)") |
| 43 | + ); |
| 44 | + |
| 45 | + RestDocsResponse responseDocument = response() |
| 46 | + .responseBodyField( |
| 47 | + fieldWithPath("stores").type(ARRAY).description("음식점 목록"), |
| 48 | + fieldWithPath("stores[].id").type(NUMBER).description("음식점 ID"), |
| 49 | + fieldWithPath("stores[].imageUrl").type(STRING).description("음식점 대표 이미지 URL"), |
| 50 | + fieldWithPath("stores[].name").type(STRING).description("음식점 이름"), |
| 51 | + fieldWithPath("stores[].district").type(STRING).description("음식점 주소 (구)"), |
| 52 | + fieldWithPath("stores[].neighborhood").type(STRING).description("음식점 주소 (동)"), |
| 53 | + fieldWithPath("stores[].category").type(STRING).description("음식점 카테고리") |
| 54 | + ); |
| 55 | + |
| 56 | + @Test |
| 57 | + void 음식점_목록_최신순으로_조회() { |
| 58 | + StoresResponse response = new StoresResponse(List.of( |
| 59 | + new StorePreviewResponse(2L, "https://example.image", "농민백암순대", "강남구", "대치동", "한식"), |
| 60 | + new StorePreviewResponse(1L, "https://example.image", "석관동떡볶이", "성북구", "석관동", "한식") |
| 61 | + )); |
| 62 | + doReturn(response).when(storeService).getStores(anyInt()); |
| 63 | + |
| 64 | + int size = 2; |
| 65 | + var document = document("store/get", 200) |
| 66 | + .request(requestDocument) |
| 67 | + .response(responseDocument) |
| 68 | + .build(); |
| 69 | + |
| 70 | + given(document) |
| 71 | + .contentType(ContentType.JSON) |
| 72 | + .queryParam("size", size) |
| 73 | + .when().get("/api/shops") |
| 74 | + .then().statusCode(200); |
| 75 | + } |
| 76 | + |
| 77 | + @EnumSource(value = BusinessErrorCode.class, names = {"PRESIGNED_URL_GENERATION_FAILED"}) |
| 78 | + @ParameterizedTest |
| 79 | + void 음식점_목록_조회_실패(BusinessErrorCode errorCode) { |
| 80 | + doThrow(new BusinessException(errorCode)).when(storeService).getStores(anyInt()); |
| 81 | + |
| 82 | + int size = 2; |
| 83 | + var document = document("store/get", errorCode) |
| 84 | + .request(requestDocument) |
| 85 | + .response(ERROR_RESPONSE) |
| 86 | + .build(); |
| 87 | + |
| 88 | + given(document) |
| 89 | + .contentType(ContentType.JSON) |
| 90 | + .queryParam("size", size) |
| 91 | + .when().get("/api/shops") |
| 92 | + .then().statusCode(errorCode.getStatus().value()); |
| 93 | + } |
| 94 | + } |
| 95 | + |
31 | 96 | @Nested |
32 | 97 | class SearchStores { |
33 | 98 |
|
|
0 commit comments