Handle empty lucky number response

This commit is contained in:
Mikołaj Pich 2019-08-12 22:33:12 +02:00
parent 1671abc5d4
commit add02779fa
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
3 changed files with 28 additions and 1 deletions

View file

@ -64,7 +64,9 @@ class HomepageRepository(private val api: HomepageService) {
@Deprecated("Deprecated due to VULCAN homepage update 19.06", ReplaceWith("getKidsLuckyNumbers()"))
fun getLuckyNumber(): Maybe<Int> {
return api.getKidsLuckyNumbers().compose(ErrorHandlerTransformer()).map { it.data }
.map { it[0].content[0].name }
.map { it[0].content }
.filter { it.isNotEmpty() }
.map { it[0].name }
.filter { it.isNotBlank() }
.map { it.substringAfterLast(": ").toInt() }
}

View file

@ -78,4 +78,13 @@ class HomepageTest : BaseLocalTest() {
val number = repo.getLuckyNumber().blockingGet()
assertEquals(18, number)
}
@Test
fun getLuckyNumber_empty() {
server.enqueue(MockResponse().setBody(HomepageTest::class.java.getResource("GetEmpty.json").readText()))
server.start(3000)
val number = repo.getLuckyNumber().blockingGet()
assertEquals(null, number)
}
}

View file

@ -0,0 +1,16 @@
{
"data": [
{
"IkonkaNazwa": null,
"Num": null,
"Zawartosc": [],
"Nazwa": "",
"Url": null,
"Symbol": null,
"Nieaktywny": false
}
],
"success": true,
"errorMessage": null,
"feedback": null
}