Route test failing even though the actual route is working

Heya,

I have the following route defined:

val feedback: Route = path("feedback") {
        post(complete("in feedback"))
    }

I’m trying to test it:

test("testFeedback") {
        Get() ~> ApiRoutes.feedback ~> check {
            handled should be(false)
        }

        Post() ~> ApiRoutes.feedback ~> check {
            println("rejections: " + rejections.mkString(","))
            handled should be(true)
        }
    }

The first test, on GET, passes (here i’m just making sure GET is rejected)

However the second test, on POST, also fails because handled was false.

If I try to access either the status, contentType, etc, then on either GET or POST, it just fails with an exception saying ‘request was rejected’.

However if I run the live server and hit a POST to /feedback, that works just fine and I get the message.

Any ideas… am I doing something wrong?

Hi!

You need to call it with Post("feedback").
When using Post() only, it issues a post to the / URL.

1 Like

Wow, I feel stupid.

Thank you! :)

1 Like