|
5 | 5 | import static org.mockito.Mockito.doReturn; |
6 | 6 | import static org.mockito.Mockito.doThrow; |
7 | 7 | import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; |
| 8 | +import static org.springframework.restdocs.payload.JsonFieldType.ARRAY; |
| 9 | +import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; |
| 10 | +import static org.springframework.restdocs.payload.JsonFieldType.STRING; |
8 | 11 | import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; |
9 | 12 | import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; |
10 | 13 | import static org.springframework.restdocs.request.RequestDocumentation.partWithName; |
11 | 14 |
|
| 15 | +import eatda.controller.story.StoriesDetailResponse; |
| 16 | +import eatda.controller.story.StoriesDetailResponse.StoryDetailResponse; |
12 | 17 | import eatda.controller.story.StoriesResponse; |
13 | 18 | import eatda.controller.story.StoryRegisterRequest; |
14 | 19 | import eatda.controller.story.StoryRegisterResponse; |
|
26 | 31 | import java.util.List; |
27 | 32 | import org.junit.jupiter.api.Nested; |
28 | 33 | import org.junit.jupiter.api.Test; |
| 34 | +import org.junit.jupiter.params.ParameterizedTest; |
| 35 | +import org.junit.jupiter.params.provider.EnumSource; |
29 | 36 | import org.springframework.http.HttpHeaders; |
30 | 37 | import org.springframework.restdocs.restassured.RestDocumentationFilter; |
31 | 38 |
|
@@ -223,4 +230,68 @@ class GetStory { |
223 | 230 | .body("message", equalTo(BusinessErrorCode.STORY_NOT_FOUND.getMessage())); |
224 | 231 | } |
225 | 232 | } |
| 233 | + |
| 234 | + @Nested |
| 235 | + class GetStoriesByKakaoId { |
| 236 | + |
| 237 | + RestDocsRequest requestDocument = request() |
| 238 | + .tag(Tag.STORY_API) |
| 239 | + .summary("카카오 ID로 스토리 목록 조회") |
| 240 | + .description("특정 카카오 ID에 해당하는 스토리 목록을 페이지네이션하여 조회합니다.") |
| 241 | + .pathParameter( |
| 242 | + parameterWithName("kakaoId").description("가게의 카카오 ID") |
| 243 | + ) |
| 244 | + .queryParameter( |
| 245 | + parameterWithName("size").description("스토리 개수 (기본값: 5) (최소값: 1, 최대값: 50)").optional() |
| 246 | + ); |
| 247 | + |
| 248 | + RestDocsResponse responseDocument = response() |
| 249 | + .responseBodyField( |
| 250 | + fieldWithPath("stories").type(ARRAY).description("스토리 상세 리스트"), |
| 251 | + fieldWithPath("stories[].storyId").type(NUMBER).description("스토리 ID"), |
| 252 | + fieldWithPath("stories[].imageUrl").type(STRING).description("스토리 이미지 URL"), |
| 253 | + fieldWithPath("stories[].memberId").type(NUMBER).description("회원 ID"), |
| 254 | + fieldWithPath("stories[].memberNickname").type(STRING).description("회원 닉네임") |
| 255 | + ); |
| 256 | + |
| 257 | + @Test |
| 258 | + void 카카오_ID로_스토리_목록_조회_성공() { |
| 259 | + String kakaoId = "123456"; |
| 260 | + int size = 5; |
| 261 | + StoriesDetailResponse response = new StoriesDetailResponse(List.of( |
| 262 | + new StoryDetailResponse(1L, "https://dummy-s3.com/story1.png", 1L, "커찬"), |
| 263 | + new StoryDetailResponse(2L, "https://dummy-s3.com/story2.png", 2L, "준환") |
| 264 | + )); |
| 265 | + doReturn(response).when(storyService).getPagedStoryDetails(kakaoId, size); |
| 266 | + |
| 267 | + var document = document("story/get-stories-by-kakao-id", 200) |
| 268 | + .request(requestDocument) |
| 269 | + .response(responseDocument) |
| 270 | + .build(); |
| 271 | + |
| 272 | + given(document) |
| 273 | + .queryParam("size", size) |
| 274 | + .header(HttpHeaders.AUTHORIZATION, accessToken()) |
| 275 | + .when().get("/api/stories/kakao/{kakaoId}", kakaoId) |
| 276 | + .then().statusCode(200); |
| 277 | + } |
| 278 | + |
| 279 | + @EnumSource(value = BusinessErrorCode.class, names = {"PRESIGNED_URL_GENERATION_FAILED"}) |
| 280 | + @ParameterizedTest |
| 281 | + void 카카오_ID로_스토리_목록_조회_실패(BusinessErrorCode errorCode) { |
| 282 | + String kakaoId = "nonexistent"; |
| 283 | + int size = 5; |
| 284 | + doThrow(new BusinessException(errorCode)).when(storyService).getPagedStoryDetails(kakaoId, size); |
| 285 | + |
| 286 | + var document = document("story/get-stories-by-kakao-id", errorCode) |
| 287 | + .request(requestDocument) |
| 288 | + .response(ERROR_RESPONSE) |
| 289 | + .build(); |
| 290 | + |
| 291 | + given(document) |
| 292 | + .queryParam("size", size) |
| 293 | + .when().get("/api/stories/kakao/{kakaoId}", kakaoId) |
| 294 | + .then().statusCode(errorCode.getStatus().value()); |
| 295 | + } |
| 296 | + } |
226 | 297 | } |
0 commit comments