Skip to content

Instantly share code, notes, and snippets.

@fievx
Created January 2, 2019 09:43
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/2a0937a30983fa1a714bfd605aee0c30 to your computer and use it in GitHub Desktop.
Save fievx/2a0937a30983fa1a714bfd605aee0c30 to your computer and use it in GitHub Desktop.
class AuthenticationManagerTest : KoinTest{
lateinit var server : MockWebServer
@Before
fun initTest(){
server = MockWebServer()
}
@After
fun shutdown(){
server.shutdown()
}
@Test
fun `authentication sends proper body`(){
server.apply{
enqueue(MockResponse().setBody(MockResponseFileReader("login_success.json").content))
}
val baseUrl = server.url("")
//we create the AuthenticationManager using the Base Url provided by the Mock Server
startKoin(listOf(module {
single { AuthenticationManager(baseUrl.url().toString()) }
}))
get<AuthenticationManager>().apply {
authenticateBlocking()
}
val testBody = LoginBody(AuthenticationManager.username, AuthenticationManager.password)
val requestBody = server.takeRequest().body.readUtf8()
val json = JsonParser().parse(requestBody).asJsonObject
assertEquals(json.get("username").toString().replace("\"",""), testBody.username)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment