diff --git a/api/src/test/kotlin/com/few/api/domain/article/usecase/ReadArticleUseCaseTest.kt b/api/src/test/kotlin/com/few/api/domain/article/usecase/ReadArticleUseCaseTest.kt index 914fa4812..95674fce7 100644 --- a/api/src/test/kotlin/com/few/api/domain/article/usecase/ReadArticleUseCaseTest.kt +++ b/api/src/test/kotlin/com/few/api/domain/article/usecase/ReadArticleUseCaseTest.kt @@ -1,5 +1,6 @@ package com.few.api.domain.article.usecase +import com.few.api.domain.article.service.ArticleViewHisService import com.few.api.domain.article.service.BrowseArticleProblemsService import com.few.api.domain.article.service.ReadArticleWriterRecordService import com.few.api.domain.article.service.dto.BrowseArticleProblemsOutDto @@ -9,9 +10,7 @@ import com.few.api.repo.dao.article.ArticleDao import com.few.api.repo.dao.article.record.SelectArticleRecord import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.BehaviorSpec -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify +import io.mockk.* import java.net.URL import java.time.LocalDateTime @@ -22,13 +21,20 @@ class ReadArticleUseCaseTest : BehaviorSpec({ lateinit var readArticleWriterRecordService: ReadArticleWriterRecordService lateinit var browseArticleProblemsService: BrowseArticleProblemsService lateinit var useCase: ReadArticleUseCase - val useCaseIn = ReadArticleUseCaseIn(articleId = 1L) + lateinit var articleViewHisService: ArticleViewHisService + val useCaseIn = ReadArticleUseCaseIn(articleId = 1L, memberId = 1L) beforeContainer { articleDao = mockk() readArticleWriterRecordService = mockk() browseArticleProblemsService = mockk() - useCase = ReadArticleUseCase(articleDao, readArticleWriterRecordService, browseArticleProblemsService) + articleViewHisService = mockk() + useCase = ReadArticleUseCase( + articleDao, + readArticleWriterRecordService, + browseArticleProblemsService, + articleViewHisService + ) } given("아티클 조회 요청이 온 상황에서") { @@ -52,6 +58,8 @@ class ReadArticleUseCaseTest : BehaviorSpec({ every { articleDao.selectArticleRecord(any()) } returns record every { readArticleWriterRecordService.execute(any()) } returns writerSvcOutDto every { browseArticleProblemsService.execute(any()) } returns probSvcOutDto + every { articleViewHisService.addArticleViewHis(any()) } just Runs + every { articleViewHisService.readArticleViews(any()) } returns 1L then("아티클이 정상 조회된다") { useCase.execute(useCaseIn) diff --git a/api/src/test/kotlin/com/few/api/web/controller/article/ArticleControllerTest.kt b/api/src/test/kotlin/com/few/api/web/controller/article/ArticleControllerTest.kt index f545f9f13..7d572acdb 100644 --- a/api/src/test/kotlin/com/few/api/web/controller/article/ArticleControllerTest.kt +++ b/api/src/test/kotlin/com/few/api/web/controller/article/ArticleControllerTest.kt @@ -69,7 +69,8 @@ class ArticleControllerTest : ControllerTestSpec() { val uri = UriComponentsBuilder.newInstance().path("$BASE_URL/{articleId}").build().toUriString() // set usecase mock val articleId = 1L - `when`(readArticleUseCase.execute(ReadArticleUseCaseIn(articleId))).thenReturn( + val memberId = 1L + `when`(readArticleUseCase.execute(ReadArticleUseCaseIn(articleId, memberId))).thenReturn( ReadArticleUseCaseOut( id = 1L, writer = WriterDetail( @@ -81,7 +82,8 @@ class ArticleControllerTest : ControllerTestSpec() { content = CategoryType.fromCode(0)!!.name, problemIds = listOf(1L, 2L, 3L), category = "경제", - createdAt = LocalDateTime.now() + createdAt = LocalDateTime.now(), + views = 1L ) ) @@ -119,7 +121,9 @@ class ArticleControllerTest : ControllerTestSpec() { PayloadDocumentation.fieldWithPath("data.category") .fieldWithString("아티클 카테고리"), PayloadDocumentation.fieldWithPath("data.createdAt") - .fieldWithString("아티클 생성일") + .fieldWithString("아티클 생성일"), + PayloadDocumentation.fieldWithPath("data.views") + .fieldWithString("아티클 조회수") ) ) ).build()