Created
January 2, 2019 11:29
-
-
Save fievx/bbe8eb70bb1fafe24d3bc7e64e651e57 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
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