160 lines
5.1 KiB
Kotlin
160 lines
5.1 KiB
Kotlin
package kr.co.vividnext.sodalive.search
|
|
|
|
import kr.co.vividnext.sodalive.content.ContentType
|
|
import kr.co.vividnext.sodalive.member.Member
|
|
import org.junit.jupiter.api.Assertions.assertEquals
|
|
import org.junit.jupiter.api.DisplayName
|
|
import org.junit.jupiter.api.Test
|
|
import org.mockito.Mockito
|
|
|
|
class SearchServiceTest {
|
|
private val repository: SearchRepository = Mockito.mock(SearchRepository::class.java)
|
|
private val service = SearchService(repository)
|
|
|
|
@Test
|
|
@DisplayName("콘텐츠 검색은 전달받은 isAdult 값을 그대로 사용한다")
|
|
fun shouldUseProvidedIsAdultForContentSearch() {
|
|
val member = createMember(id = 101L, countryCode = "KR")
|
|
val contentItem = SearchResponseItem(
|
|
id = 10L,
|
|
imageUrl = "https://cdn.test/content.png",
|
|
title = "title",
|
|
nickname = "creator"
|
|
)
|
|
|
|
Mockito.`when`(
|
|
repository.searchContentTotalCount(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
isAdult = true,
|
|
contentType = ContentType.ALL
|
|
)
|
|
).thenReturn(1)
|
|
Mockito.`when`(
|
|
repository.searchContentList(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
isAdult = true,
|
|
contentType = ContentType.ALL,
|
|
offset = 0,
|
|
limit = 10
|
|
)
|
|
).thenReturn(listOf(contentItem))
|
|
|
|
val result = service.searchContentList(
|
|
keyword = "keyword",
|
|
isAdult = true,
|
|
contentType = ContentType.ALL,
|
|
member = member,
|
|
offset = 0,
|
|
limit = 10
|
|
)
|
|
|
|
assertEquals(1, result.totalCount)
|
|
assertEquals(SearchResponseType.CONTENT, result.items.first().type)
|
|
Mockito.verify(repository).searchContentTotalCount(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
isAdult = true,
|
|
contentType = ContentType.ALL
|
|
)
|
|
Mockito.verify(repository, Mockito.never()).searchContentTotalCount(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
isAdult = false,
|
|
contentType = ContentType.ALL
|
|
)
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("통합 검색은 전달받은 isAdult 값으로 콘텐츠/시리즈 조회를 수행한다")
|
|
fun shouldUseProvidedIsAdultForUnifiedSearch() {
|
|
val member = createMember(id = 102L, countryCode = "KR")
|
|
val creatorItem = SearchResponseItem(
|
|
id = 20L,
|
|
imageUrl = "https://cdn.test/creator.png",
|
|
title = "creator",
|
|
nickname = "creator"
|
|
)
|
|
val contentItem = SearchResponseItem(
|
|
id = 21L,
|
|
imageUrl = "https://cdn.test/content.png",
|
|
title = "content",
|
|
nickname = "creator"
|
|
)
|
|
val seriesItem = SearchResponseItem(
|
|
id = 22L,
|
|
imageUrl = "https://cdn.test/series.png",
|
|
title = "series",
|
|
nickname = "creator"
|
|
)
|
|
|
|
Mockito.`when`(
|
|
repository.searchCreatorList(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
offset = 0,
|
|
limit = 3
|
|
)
|
|
).thenReturn(listOf(creatorItem))
|
|
Mockito.`when`(
|
|
repository.searchContentList(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
isAdult = true,
|
|
contentType = ContentType.ALL,
|
|
offset = 0,
|
|
limit = 3
|
|
)
|
|
).thenReturn(listOf(contentItem))
|
|
Mockito.`when`(
|
|
repository.searchSeriesList(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
isAdult = true,
|
|
contentType = ContentType.ALL,
|
|
offset = 0,
|
|
limit = 3
|
|
)
|
|
).thenReturn(listOf(seriesItem))
|
|
|
|
val result = service.searchUnified(
|
|
keyword = "keyword",
|
|
isAdult = true,
|
|
contentType = ContentType.ALL,
|
|
member = member
|
|
)
|
|
|
|
assertEquals(SearchResponseType.CREATOR, result.creatorList.first().type)
|
|
assertEquals(SearchResponseType.CONTENT, result.contentList.first().type)
|
|
assertEquals(SearchResponseType.SERIES, result.seriesList.first().type)
|
|
Mockito.verify(repository).searchContentList(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
isAdult = true,
|
|
contentType = ContentType.ALL,
|
|
offset = 0,
|
|
limit = 3
|
|
)
|
|
Mockito.verify(repository).searchSeriesList(
|
|
keyword = "keyword",
|
|
memberId = member.id!!,
|
|
isAdult = true,
|
|
contentType = ContentType.ALL,
|
|
offset = 0,
|
|
limit = 3
|
|
)
|
|
}
|
|
|
|
private fun createMember(id: Long, countryCode: String?): Member {
|
|
return Member(
|
|
email = "member$id@test.com",
|
|
password = "password",
|
|
nickname = "member$id"
|
|
).apply {
|
|
this.id = id
|
|
this.countryCode = countryCode
|
|
}
|
|
}
|
|
}
|