cjstehno / ersatz

🤖 A simulated HTTP server for testing client code with configurable responses.
https://cjstehno.github.io/ersatz
Apache License 2.0
47 stars 5 forks source link

Investigate request body decoder/matcher interactions #148

Closed cjstehno closed 2 years ago

cjstehno commented 2 years ago

Consdier the case where you have an application/json Map of data coming in via a POST request (serialized to json), but you want to match that the specified map key starts with a given prefix. Such as:

server.expectations(expect -> {
    expect.POST("/api/something", req -> {
        req.body(
            hasEntry(equalTo("run_id"), startsWith("somejob_bob_")),
            APPLICATION_JSON
        );
        req.called(1);
        req.responder(res -> {
            res.code(200);
            res.body(responseJson, APPLICATION_JSON);
        });
    });
});

It seems that maybe the decoder is not playing nice with the matcher... or the matchers are overly restrictive (often the case).

It appears that the matcher receives null as the incoming object... maybe the matcher is applied in the wrong order or something

cjstehno commented 2 years ago

It appears that is is not an issue in the current code.