Skip to content

Commit

Permalink
test: article 조회수 추가 관련 test 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hun-ca committed Jul 17, 2024
1 parent 1334ccf commit 390b898
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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<ArticleDao>()
readArticleWriterRecordService = mockk<ReadArticleWriterRecordService>()
browseArticleProblemsService = mockk<BrowseArticleProblemsService>()
useCase = ReadArticleUseCase(articleDao, readArticleWriterRecordService, browseArticleProblemsService)
articleViewHisService = mockk<ArticleViewHisService>()
useCase = ReadArticleUseCase(
articleDao,
readArticleWriterRecordService,
browseArticleProblemsService,
articleViewHisService
)
}

given("아티클 조회 요청이 온 상황에서") {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)
)

Expand Down Expand Up @@ -119,7 +121,9 @@ class ArticleControllerTest : ControllerTestSpec() {
PayloadDocumentation.fieldWithPath("data.category")
.fieldWithString("아티클 카테고리"),
PayloadDocumentation.fieldWithPath("data.createdAt")
.fieldWithString("아티클 생성일")
.fieldWithString("아티클 생성일"),
PayloadDocumentation.fieldWithPath("data.views")
.fieldWithString("아티클 조회수")
)
)
).build()
Expand Down

0 comments on commit 390b898

Please sign in to comment.