I want to create an integration test in micronaut framework with kotlin but can’t handle how to do that.
@Test
fun confirmUser() {
val user = userDao.save(
User(activated = false, confirmationToken = "token", email = "[email protected]", confirmationTokenExpireDate = LocalDateTime.now(
Clock.systemUTC()).plusMinutes(60).toString())
)
applicationDao.save(
Application(
name = "app",
userId = user.id
)
)
registerXXXStubPost("/xxxxxxx/authenticate", tokenDto, "token_response.json")
registerXXXPost("/xxxxx/user", apiDto)
val result = userController.confirmUser("token")
assertTrue(result.status == HttpStatus.OK)
assertTrue(result.body.get().activated!!)
}
My controller function looks like this:
fun confirmUser(@PathVariable token: String): HttpResponse<UserDto> {
val user = userService.activateTechnicalUser(token)
userService.createUser(technicalUser)
return HttpResponse.ok<TechnicalUserDto>().body(user.toUserDto())
}
createUser function is async and does some actions on user object and then saves it to database
I want to be sure that the whole process works correctly and maybe make this async function be sync in the test – something like that
Do you know how to handle this case?
The test passes correctly as user gets activated in db in sync function activateTechnicalUser, but then creating needs to call another service what takes too much time to wait for the response while the application is running