Last active
November 27, 2017 10:59
-
-
Save txusballesteros/4e38556a96f71b625f4a9a17ca5d48cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias getNowPlayingMoviesFromCloud = () -> ReaderT<IdHK, Kodein, Try<List<MovieDataModel>>> | |
val getNowPlayingMoviesFromCloudImpl: getNowPlayingMoviesFromCloud by lazy {{ | |
Reader.ask<Kodein>().flatMap { context -> | |
val request: requestNowPlayingMoviesToBackend = context.instance() | |
request().map { response -> | |
response.map { it.movies.map(::mapToData) } | |
} | |
} | |
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NowPlayingCloudDataSourceTest : UnitTest() { | |
companion object { | |
private const val PAGE = 123 | |
private val MODEL = MovieApiModel( | |
1, | |
"originalTitle", | |
"en", | |
"title", | |
"overview", | |
"2017-08-23", | |
true, | |
"backdrop", | |
"poster", | |
1, | |
5.5f) | |
} | |
private val testContext = Kodein { | |
bind<requestNowPlayingMoviesToBackend>() with provider {{ | |
Reader.ask<Kodein>().map({ | |
Try { NowPlayingResponse(PAGE, listOf(MODEL)) } | |
}) | |
}} | |
} | |
@Test | |
fun shouldGetNowPlayingMoviesFromCloudDataSource() { | |
val datasource: getNowPlayingMoviesFromCloud = getNowPlayingMoviesFromCloudImpl | |
datasource().run(testContext).flatMap { | |
it.fold({ | |
throw RuntimeException(it) | |
}, { | |
with(it.first()) { | |
Assert.assertEquals(MODEL.id, id) | |
} | |
}) | |
it | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment