I'm starting to use Pact (on Java) for Contract Tests.
I've read Contract Tests vs Functional Tests on Pact best practices but I'm a little confused.
Example: a simple REST endpoint that creates a resource (POST), returning a 201 Created on success and 400 Bad Request for syntactic validation errors. The request body is something like:
{
"firstname" : "Foo",
"lastname" : "Bar"
}
Both firstname
and lastname
must not be blank. So far as I understand I could write 3 scenarios here, in which the provider should return 400 Bad Request:
firstname
is blank,lastname
is not blankfirstname
is not blank,lastname
is blankfirstname
andlastname
are both blank
The thing is that the mock server returns a 500 Internal Server Error if only the "happy path pact" is defined, and if I want to make it return 400 Bad Request I have to write all possible pacts. Moreover, if I add another fields with the same validation rule the number of pacts explodes.
- First of all, should I test that scenarios on my consumer?
- If yes, do exists any smart way to implement it with Pact DSL?
Thank you.