Handle empty lucky number response
This commit is contained in:
parent
1671abc5d4
commit
add02779fa
3 changed files with 28 additions and 1 deletions
|
@ -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() }
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"data": [
|
||||
{
|
||||
"IkonkaNazwa": null,
|
||||
"Num": null,
|
||||
"Zawartosc": [],
|
||||
"Nazwa": "",
|
||||
"Url": null,
|
||||
"Symbol": null,
|
||||
"Nieaktywny": false
|
||||
}
|
||||
],
|
||||
"success": true,
|
||||
"errorMessage": null,
|
||||
"feedback": null
|
||||
}
|
Loading…
Reference in a new issue