Ste
10/13/2023, 9:00 AMbuilder
.given("default state")
.uponReceiving("A request for GET limits")
.path(URL_PAYMENTS_SERVICE_LIMITS)
.method(HttpGet.METHOD_NAME)
.headers(
HEADER_X_INFO, getIdentifier(
id = FAKE_ID,
firstName = FAKE_FIRST_NUMBER,
lastName = FAKE_LAST_NAME
)
)
.willRespondWith()
.status(200)
.body(PactDslJsonBody().apply {
integerType("limits", 111111L)
})
.uponReceiving("A request for GET limits with no headers")
.path(URL_PAYMENTS_SERVICE_LIMITS)
.method(HttpGet.METHOD_NAME)
.willRespondWith()
.status(400)
.body(PactDslJsonBody().apply {
stringType("errorMessage", "error in request")
})
.toPact()
I can get my tests to work when I split this into two separate pacts. However, there's something about that that doesn't make sense to me. I basically just want an 'else' case should the request be missing the vital header info... Can anyone advise?Bas Dijkstra
10/13/2023, 11:15 AM@Pact methods. Don't think of them as an 'else' to your happy path, think of them as a separate interaction instead.
Having them separated also makes finding the root cause of an error much easier, because you can see exactly which interaction is defined where and which ones passes and fails. Tests should ideally fail for one reason only, and having if-then-else in your tests (either explicit or more implicit like here) is somewhat of an antipattern, at least to merholshausen
10/15/2023, 9:33 PMrholshausen
10/15/2023, 9:34 PM