-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/board service: Suspended item 조회 #79
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
base: main
Are you sure you want to change the base?
Changes from all commits
ce520d4
a2eb945
8c20da3
6484464
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,14 @@ package me.nettee.board.application.service | |
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.FreeSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.clearMocks | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import me.nettee.board.application.domain.type.BoardStatus | ||
import me.nettee.board.application.exception.BoardCommandErrorCode.BOARD_NOT_FOUND | ||
import me.nettee.board.application.exception.BoardCommandException | ||
import me.nettee.board.application.exception.BoardQueryErrorCode.BOARD_FORBIDDEN | ||
import me.nettee.board.application.exception.BoardQueryErrorCode.BOARD_NOT_FOUND | ||
import me.nettee.board.application.exception.BoardQueryException | ||
import me.nettee.board.application.model.BoardQueryModels.BoardDetail | ||
import me.nettee.board.application.model.BoardQueryModels.BoardSummary | ||
import me.nettee.board.application.port.BoardQueryPort | ||
|
@@ -23,6 +25,10 @@ class BoardQueryServiceTest : FreeSpec({ | |
val boardQueryPort = mockk<BoardQueryPort>() // mocking | ||
val boardQueryService = BoardQueryService(boardQueryPort) // 주입 | ||
|
||
beforeTest { | ||
clearMocks(boardQueryPort) | ||
} | ||
|
||
Comment on lines
+28
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓
|
||
"BoardQueryService" - { | ||
"getBoard" - { | ||
"board detail 조회 by board id" { | ||
|
@@ -52,6 +58,35 @@ class BoardQueryServiceTest : FreeSpec({ | |
verify(exactly = 1) { boardQueryPort.findById(boardId) } | ||
} | ||
|
||
"[예외] boardDetail status가 suspended 일 때 Exception 발생" { | ||
// given | ||
val boardId = 1L | ||
val now = Instant.now() | ||
|
||
val expectedDetail = BoardDetail( | ||
boardId, | ||
"Test Title", | ||
"test Content", | ||
BoardStatus.SUSPENDED, | ||
now, | ||
now | ||
) | ||
|
||
every { | ||
boardQueryPort.findById(boardId) | ||
} returns Optional.of(expectedDetail) | ||
|
||
// when | ||
val exception = shouldThrow<BoardQueryException> { | ||
boardQueryService.getBoard(boardId) | ||
} | ||
|
||
// then | ||
exception.errorCode shouldBe BOARD_FORBIDDEN | ||
|
||
verify(exactly = 1) { boardQueryPort.findById(boardId) } | ||
} | ||
|
||
"board id에 해당하는 게시판이 없으면 예외 반환" { | ||
// given | ||
val boardId = 999L | ||
|
@@ -60,7 +95,7 @@ class BoardQueryServiceTest : FreeSpec({ | |
} returns Optional.empty() | ||
|
||
// when & then | ||
val exception = shouldThrow<BoardCommandException> { | ||
val exception = shouldThrow<BoardQueryException> { | ||
boardQueryService.getBoard(boardId) | ||
} | ||
exception.errorCode shouldBe BOARD_NOT_FOUND | ||
|
@@ -87,7 +122,7 @@ class BoardQueryServiceTest : FreeSpec({ | |
), | ||
BoardSummary( | ||
2L, | ||
"Suspended Board", | ||
null, | ||
BoardStatus.SUSPENDED, | ||
now, | ||
now | ||
|
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.
👍 훌륭하고 깔끔한 작업입니다.
이 항목들이 특히 보기 좋습니다.
팀 내 작업 방식에 대한 리뷰를 지금까지 꼼꼼하게 확인해서 반영해 주신 것 같습니다.
Page
객체에서 아이템 매핑에 적절한map
함수 사용==
연산자 허용이 부분은 조금 더 생각해 볼 수 있을 것 같습니다.
title
을null
로 할지 기타 기본값을 내릴지 나중에 정할 수 있어 보입니다. 이번 단계 온보딩 프로젝트에서는 다국어 등을 고려하지 않으므로 나중에 생각해 볼 수 있을 것 같습니다.record
인스턴스 생성 시, 생성자보다 빌더나 mapstruct 함수, record 내부 메서드 등을 권장하고 싶습니다.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.
@merge-simpson 좋은 의견 감사합니다.
온보딩에서는 다중 사용이 필요 없다고 판단해 생성자를 사용했지만,
향후 다양한 활용 가능성을 고려하면 record 내부 메서드를 사용하는 것이 더 적절해 보입니다.