Skip to content

Commit

Permalink
test: 아이 삭제 application 계층 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
whereami2048 committed Jan 6, 2025
1 parent 972db09 commit 4f5c026
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Binary file removed dump.rdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class BabyCommandService(
}

fun deleteById(userId: UUID, babyId: UUID) {
val findBaby = babyManagerService.getBabyByIdAndUserIsAdmin(userId, babyId)
babyRepository.deleteBaby(findBaby)
babyManagerService.getBabyByIdAndUserIsAdmin(userId, babyId).let {
babyRepository.deleteBaby(it)
}
}

fun saveAll(babies: List<Baby>): List<Baby> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package kr.co.vacgom.api.baby.application

import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.mockk
import kr.co.vacgom.api.baby.domain.Baby
import kr.co.vacgom.api.baby.domain.enums.Gender
import kr.co.vacgom.api.baby.exceptioin.BabyError
import kr.co.vacgom.api.baby.presentation.dto.BabyDto
import kr.co.vacgom.api.baby.repository.BabyRepository
import kr.co.vacgom.api.babymanager.application.BabyManagerService
import kr.co.vacgom.api.global.exception.error.BusinessException
import kr.co.vacgom.api.global.util.UuidCreator
import kr.co.vacgom.api.user.application.UserQueryService
import java.time.LocalDate

Expand All @@ -22,6 +27,7 @@ class BabyCommandServiceTest : DescribeSpec({
babyRepository = babyRepositoryMock,
userQueryService = userQueryServiceMock,
)

describe("아이 정보 수정 테스트") {
context("아이가 존재하는 경우") {
it("정상적으로 정보 수정이 이루어진다.") {
Expand All @@ -43,6 +49,27 @@ class BabyCommandServiceTest : DescribeSpec({
}
}
}

describe("아이 삭제 테스트") {
context("아이가 존재하는 경우") {
it("정상적으로 아이가 삭제된다.") {
val userId = UuidCreator.create()
every { babyManagerServiceMock.getBabyByIdAndUserIsAdmin(userId, baby.id) } returns baby

shouldNotThrow<BusinessException> { sut.deleteById(userId, baby.id) }
}
}

context("아이가 존재하지 않는 경우") {
val userId = UuidCreator.create()
every { babyManagerServiceMock.getBabyByIdAndUserIsAdmin(userId, baby.id) } throws BusinessException(BabyError.BABY_NOT_FOUND)

val result = shouldThrow<BusinessException> { sut.deleteById(userId, baby.id) }

result.errorCode shouldBe BabyError.BABY_NOT_FOUND
result.message shouldBe BabyError.BABY_NOT_FOUND.message
}
}
}) {
companion object {
val baby = Baby(
Expand Down

0 comments on commit 4f5c026

Please sign in to comment.