From ee5e8f8dfbc83d25c69898030960d94136605293 Mon Sep 17 00:00:00 2001 From: Gabi Moreno Date: Tue, 5 Dec 2023 08:54:16 +0100 Subject: [PATCH] Add support for premium audios inside podcast posts one the web --- .../gabimoreno/domain/util/ExtractMp3Url.kt | 12 ++-- .../domain/util/ExtractMp3UrlKtTest.kt | 55 +++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/gabimoreno/src/main/java/soy/gabimoreno/domain/util/ExtractMp3Url.kt b/gabimoreno/src/main/java/soy/gabimoreno/domain/util/ExtractMp3Url.kt index af43798..315ec3d 100644 --- a/gabimoreno/src/main/java/soy/gabimoreno/domain/util/ExtractMp3Url.kt +++ b/gabimoreno/src/main/java/soy/gabimoreno/domain/util/ExtractMp3Url.kt @@ -1,17 +1,17 @@ package soy.gabimoreno.domain.util -import androidx.annotation.VisibleForTesting - fun String.extractMp3Url(): String? { val startIndex = indexOf(PREFIX) val suffix = SUFFIX val suffixLength = suffix.length - val endIndex = indexOf(suffix) + suffixLength + var endIndex = indexOf(suffix) + suffixLength + if (endIndex <= startIndex) { + endIndex += substring(endIndex, length).indexOf(suffix) + suffixLength + } if (startIndex == -1 || endIndex == suffixLength - 1) return null return substring(startIndex, endIndex) } -@VisibleForTesting -internal const val PREFIX = "https://gabimoreno.soy/wp-content/uploads/" -internal const val SUFFIX = ".mp3" +private const val PREFIX = "https://gabimoreno.soy/wp-content/uploads/" +private const val SUFFIX = ".mp3" diff --git a/gabimoreno/src/test/java/soy/gabimoreno/domain/util/ExtractMp3UrlKtTest.kt b/gabimoreno/src/test/java/soy/gabimoreno/domain/util/ExtractMp3UrlKtTest.kt index b8d78b0..03e60ac 100644 --- a/gabimoreno/src/test/java/soy/gabimoreno/domain/util/ExtractMp3UrlKtTest.kt +++ b/gabimoreno/src/test/java/soy/gabimoreno/domain/util/ExtractMp3UrlKtTest.kt @@ -57,7 +57,62 @@ class ExtractMp3UrlKtTest { result shouldBeEqualTo MP3_URL } + + @Test + fun `GIVEN a content with another MP3 url before WHEN call THEN get the expected mp3 url`() { + val rendered = "
\n" + + "\n" + + "

Episodio 150 – Domina el UI Testing en ANDROID con estos tips

\n" + + "\n" + + "\n" + + "\n" + + "

En esta charla técnica, exploraremos el fascinante mundo del UI Testing en Android con Sergio Sastre.

\n" + + "\n" + + "\n" + + "\n" + + "

¿Alguna vez te has preguntado cómo asegurar que las interfaces de usuario (UI) en tus apps Android funcionen a la perfección? Aquí está tu respuesta.

\n" + + "\n" + + "\n" + + "\n" + + "

¿Viste ya la entrevista a XurxoDev?

\n" + + "\n" + + "\n" + + "\n" + + "
\n" + + "\n" + + "
\n" + + "\n" + + "\n" + + "\n" + + "
\n" + + "\n" + + "\n" + + "\n" + + "
\n" + + "\n" + + "\n" + + "\n" + + "

Podcast Premium

\n" + + "\n" + + "\n" + + "\n" + + "
\n" + + "
" + + val result = rendered.extractMp3Url() + + result shouldBeEqualTo MP3_URL + } } +private const val PREFIX = "https://gabimoreno.soy/wp-content/uploads/" +internal const val OTHER_PREFIX = "https://foo/" + private const val MP3_URL = "${PREFIX}GABI-MORENO-Premium-sample.mp3" + +private const val OTHER_MP3_URL = + "${OTHER_PREFIX}foo.mp3"