Implement URL input format checks

This commit is contained in:
Kirill Kamakin
2021-11-27 12:27:25 +03:00
parent ebba1889c7
commit 339f8327de
6 changed files with 52 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ package gq.kirmanak.mealient.data.auth.impl
import com.google.common.truth.Truth.assertThat
import dagger.hilt.android.testing.HiltAndroidTest
import gq.kirmanak.mealient.data.auth.impl.AuthenticationError.MalformedUrl
import gq.kirmanak.mealient.data.auth.impl.AuthenticationError.Unauthorized
import gq.kirmanak.mealient.test.AuthImplTestData.TEST_PASSWORD
import gq.kirmanak.mealient.test.AuthImplTestData.TEST_TOKEN
@@ -50,4 +51,29 @@ class AuthRepoImplTest : MockServerTest() {
subject.authenticate(TEST_USERNAME, TEST_PASSWORD, serverUrl)
assertThat(subject.getBaseUrl()).isEqualTo(serverUrl)
}
@Test(expected = MalformedUrl::class)
fun `when baseUrl has ftp scheme then throws`() {
subject.parseBaseUrl("ftp://test")
}
@Test
fun `when baseUrl scheme has one slash then corrects`() {
assertThat(subject.parseBaseUrl("https:/test")).isEqualTo("https://test/")
}
@Test
fun `when baseUrl is single word then appends scheme and slash`() {
assertThat(subject.parseBaseUrl("test")).isEqualTo("https://test/")
}
@Test
fun `when baseUrl is host appends scheme and slash`() {
assertThat(subject.parseBaseUrl("google.com")).isEqualTo("https://google.com/")
}
@Test
fun `when baseUrl is correct then doesn't change`() {
assertThat(subject.parseBaseUrl("https://google.com/")).isEqualTo("https://google.com/")
}
}