From e5a47ac17a51580c7608c93e349af8d3391616b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9D=B8=EC=A4=80?= <54973090+dlswns2480@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:53:29 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95=20(#173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pokit/alert/port/service/AlertServiceTest.kt | 10 +++++++++- .../pokit/auth/port/service/AuthServiceTest.kt | 3 +++ .../content/port/service/ContentServiceTest.kt | 16 ++++++++++++++-- .../pokit/user/port/service/UserServiceTest.kt | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/application/src/test/kotlin/com/pokit/alert/port/service/AlertServiceTest.kt b/application/src/test/kotlin/com/pokit/alert/port/service/AlertServiceTest.kt index f94fcc88..b2d3b582 100644 --- a/application/src/test/kotlin/com/pokit/alert/port/service/AlertServiceTest.kt +++ b/application/src/test/kotlin/com/pokit/alert/port/service/AlertServiceTest.kt @@ -2,8 +2,12 @@ package com.pokit.alert.port.service import com.pokit.alert.AlertFixure import com.pokit.alert.port.out.AlertBatchPort +import com.pokit.alert.port.out.AlertContentPort import com.pokit.alert.port.out.AlertPort +import com.pokit.alert.port.out.AlertSender +import com.pokit.content.port.out.ContentPort import com.pokit.user.UserFixture +import com.pokit.user.port.out.FcmTokenPort import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe import io.mockk.every @@ -17,7 +21,11 @@ class AlertServiceTest : BehaviorSpec({ val alertPort = mockk() val now = mockk>() val alertBatchPort = mockk() - val alertService = AlertService(now, alertPort, alertBatchPort) + val alertSender = mockk() + val fcmTokenPort = mockk() + val alertContentPort = mockk() + val contentPort = mockk() + val alertService = AlertService(now, alertPort, alertBatchPort, alertSender, fcmTokenPort, alertContentPort, contentPort) Given("알림 관련 요청이 들어올 때") { val nowTime = LocalDateTime.of(2024, 8, 15, 15, 30) diff --git a/application/src/test/kotlin/com/pokit/auth/port/service/AuthServiceTest.kt b/application/src/test/kotlin/com/pokit/auth/port/service/AuthServiceTest.kt index 7306eef6..6c354a27 100644 --- a/application/src/test/kotlin/com/pokit/auth/port/service/AuthServiceTest.kt +++ b/application/src/test/kotlin/com/pokit/auth/port/service/AuthServiceTest.kt @@ -41,6 +41,9 @@ class AuthServiceTest : BehaviorSpec({ every { tokenProvider.createToken(user.id) } returns token every { tokenProvider.getUserId("refresh") } returns user.id every { tokenProvider.reissueToken(user.id, "refresh") } returns reissueResult + every { + userPort.loadBySubAndAuthPlatform(userInfo.sub, AuthPlatform.of(request.authPlatform)) + } returns user When("로그인할 때 구글 플랫폼으로 올바른 인증코드로 요청하면") { val resultToken = authService.signIn(request) diff --git a/application/src/test/kotlin/com/pokit/content/port/service/ContentServiceTest.kt b/application/src/test/kotlin/com/pokit/content/port/service/ContentServiceTest.kt index 07b28b47..d80673c6 100644 --- a/application/src/test/kotlin/com/pokit/content/port/service/ContentServiceTest.kt +++ b/application/src/test/kotlin/com/pokit/content/port/service/ContentServiceTest.kt @@ -1,6 +1,8 @@ package com.pokit.content.port.service +import com.pokit.alert.model.CreateAlertRequest import com.pokit.bookmark.BookmarkFixture +import com.pokit.bookmark.model.Bookmark import com.pokit.bookmark.port.out.BookmarkPort import com.pokit.category.CategoryFixture import com.pokit.category.port.out.CategoryPort @@ -8,6 +10,7 @@ import com.pokit.common.exception.NotFoundCustomException import com.pokit.content.ContentFixture import com.pokit.content.dto.request.toDomain import com.pokit.content.model.Content +import com.pokit.content.port.out.ContentCountPort import com.pokit.content.port.out.ContentPort import com.pokit.log.port.out.UserLogPort import com.pokit.user.UserFixture @@ -15,14 +18,18 @@ import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe import io.mockk.every +import io.mockk.justRun import io.mockk.mockk +import org.springframework.context.ApplicationEventPublisher class ContentServiceTest : BehaviorSpec({ val contentPort = mockk() val bookmarkPort = mockk() val categoryPort = mockk() val userLogPort = mockk() - val contentService = ContentService(contentPort, bookmarkPort, categoryPort, userLogPort) + val publisher = mockk() + val contentCountPort = mockk() + val contentService = ContentService(contentPort, bookmarkPort, categoryPort, userLogPort, publisher, contentCountPort) Given("컨텐츠에 대해 즐겨찾기 할 때") { val user = UserFixture.getUser() @@ -33,7 +40,8 @@ class ContentServiceTest : BehaviorSpec({ every { contentPort.loadByUserIdAndId(user.id, requestContentId) } returns content every { contentPort.loadByUserIdAndId(user.id, invalidContentId) } returns null - every { bookmarkPort.persist(bookmark) } returns bookmark + every { bookmarkPort.persist(any(Bookmark::class)) } returns bookmark + every { bookmarkPort.loadByContentIdAndUserId(requestContentId, user.id) } returns null When("존재하지 않는 컨텐츠면") { Then("예외가 발생한다.") { @@ -88,6 +96,10 @@ class ContentServiceTest : BehaviorSpec({ bookmarkPort.isBookmarked(content.id, user.id) } returns true + every { + publisher.publishEvent(any(CreateAlertRequest::class)) + } returns Unit + When("저장 요청이 들어오면") { val content = contentService.create(user, command) Then("저장 후 저장 된 컨텐츠를 반환한다.") { diff --git a/application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt b/application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt index 6efb981c..884ed56e 100644 --- a/application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt +++ b/application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt @@ -28,7 +28,7 @@ class UserServiceTest : BehaviorSpec({ val user = UserFixture.getUser() val invalidUser = UserFixture.getInvalidUser() val request = UserFixture.getSignUpRequest() - val modifieUser = User(user.id, user.email, user.role, request.nickName, AuthPlatform.GOOGLE) + val modifieUser = User(user.id, user.email, user.role, request.nickName, AuthPlatform.GOOGLE, sub = "sub") val image = CategoryImage(1, "https://www.image.com") val unCategorized = CategoryFixture.getUnCategorized(user.id, image)