Skip to content

Commit

Permalink
test: (#249) 휴무표 작성 기간 확인 testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 committed Dec 22, 2022
1 parent a3dfb62 commit d515693
Showing 1 changed file with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package team.comit.simtong.domain.holiday.usecase

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import org.mockito.kotlin.given
import org.springframework.boot.test.mock.mockito.MockBean
import team.comit.simtong.domain.holiday.exception.HolidayExceptions
import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort
import team.comit.simtong.domain.holiday.spi.HolidaySecurityPort
import team.comit.simtong.domain.holiday.spi.QueryHolidayPeriodPort
import team.comit.simtong.domain.user.exception.UserExceptions
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.User
import team.comit.simtong.global.annotation.SimtongTest
import java.time.LocalDate
import java.util.UUID

@SimtongTest
class CheckHolidayPeriodUseCaseTests {

@MockBean
private lateinit var queryHolidayPeriodPort: QueryHolidayPeriodPort

@MockBean
private lateinit var queryUserPort: HolidayQueryUserPort

@MockBean
private lateinit var securityPort: HolidaySecurityPort

private lateinit var checkHolidayPeriodUseCase: CheckHolidayPeriodUseCase

private val id: UUID = UUID.randomUUID()

private val date: LocalDate = LocalDate.now()

private val userStub: User by lazy {
User(
id = id,
nickname = "test nickname",
name = "test name",
email = "[email protected]",
password = "test password",
employeeNumber = 1234567890,
authority = Authority.ROLE_COMMON,
spotId = id,
teamId = id,
profileImagePath = User.DEFAULT_IMAGE
)
}

@BeforeEach
fun setUp() {
checkHolidayPeriodUseCase = CheckHolidayPeriodUseCase(
queryHolidayPeriodPort = queryHolidayPeriodPort,
queryUserPort = queryUserPort,
securityPort = securityPort
)
}

@Test
fun `휴무표 작성 기간일 때`() {
// given
given(securityPort.getCurrentUserId())
.willReturn(id)

given(queryUserPort.queryUserById(id))
.willReturn(userStub)

given(queryHolidayPeriodPort.existsHolidayPeriodByDateAndSpotId(date, userStub.spotId))
.willReturn(true)

// when & then
assertDoesNotThrow {
checkHolidayPeriodUseCase.execute()
}
}

@Test
fun `휴무표 작성 기간이 아닐 때`() {
// given
given(securityPort.getCurrentUserId())
.willReturn(id)

given(queryUserPort.queryUserById(id))
.willReturn(userStub)

given(queryHolidayPeriodPort.existsHolidayPeriodByDateAndSpotId(date, userStub.spotId))
.willReturn(false)

// when & then
assertThrows<HolidayExceptions.NotFound> {
checkHolidayPeriodUseCase.execute()
}
}

@Test
fun `유저를 찾을 수 없음`() {
// given
given(securityPort.getCurrentUserId())
.willReturn(id)

given(queryUserPort.queryUserById(id))
.willReturn(null)

// when & then
assertThrows<UserExceptions.NotFound> {
checkHolidayPeriodUseCase.execute()
}
}

}

0 comments on commit d515693

Please sign in to comment.