|
|
|
|
@@ -0,0 +1,102 @@
|
|
|
|
|
package kr.co.vividnext.sodalive.v2.api.audio.recommendation.adapter.`in`.web
|
|
|
|
|
|
|
|
|
|
import kr.co.vividnext.sodalive.common.CountryContext
|
|
|
|
|
import kr.co.vividnext.sodalive.configs.SecurityConfig
|
|
|
|
|
import kr.co.vividnext.sodalive.i18n.LangContext
|
|
|
|
|
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
|
|
|
|
import kr.co.vividnext.sodalive.jwt.JwtAccessDeniedHandler
|
|
|
|
|
import kr.co.vividnext.sodalive.jwt.JwtAuthenticationEntryPoint
|
|
|
|
|
import kr.co.vividnext.sodalive.jwt.TokenProvider
|
|
|
|
|
import kr.co.vividnext.sodalive.member.Member
|
|
|
|
|
import kr.co.vividnext.sodalive.member.MemberAdapter
|
|
|
|
|
import kr.co.vividnext.sodalive.member.MemberRole
|
|
|
|
|
import kr.co.vividnext.sodalive.v2.api.audio.recommendation.application.AudioRecommendationFacade
|
|
|
|
|
import kr.co.vividnext.sodalive.v2.api.audio.recommendation.dto.AudioRecommendationsResponse
|
|
|
|
|
import org.junit.jupiter.api.DisplayName
|
|
|
|
|
import org.junit.jupiter.api.Test
|
|
|
|
|
import org.mockito.Mockito
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
|
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
|
|
|
|
import org.springframework.boot.test.mock.mockito.MockBean
|
|
|
|
|
import org.springframework.context.annotation.Import
|
|
|
|
|
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user
|
|
|
|
|
import org.springframework.test.web.servlet.MockMvc
|
|
|
|
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
|
|
|
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
|
|
|
|
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
|
|
|
|
|
|
|
|
|
|
@WebMvcTest(AudioRecommendationController::class)
|
|
|
|
|
@Import(SecurityConfig::class)
|
|
|
|
|
class AudioRecommendationControllerTest @Autowired constructor(
|
|
|
|
|
private val mockMvc: MockMvc
|
|
|
|
|
) {
|
|
|
|
|
@MockBean
|
|
|
|
|
private lateinit var facade: AudioRecommendationFacade
|
|
|
|
|
|
|
|
|
|
@MockBean
|
|
|
|
|
private lateinit var countryContext: CountryContext
|
|
|
|
|
|
|
|
|
|
@MockBean
|
|
|
|
|
private lateinit var langContext: LangContext
|
|
|
|
|
|
|
|
|
|
@MockBean
|
|
|
|
|
private lateinit var sodaMessageSource: SodaMessageSource
|
|
|
|
|
|
|
|
|
|
@MockBean
|
|
|
|
|
private lateinit var tokenProvider: TokenProvider
|
|
|
|
|
|
|
|
|
|
@MockBean
|
|
|
|
|
private lateinit var accessDeniedHandler: JwtAccessDeniedHandler
|
|
|
|
|
|
|
|
|
|
@MockBean
|
|
|
|
|
private lateinit var authenticationEntryPoint: JwtAuthenticationEntryPoint
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("오디오 추천 조회는 비회원에게 200 OK와 ApiResponse.ok wrapper를 반환한다")
|
|
|
|
|
fun shouldReturnRecommendationsForAnonymous() {
|
|
|
|
|
Mockito.doReturn(emptyResponse()).`when`(facade).getRecommendations(null)
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(get("/api/v2/audio/recommendations"))
|
|
|
|
|
.andExpect(status().isOk)
|
|
|
|
|
.andExpect(jsonPath("$.success").value(true))
|
|
|
|
|
.andExpect(jsonPath("$.data.banners").isArray)
|
|
|
|
|
.andExpect(jsonPath("$.data.originalSeries").isArray)
|
|
|
|
|
.andExpect(jsonPath("$.data.latestAudios").isArray)
|
|
|
|
|
.andExpect(jsonPath("$.data.recommendedAudios").isArray)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("오디오 추천 조회는 인증 회원을 nullable member로 facade에 전달한다")
|
|
|
|
|
fun shouldPassAuthenticatedMemberToFacade() {
|
|
|
|
|
val member = Member(
|
|
|
|
|
email = "viewer@test.com",
|
|
|
|
|
password = "password",
|
|
|
|
|
nickname = "viewer",
|
|
|
|
|
role = MemberRole.USER
|
|
|
|
|
).apply { id = 10L }
|
|
|
|
|
Mockito.doReturn(emptyResponse()).`when`(facade).getRecommendations(eqValue(member))
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(get("/api/v2/audio/recommendations").with(user(MemberAdapter(member))))
|
|
|
|
|
.andExpect(status().isOk)
|
|
|
|
|
.andExpect(jsonPath("$.success").value(true))
|
|
|
|
|
|
|
|
|
|
Mockito.verify(facade).getRecommendations(eqValue(member))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun emptyResponse(): AudioRecommendationsResponse {
|
|
|
|
|
return AudioRecommendationsResponse(
|
|
|
|
|
banners = emptyList(),
|
|
|
|
|
originalSeries = emptyList(),
|
|
|
|
|
latestAudios = emptyList(),
|
|
|
|
|
newAndHotAudios = emptyList(),
|
|
|
|
|
freeAudios = emptyList(),
|
|
|
|
|
pointAudios = emptyList(),
|
|
|
|
|
mostCommentedAudios = emptyList(),
|
|
|
|
|
recommendedAudios = emptyList()
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun <T> eqValue(value: T): T {
|
|
|
|
|
return Mockito.eq(value) ?: value
|
|
|
|
|
}
|
|
|
|
|
}
|