Goetz Markgraf
02/02/2023, 10:01 AMget("/some/uri") {
val data = call.receive<SomeType>()
val result = doBusinessStuffWith(data)
call.respond(result.doSomeFormatting()
}
And the business function is defined somewhere else:
fun doBusinessStuffWith(data: SomeType): SomeReturnType {
...
}
Is there a way to test the controller in isolation by mocking the business function doBusinessStuffWith
?
In Javascript, you can mock any function call with jest
. I assume, it is not that easy in kotlin, but is there a nice way?
Thank you for your ideas …dave
02/02/2023, 10:04 AMSam
02/02/2023, 10:04 AMDominik Sandjaja
02/02/2023, 10:04 AMdoBusinessStuffWith(...)
to a dedicated class. This would not only make testing simpler (you can then simply mock that class and the method call), but it would also clarify the responsibilities of the two classes: One for routing and request/response handling, one for doing logic.Goetz Markgraf
02/02/2023, 10:07 AMDominik Sandjaja
02/02/2023, 10:09 AMdave
02/02/2023, 10:09 AMGoetz Markgraf
02/02/2023, 10:10 AMdave
02/02/2023, 10:10 AMfun myController(fn: (String) -> DomainThing)