-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: Board controller, service 계층 리팩토링/테스트 코드 추가 #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
89 changes: 89 additions & 0 deletions
89
src/test/java/com/Alchive/backend/controller/BoardControllerTest.java
This file contains hidden or 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,89 @@ | ||
| package com.Alchive.backend.controller; | ||
|
|
||
| import com.Alchive.backend.config.result.ResultResponse; | ||
| import com.Alchive.backend.domain.board.Board; | ||
| import com.Alchive.backend.domain.board.BoardStatus; | ||
| import com.Alchive.backend.domain.problem.Problem; | ||
| import com.Alchive.backend.domain.problem.ProblemDifficulty; | ||
| import com.Alchive.backend.domain.problem.ProblemPlatform; | ||
| import com.Alchive.backend.domain.user.User; | ||
| import com.Alchive.backend.dto.request.ProblemNumberRequest; | ||
| import com.Alchive.backend.dto.response.BoardDetailResponseDTO; | ||
| import com.Alchive.backend.dto.response.BoardResponseDTO; | ||
| import com.Alchive.backend.dto.response.ProblemResponseDTO; | ||
| import com.Alchive.backend.service.BoardService; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.springframework.http.ResponseEntity; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static com.Alchive.backend.config.result.ResultCode.*; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.nullable; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| public class BoardControllerTest { | ||
| @InjectMocks | ||
| private BoardController sut; | ||
| @Mock | ||
| private BoardService boardService; | ||
| private Board board; | ||
| private Problem problem; | ||
| private User user; | ||
| private List<String> algorithms = Arrays.asList("BFS", "DFS"); | ||
|
|
||
| private long problemId = 1L; | ||
| private int problemNumber = 1; | ||
| private String problemTitle = "testProblem"; | ||
| private String problemContent = "this is test problem's content"; | ||
| private String problemUrl = "https://test/problem/1"; | ||
| private ProblemDifficulty problemDifficulty = ProblemDifficulty.LEVEL0; | ||
| private ProblemPlatform problemPlatform = ProblemPlatform.BAEKJOON; | ||
| private long userId = 1L; | ||
| private String userEmail = "[email protected]"; | ||
| private String userName = "testUsername"; | ||
| private long boardId = 1L; | ||
| private String boardMemo = "test problem's memo"; | ||
| private BoardStatus boardStatus = BoardStatus.CORRECT; | ||
| private String boardDescription = "test problem's description"; | ||
| @BeforeEach | ||
|
|
||
| public void setUp() { | ||
| problem = new Problem(problemId, problemNumber, problemTitle, problemContent, problemUrl, problemDifficulty, problemPlatform); | ||
| user = new User(userId, userEmail, userName); | ||
| board = new Board(boardId, problem, user, boardMemo, boardStatus, boardDescription); | ||
| } | ||
|
|
||
| @DisplayName("게시물 저장 여부 조회 - 이미 존재하는 문제") | ||
| @Test | ||
| public void existBoard() { | ||
| BoardDetailResponseDTO response = new BoardDetailResponseDTO(new BoardResponseDTO(board), new ProblemResponseDTO(problem, algorithms), new ArrayList<>()); | ||
| when(boardService.isBoardSaved(any(User.class), any(ProblemNumberRequest.class))).thenReturn(response); | ||
| when(boardService.boardSavedStatus(response)).thenReturn(BOARD_ALREADY_EXIST); | ||
|
|
||
| ResponseEntity<ResultResponse> result = sut.isBoardSaved(user, new ProblemNumberRequest(problemPlatform, problemNumber)); | ||
|
|
||
| Assertions.assertEquals(BOARD_ALREADY_EXIST.getMessage(), result.getBody().getMessage()); | ||
| } | ||
|
|
||
| @DisplayName("게시물 저장 여부 조회 - 존재하지 않는 문제") | ||
| @Test | ||
| public void newBoard() { | ||
| when(boardService.isBoardSaved(any(User.class), any(ProblemNumberRequest.class))).thenReturn(null); | ||
| when(boardService.boardSavedStatus(nullable(BoardDetailResponseDTO.class))).thenReturn(BOARD_NOT_EXIST); | ||
|
|
||
| ResponseEntity<ResultResponse> result = sut.isBoardSaved(user, new ProblemNumberRequest(problemPlatform, problemNumber)); | ||
|
|
||
| Assertions.assertEquals(BOARD_NOT_EXIST.getMessage(), result.getBody().getMessage()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Page<List<BoardDetailResponseDTO>>→ 중첩 리스트 반환 구조 문제현재 구현은
①
boardList:List<BoardDetailResponseDTO>②
new PageImpl<>(List.of(boardList), …)로 한 번 더 래핑하여List<List<BoardDetailResponseDTO>>형태로 페이지네이션됩니다.컨트롤러/프론트단이 예상하는 스키마와 달라질 위험이 크며 직렬화 시 JSON 구조도 두 단계로 중첩됩니다.
아래와 같이 제너릭 타입을 단일 DTO 로 변경하고 불필요한
List.of래핑을 제거해 주세요.📝 Committable suggestion
🤖 Prompt for AI Agents