1
1
package me.nettee.board.adapter.driving.web
2
+
2
3
import io.kotest.core.spec.style.FreeSpec
3
4
import me.nettee.board.adapter.driving.web.dto.BoardQueryDto.BoardDetailResponse
4
5
import me.nettee.board.adapter.driving.web.mapper.BoardDtoMapper
@@ -32,16 +33,16 @@ import java.time.Instant
32
33
@WebMvcTest(BoardQueryApi ::class )
33
34
@AutoConfigureMockMvc
34
35
class BoardQueryApiTest (
35
- @MockitoBean private val boardReadUseCase : BoardReadUseCase ,
36
- @MockitoBean private val boardReadByStatusesUseCase : BoardReadByStatusesUseCase ,
37
- @MockitoBean private val boardDtoMapper : BoardDtoMapper ,
36
+ @MockitoBean private val boardReadUseCase : BoardReadUseCase ,
37
+ @MockitoBean private val boardReadByStatusesUseCase : BoardReadByStatusesUseCase ,
38
+ @MockitoBean private val boardDtoMapper : BoardDtoMapper ,
38
39
@Autowired private val mvc : MockMvc
39
40
) : FreeSpec({
40
41
41
42
lateinit var boardList : List <BoardReadSummaryModel >
42
43
43
- " [GET]게시판 상세 조회" - {
44
- val mvcGet = fun(boardId: Long ): ResultActionsDsl {
44
+ " [GET]게시판 상세 조회" - {
45
+ val mvcGet = fun(boardId: Long ): ResultActionsDsl {
45
46
return mvc.get("/api/v1/boards/$boardId") {
46
47
contentType = MediaType .APPLICATION_JSON
47
48
}
@@ -56,15 +57,15 @@ class BoardQueryApiTest(
56
57
57
58
" [4xx] 비정상 요청 상태 반환" {
58
59
mvcGet(200L)
59
- .andExpect { status{ is4xxClientError()} }
60
+ .andExpect { status { is4xxClientError() } }
60
61
.andDo { print() }
61
62
.andReturn()
62
63
}
63
64
64
65
}
65
66
66
67
" [GET] statuses 사용 게시판 목록 조회" - {
67
- val mvcGet = fun(statuses: Set <BoardStatus >, page: Int ): ResultActionsDsl {
68
+ val mvcGet = fun(statuses: Set <BoardStatus >, page: Int ): ResultActionsDsl {
68
69
return mvc.get("/api/v1/boards") {
69
70
queryParam("statuses", statuses.joinToString(",") { it.name })
70
71
queryParam("page", page.toString())
@@ -82,30 +83,52 @@ class BoardQueryApiTest(
82
83
}
83
84
84
85
" [4xx] 비정상 요청 상태 반환" {
85
- val statuses = setOf( BoardStatus .REMOVED , BoardStatus .ACTIVE )
86
- mvcGet(statuses, 100)
86
+ val statuses = setOf(BoardStatus .REMOVED , BoardStatus .ACTIVE )
87
+ mvcGet(statuses, 100)
87
88
.andExpect { status { is4xxClientError() } }
88
89
.andDo { print() }
89
90
.andReturn()
90
91
}
91
92
}
92
93
94
+ var boardReadSummaryModelPage : (
95
+ List <BoardReadSummaryModel >,
96
+ Pageable ,
97
+ Set <BoardStatus >
98
+ ) -> Page <BoardReadSummaryModel >
99
+
93
100
beforeSpec {
94
- val boardDetail = BoardReadDetailModel (1L,"title1", "content1", BoardStatus .ACTIVE , Instant .now(), null);
101
+ boardReadSummaryModelPage = { boardList, pageable, boardStatus ->
102
+ // val filteredBoards = boardList.filter { it.status in boardStatus }
103
+ val filteredBoards = boardList
104
+ .takeIf { it.isNotEmpty() }
105
+ ? : throw ResponseStatusException (HttpStatus .BAD_REQUEST )
106
+
107
+ val pageContent = filteredBoards.drop(pageable.pageNumber * pageable.pageSize)
108
+ .take(pageable.pageSize)
109
+ .takeIf { it.isNotEmpty() }
110
+ ? : throw ResponseStatusException (HttpStatus .BAD_REQUEST )
111
+
112
+ PageImpl (pageContent, pageable, filteredBoards.size.toLong())
113
+ }
114
+
115
+ val boardDetail = BoardReadDetailModel (1L, "title1", "content1", BoardStatus .ACTIVE , Instant .now(), Instant .now(), null)
95
116
// list 반복문 완성 코드 ***
96
117
boardList = (1..14).flatMap {
97
118
listOf(
98
- BoardReadSummaryModel (it.toLong(), "title$it", "content$it", BoardStatus . ACTIVE , Instant .now(), null ),
99
- BoardReadSummaryModel (it.toLong(), "title$it", "content$it", BoardStatus . SUSPENDED , Instant .now(), null )
119
+ BoardReadSummaryModel (it.toLong(), "title$it", "content$it", Instant .now(), Instant .now() ),
120
+ BoardReadSummaryModel (it.toLong(), "title$it", "content$it", Instant .now(), Instant .now() )
100
121
)
101
122
}
102
123
103
- `when ` (boardReadUseCase.getBoard(1L)).thenAnswer { boardDetail }
124
+ `when `(boardReadUseCase.getBoard(1L)).thenAnswer { boardDetail }
104
125
`when `(boardReadUseCase.getBoard(argThat { it != 1L })).thenThrow(ResponseStatusException (HttpStatus .NOT_FOUND ))
105
- `when `(boardReadByStatusesUseCase.findByStatuses(
106
- any<Set <BoardStatus >>(),
107
- any<Pageable >()
108
- )).thenAnswer { invocation ->
126
+ `when `(
127
+ boardReadByStatusesUseCase.findByStatuses(
128
+ any<Set <BoardStatus >>(),
129
+ any<Pageable >()
130
+ )
131
+ ).thenAnswer { invocation ->
109
132
val statuses = invocation.getArgument<Set <BoardStatus >>(0)
110
133
val pageable = invocation.getArgument<Pageable >(1)
111
134
boardReadSummaryModelPage(boardList, pageable, statuses)
@@ -114,23 +137,4 @@ class BoardQueryApiTest(
114
137
}
115
138
})
116
139
117
- fun boardReadSummaryModelPage (
118
- boardList : List <BoardReadSummaryModel >,
119
- pageable : Pageable ,
120
- boardStatus : Set <BoardStatus >
121
- ): Page <BoardReadSummaryModel > {
122
- println (" Board Statuses: $boardStatus " )
123
- println (" Board List: ${boardList.map { it.status }} " )
124
-
125
- val filteredBoards = boardList.filter { it.status in boardStatus }
126
- .takeIf { it.isNotEmpty() }
127
- ? : throw ResponseStatusException (HttpStatus .BAD_REQUEST )
128
-
129
- val pageContent = filteredBoards.drop(pageable.pageNumber * pageable.pageSize)
130
- .take(pageable.pageSize)
131
- .takeIf { it.isNotEmpty() }
132
- ? : throw ResponseStatusException (HttpStatus .BAD_REQUEST )
133
-
134
- return PageImpl (pageContent, pageable, filteredBoards.size.toLong())
135
- }
136
140
0 commit comments