Untitled
unknown
plain_text
a year ago
5.0 kB
2
Indexable
Never
package com.vidio.kmm.api import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import org.koin.core.context.stopKoin import org.koin.test.KoinTest import org.koin.test.get import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertNotEquals import kotlin.test.assertNotNull import kotlin.test.assertTrue class GetSearchIntegrationTest : KoinTest { private val mutex = Mutex() private val origin = "https://api.staging.vidio.com" @BeforeTest fun setup() = kotlinx.coroutines.test.runTest { mutex.withLock { VidioApiTestFixture.initialize() } } @AfterTest fun tearDown() = stopKoin() @Test fun search_index_with_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val searchSection = getSearch.getSearchIndex(keyword = "sctv") assertTrue(searchSection.sections.isNotEmpty()) assertNotEquals("-1", searchSection.sections.first().id) assertNotNull(searchSection.sections.first().contents) assertNotNull(searchSection.meta) } } @Test fun search_index_without_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val searchSection = getSearch.getSearchIndex(keyword = "zxcvbnm") assertTrue(searchSection.sections.isEmpty()) } } @Test fun search_lives_with_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/lives?q=sctv" val result = getSearch.getSearchLives(url) assertTrue(result.livestreamings.isNotEmpty()) assertNotEquals("-1", result.livestreamings.first().id) } } @Test fun search_lives_pagination_with_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/lives?q=sctv&page=1&per_page=1" val result = getSearch.getSearchLives(url) assertTrue(result.livestreamings.isNotEmpty()) assertNotNull(result.links?.next) } } @Test fun search_lives_without_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/lives?q=zxcvbnm" val result = getSearch.getSearchLives(url) assertTrue(result.livestreamings.isEmpty()) } } @Test fun search_video_with_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/videos?q=sarahnb" val result = getSearch.getSearchVideo(url) assertTrue(result.videos.isNotEmpty()) assertNotEquals("-1", result.videos.first().id) } } @Test fun search_video_pagination_with_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/videos?q=gundala&page=1&per_page=10" val result = getSearch.getSearchVideo(url) assertTrue(result.videos.isNotEmpty()) assertNotNull(result.links?.next) } } @Test fun search_video_without_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/videos?q=zxcvbnm" val result = getSearch.getSearchVideo(url) assertTrue(result.videos.isEmpty()) } } @Test fun search_film_with_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/films?q=gundala" val result = getSearch.getSearchFilm(url) assertNotEquals("-1", result.films[0].id) assertTrue(result.films.isNotEmpty()) } } @Test fun search_film_pagination_with_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/films?q=cinta&page=1&per_page=10" val result = getSearch.getSearchFilm(url) assertTrue(result.films.isNotEmpty()) assertNotEquals("-1", result.films[0].id) assertTrue(result.links?.next?.isNotEmpty() ?: false) } } @Test fun search_film_without_result() = kotlinx.coroutines.test.runTest { mutex.withLock { val getSearch: GetSearch = get() val url = "$origin/search/films?q=zxcvbnm" val result = getSearch.getSearchFilm(url) assertTrue(result.films.isEmpty()) } } }