is ti possible to test on top of `ContractRoute` w...
# http4k
v
is ti possible to test on top of
ContractRoute
with
Path.string()
parameters? Basically, I can do:
Copy code
val response = myContractRoute(request)
but when accessing
Path.string()
parameters I am getting:
Copy code
Request was not routed, so no uri-template present
I tried then with what I found in https://www.http4k.org/cookbook/test_driven_apps/:
Copy code
val root = routes(myContractRoute)
but it seems the
routes()
method cannot work with ContractRoute. is there a way?
d
You need a contract block to wrap the contract route - a simple empty one will do it - TBH am not sure if this has been changed by the recent routing changes, because I think I used to work without that. Will have to investigate..
v
do you want to create an issue for investigation?
Copy code
val app = routes(contract { routes += myContractRoute })
val response = app(request)
still:
Request was not routed, so no uri-template present
d
I've just tried this and it seems to work fine:
Copy code
@Test
    fun `test route`() {
        val route = <http://Path.int|Path.int>().of("sue") bindContract GET to { path -> { Response(OK).body(path.toString()) } }
        assertThat(route(Request(GET, "/123")), hasBody("123"))
    }
in a contract route, the parameters are already extracted and passed into the bound handler creation function, so you don't need to get them again
v
Ok, I can see the problem now – because the method is too complex, it is easier for me to use
request.path("sue")
- but path is empty within the tests.
so is it correct that the path is empty?