I am writing an integration test using the Scala Play framework.
I in the controller I have a function that looks like this:
def myEndpoint: AnyAction = myActionProvider.securedEndpoint("myEndpoint") { implicit request =>
// Business logic
Ok("")
}
myActionProvider.securedEndpoint
chains together some Action builders using andThen()
and returns an ActionBuilder
.
In my integration test I have the following:
val fakeRequest: FakeRequest = buildFakeRequest()
myController.myEndpoint.apply(fakeRequest)
The fake request contains a generated security token and other headers required by our app.
I am able to break inside myActionProvider.securedEndpoint
and follow the execution. However, I am not able to break inside any of the invokeBlock
methods, nor inside the business logic of the controller. Logging shows that those pathways are never executed.
If I save the result of myController.myEndpoint.apply(fakeRequest)
to a variable, its type is Accumulator[ByteString, Result]
. It looks like this contains the chained Action builders and the business logic code block, but Play never executes it.
The code throws no exceptions and nothing is output to the console.
I was wondering if it was an error with my test syntax. I've also tried the following, to no avail:
myController.myEndpoint { fakeRequest }
myController.myEndpoint()(fakeRequest)
And yes, the code works in a "regular" e.g. non-testing environment :)