Skip to content

Instantly share code, notes, and snippets.

@fievx
Created January 2, 2019 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fievx/bbe8eb70bb1fafe24d3bc7e64e651e57 to your computer and use it in GitHub Desktop.
Save fievx/bbe8eb70bb1fafe24d3bc7e64e651e57 to your computer and use it in GitHub Desktop.
class AuthenticationManagerTest : KoinTest{
@Before
fun initTest(){
loadKoinModules(listOf(module {
scope(TEST_SCOPE, override = true) { MockWebServer() }
factory (override = true){ AuthenticationManager(get<MockWebServer>().url("").toString()) }
}))
getKoin().createScope(TEST_SCOPE)
}
@After
fun shutdown(){
get<MockWebServer>().shutdown()
getKoin().getScope(TEST_SCOPE).close()
}
@Test
fun `authentication call populates login`(){
get<MockWebServer>().apply{
enqueue(MockResponse().setBody(MockResponseFileReader("login_success.json").content))
}
val authManager = get<AuthenticationManager>().apply {
authenticateBlocking()
}
assertTrue(authManager.login?.token!=null)
assertEquals(authManager.login?.idUser, 31098)
}
@Test
fun `authentication call failure populates error`(){
get<MockWebServer>().apply{
enqueue(MockResponse().setBody(MockResponseFileReader("login_failure.json").content))
}
val authManager = get<AuthenticationManager>().apply {
authenticateBlocking()
}
assertTrue(authManager.login?.token==null)
assertEquals(authManager.login?.errors, "Invalid credentials")
}
companion object {
const val TEST_SCOPE = "TEST_SCOPE"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment