Skip to content

Commit

Permalink
Merge pull request #96 from Bhyan/parseEpisodeDetailsTest
Browse files Browse the repository at this point in the history
- Test parseEpisodeDetails tests added
  • Loading branch information
justdvnsh authored Oct 25, 2021
2 parents 3875809 + d939cf3 commit b6ad82a
Show file tree
Hide file tree
Showing 2 changed files with 1,830 additions and 10 deletions.
91 changes: 81 additions & 10 deletions domain/src/test/java/kitefoundation/tech/domain/utils/ParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import divyansh.tech.animeclassroom.ResultWrapper.Success
import divyansh.tech.animeclassroom.models.home.AnimeDetailModel
import divyansh.tech.animeclassroom.models.home.AnimeModel
import divyansh.tech.animeclassroom.models.home.GenreModel
import divyansh.tech.animeclassroom.models.home.PlayerScreenModel
import divyansh.tech.animeclassroom.utils.Parser.parseAnimeDetails
import divyansh.tech.animeclassroom.utils.Parser.parseEpisodeDetails
import divyansh.tech.animeclassroom.utils.Parser.parseGenresAnimeJson
import divyansh.tech.animeclassroom.utils.Parser.parsePopularAnimeJson
import divyansh.tech.animeclassroom.utils.Parser.parseRecentReleaseJson
Expand Down Expand Up @@ -53,15 +55,21 @@ class ParserTest {
assertEquals(response.data?.size, 2)

assertEquals(response.data?.first()?.name, "Jujutsu Kaisen (TV)")
assertEquals(response.data?.first()?.imageUrl, "https://gogocdn.net/cover/jujutsu-kaisen-tv.png")
assertEquals(
response.data?.first()?.imageUrl,
"https://gogocdn.net/cover/jujutsu-kaisen-tv.png"
)
assertEquals(response.data?.first()?.releaseDate, "2020")
assertEquals(response.data?.first()?.animeUrl, "/category/jujutsu-kaisen-tv")
assertNull(response.data?.first()?.episodeUrl)
assertNull(response.data?.first()?.episodeNumber)
assertNull(response.data?.first()?.genre)

assertEquals(response.data?.last()?.name, "Jujutsu Kaisen (TV) (Dub)")
assertEquals(response.data?.last()?.imageUrl, "https://gogocdn.net/cover/jujutsu-kaisen-tv-dub.png")
assertEquals(
response.data?.last()?.imageUrl,
"https://gogocdn.net/cover/jujutsu-kaisen-tv-dub.png"
)
assertEquals(response.data?.last()?.releaseDate, "2020")
assertEquals(response.data?.last()?.animeUrl, "/category/jujutsu-kaisen-tv-dub")
assertNull(response.data?.last()?.episodeUrl)
Expand Down Expand Up @@ -93,20 +101,44 @@ class ParserTest {

assertEquals((response.data as ArrayList<*>).size, 60)

assertEquals(((response.data as ArrayList<*>).first() as AnimeModel).name, "Assault Lily: Fruits")
assertEquals(((response.data as ArrayList<*>).first() as AnimeModel).imageUrl, "https://gogocdn.net/cover/assault-lily-fruits.png")
assertEquals(
((response.data as ArrayList<*>).first() as AnimeModel).name,
"Assault Lily: Fruits"
)
assertEquals(
((response.data as ArrayList<*>).first() as AnimeModel).imageUrl,
"https://gogocdn.net/cover/assault-lily-fruits.png"
)
assertNull(((response.data as ArrayList<*>).first() as AnimeModel).releaseDate)
assertNull(((response.data as ArrayList<*>).first() as AnimeModel).animeUrl)
assertEquals(((response.data as ArrayList<*>).first() as AnimeModel).episodeUrl, "/assault-lily-fruits-episode-7")
assertEquals(((response.data as ArrayList<*>).first() as AnimeModel).episodeNumber, "Episode 7")
assertEquals(
((response.data as ArrayList<*>).first() as AnimeModel).episodeUrl,
"/assault-lily-fruits-episode-7"
)
assertEquals(
((response.data as ArrayList<*>).first() as AnimeModel).episodeNumber,
"Episode 7"
)
assertNull(((response.data as ArrayList<*>).first() as AnimeModel).genre)

assertEquals(((response.data as ArrayList<*>).last() as AnimeModel).name, "Yu☆Gi☆Oh!: Sevens")
assertEquals(((response.data as ArrayList<*>).last() as AnimeModel).imageUrl, "https://gogocdn.net/cover/yugioh-sevens.png")
assertEquals(
((response.data as ArrayList<*>).last() as AnimeModel).name,
"Yu☆Gi☆Oh!: Sevens"
)
assertEquals(
((response.data as ArrayList<*>).last() as AnimeModel).imageUrl,
"https://gogocdn.net/cover/yugioh-sevens.png"
)
assertNull(((response.data as ArrayList<*>).last() as AnimeModel).releaseDate)
assertNull(((response.data as ArrayList<*>).last() as AnimeModel).animeUrl)
assertEquals(((response.data as ArrayList<*>).last() as AnimeModel).episodeUrl, "/yugioh-sevens-episode-69")
assertEquals(((response.data as ArrayList<*>).last() as AnimeModel).episodeNumber, "Episode 69")
assertEquals(
((response.data as ArrayList<*>).last() as AnimeModel).episodeUrl,
"/yugioh-sevens-episode-69"
)
assertEquals(
((response.data as ArrayList<*>).last() as AnimeModel).episodeNumber,
"Episode 69"
)
assertNull(((response.data as ArrayList<*>).last() as AnimeModel).genre)
}

Expand All @@ -128,12 +160,17 @@ class ParserTest {
}

@Test

fun parseGenresAnimeJsonTest(): Unit = runBlocking {
val html = FileUtil.readFileFromResources("popularAnime.html")
val response = html.let { parseGenresAnimeJson(it) }

assertEquals((response.data as ArrayList<*>).size, 48)
assertEquals(((response.data as ArrayList<*>).first() as GenreModel).genreTitle, "Action")
assertEquals(
((response.data as ArrayList<*>).first() as GenreModel).genreUrl,
"/genre/action"
)
assertEquals(((response.data as ArrayList<*>).first() as GenreModel).genreUrl, "/genre/action")
assertEquals(((response.data as ArrayList<*>).last() as GenreModel).genreTitle, "Yuri")
assertEquals(((response.data as ArrayList<*>).last() as GenreModel).genreUrl, "/genre/yuri")
Expand All @@ -156,6 +193,40 @@ class ParserTest {
assertEquals(response.message, "Index 0 out of bounds for length 0")
}

@Test
fun parseEpisodeDetailsTest(): Unit = runBlocking {
val html = FileUtil.readFileFromResources("episodeDetails.html")
val response = html.let { parseEpisodeDetails(it) }

assertEquals(
(response.data as PlayerScreenModel).animeName,
"Boruto: Naruto Next Generations Episode 1 English Subbed"
)
assertEquals(
(response.data as PlayerScreenModel).streamingUrl,
"https://gogoplay1.com/embedplus?id=OTc2MzI=&token=ZRzkyD8ewZngaN3RModR3g&expires=1635031246"
)
assertNull((response.data as PlayerScreenModel).mirrorLinks)
assertEquals(
(response.data as PlayerScreenModel).nextEpisodeUrl,
"/boruto-naruto-next-generations-episode-2"
)
assertEquals((response.data as PlayerScreenModel).previousEpisodeUrl, "null")

}

@Test
fun parseEpisodeDetailsEmptyTest(): Unit = runBlocking {
val html = ""
val response = html.let { parseEpisodeDetails(it) }

assertEquals((response.data as PlayerScreenModel).animeName, "null")
assertEquals((response.data as PlayerScreenModel).streamingUrl, "https:null")
assertNull((response.data as PlayerScreenModel).mirrorLinks)
assertEquals((response.data as PlayerScreenModel).nextEpisodeUrl, "null")
assertEquals((response.data as PlayerScreenModel).previousEpisodeUrl, "null")
}

object FileUtil {
@Throws(IOException::class)
fun readFileFromResources(fileName: String): String {
Expand Down
Loading

0 comments on commit b6ad82a

Please sign in to comment.