Skip to content

Commit

Permalink
chore: (#167) 일정 범위가 다를 경우 예외 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut committed Dec 3, 2022
1 parent b2b7f37 commit ba64ffb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package team.comit.simtong.domain.schedule.usecase

import team.comit.simtong.domain.schedule.exception.DifferentScopeException
import team.comit.simtong.domain.schedule.exception.NotScheduleOwnerException
import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException
import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.QuerySchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.NotEnoughPermissionException
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.global.annotation.UseCase
import java.util.UUID
Expand Down Expand Up @@ -36,8 +37,12 @@ class RemoveIndividualScheduleUseCase(
val schedule = querySchedulePort.queryScheduleById(scheduleId)
?: throw ScheduleNotFoundException.EXCEPTION

if (user.id != schedule.userId || Scope.INDIVIDUAL != schedule.scope) {
throw NotEnoughPermissionException.EXCEPTION
if (user.id != schedule.userId) {
throw NotScheduleOwnerException.EXCEPTION
}

if (Scope.INDIVIDUAL != schedule.scope) {
throw DifferentScopeException.EXCEPTION
}

commandSchedulePort.delete(schedule)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package team.comit.simtong.domain.schedule.usecase

import team.comit.simtong.domain.schedule.exception.DifferentScopeException
import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException
import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.QuerySchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
Expand Down Expand Up @@ -40,6 +42,10 @@ class RemoveSpotScheduleUseCase(
throw NotEnoughPermissionException.EXCEPTION
}

if (Scope.ENTIRE != schedule.scope) {
throw DifferentScopeException.EXCEPTION
}

commandSchedulePort.delete(schedule)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ 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.schedule.exception.DifferentScopeException
import team.comit.simtong.domain.schedule.exception.NotScheduleOwnerException
import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException
import team.comit.simtong.domain.schedule.model.Schedule
import team.comit.simtong.domain.schedule.model.Scope
import team.comit.simtong.domain.schedule.spi.CommandSchedulePort
import team.comit.simtong.domain.schedule.spi.QuerySchedulePort
import team.comit.simtong.domain.schedule.spi.ScheduleQueryUserPort
import team.comit.simtong.domain.schedule.spi.ScheduleSecurityPort
import team.comit.simtong.domain.user.exception.NotEnoughPermissionException
import team.comit.simtong.domain.user.exception.UserNotFoundException
import team.comit.simtong.domain.user.model.Authority
import team.comit.simtong.domain.user.model.User
Expand Down Expand Up @@ -147,7 +148,7 @@ class RemoveIndividualScheduleUseCaseTests {
}

@Test
fun `권한이 부족함 - 다른 사용자`() {
fun `자신의 일정이 아님`() {
// given
val scheduleStub = Schedule(
id = scheduleId,
Expand All @@ -170,13 +171,13 @@ class RemoveIndividualScheduleUseCaseTests {
.willReturn(scheduleStub)

// when & then
assertThrows<NotEnoughPermissionException> {
assertThrows<NotScheduleOwnerException> {
removeIndividualScheduleUseCase.execute(scheduleId)
}
}

@Test
fun `권한이 부족함 - 지점 일정`() {
fun `일정 범위가 다름`() {
// given
val scheduleStub = Schedule(
id = scheduleId,
Expand All @@ -199,7 +200,7 @@ class RemoveIndividualScheduleUseCaseTests {
.willReturn(scheduleStub)

// when & then
assertThrows<NotEnoughPermissionException> {
assertThrows<DifferentScopeException> {
removeIndividualScheduleUseCase.execute(scheduleId)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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.schedule.exception.DifferentScopeException
import team.comit.simtong.domain.schedule.exception.ScheduleNotFoundException
import team.comit.simtong.domain.schedule.model.Schedule
import team.comit.simtong.domain.schedule.model.Scope
Expand Down Expand Up @@ -160,6 +161,48 @@ class RemoveSpotScheduleUseCaseTests {
}
}

@Test
fun `일정 범위가 다름`() {
// given
val userStub = User(
id = userId,
nickname = "test nickname",
name = "test name",
email = "[email protected]",
password = "test password",
employeeNumber = 1234567890,
authority = Authority.ROLE_SUPER,
spotId = UUID.randomUUID(),
teamId = UUID.randomUUID(),
profileImagePath = "test profile image"
)

val scheduleStub = Schedule(
id = scheduleId,
userId = userId,
spotId = spotId,
title = "test title",
scope = Scope.INDIVIDUAL,
startAt = LocalDate.now(),
endAt = LocalDate.now(),
alarmTime = Schedule.DEFAULT_ALARM_TIME
)

given(securityPort.getCurrentUserId())
.willReturn(userId)

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

given(querySchedulePort.queryScheduleById(scheduleId))
.willReturn(scheduleStub)

// when & then
assertThrows<DifferentScopeException> {
removeSpotScheduleUseCase.execute(scheduleId)
}
}

@Test
fun `일정을 찾을 수 없음`() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ enum class ScheduleErrorCode(
private val message: String
) : ErrorProperty {

// 401
DIFFERENT_SCHEDULE_SCOPE(401, "일정의 범위가 다름"),

// 403
NOT_SCHEDULE_OWNER(403, "일정의 소유자가 아님"),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package team.comit.simtong.domain.schedule.exception

import team.comit.simtong.domain.schedule.error.ScheduleErrorCode
import team.comit.simtong.global.error.BusinessException

/**
*
* Different Schedule Scope Error를 발생시키는 DifferentScopeException
*
* @author kimbeomjin
* @date 2022/12/03
* @version 1.0.0
**/
class DifferentScopeException private constructor(): BusinessException(ScheduleErrorCode.DIFFERENT_SCHEDULE_SCOPE) {

companion object {
@JvmField
val EXCEPTION = DifferentScopeException()
}
}

0 comments on commit ba64ffb

Please sign in to comment.