Barry
06/10/2024, 9:43 PM.matchQuery("status", "(DRAFT|ACTIVE)", "ACTIVE")
◦ The test will check that the value is ACTIVE, but the contract will permit either DRAFT or ACTIVE as the consumer could use either value.
• Relax the stubbed repository query to accept all parameters. Therefore instead of setting up the repo mocks with the state parameters we send, we accept org.mockito.any() in order to return a result
This way we are still following Postel's Law, "strict" with what we send out but flexible with what is returned.
Is this the correct way to approach the issue of two consumers and one provider state handler?Barry
06/11/2024, 7:55 AMtest?paramA=1¶mB=2¶mC=3
And
Consumer B - Sends a requests with request parameters A,D and E
test?paramA=1¶mD=2¶mE=3
Consumer A will want a state parameter for B and C and nothing for D and E
Consumer B will want a state parameter for D and E and nothing for B and C
If I updated the state change handler to cover all possible state parameters across all consumers then the request parameters from state parameters then both consumers will send A, B, C, D and E.
My issue, really consumer A is sending values for D and E that it doesn't actually use.
Same with consumer B sending B and C.
If the provider made a change (made parameter C mandatory) then we know that this will break the contract that consumer B has, thus we know the impact.Matt (pactflow.io / pact-js / pact-go)
.matchQuery(“status”, “(DRAFT|ACTIVE)“, “ACTIVE”)this has no effect on the provider verification - it’s a request side matcher. The problem you have is that the provider test doesn’t know how to support both use cases. Personally, I’d opt for two separate `state`s on the tests, and setup the state for each scenario differently.
Matt (pactflow.io / pact-js / pact-go)
There is a state handler setup that handles both requests (I didn’t think it was wise for the provider to have multiple handers for the same endpoint)I think this should be two separate state handlers
Barry
06/12/2024, 10:06 AMMatt (pactflow.io / pact-js / pact-go)
We are considering the provider sending all state parameters for all the possible request parameters.For clarity. Do you mean, supporting multiple state params for the different scenarios?
Barry
06/12/2024, 10:17 AM.queryParameterFromProviderState("paramA", "${useParamAFromStateHandler}", "exampleOfParameterAforTest")
.queryParameterFromProviderState("paramB", "${useParamBFromStateHandler}", "exampleOfParameterBforTest")
.queryParameterFromProviderState("paramC", "${useParamCFromStateHandler}", "exampleOfParameterCforTest")
Consumer B will use A, D and E.
.queryParameterFromProviderState("paramA", "${useParamAFromStateHandler}", "exampleOfParameterAforTest")
.queryParameterFromProviderState("paramD", "${useParamDFromStateHandler}", "exampleOfParameterDforTest")
.queryParameterFromProviderState("paramE", "${useParamEFromStateHandler}", "exampleOfParameterEforTest")
The the mocked repo will have to check the values of the parameters it receives
So, to handle a request from Consumer A, if A, B, C have a value and D and E are null, then return expected body
and for Consumer B, if A, D, E have a value and B and C are null, then return expected body.Barry
06/12/2024, 10:32 AM.matchQuery(“status”, “(DRAFT|ACTIVE)“, “ACTIVE”)
this has no effect on the provider verification - it’s a request side matcher. The problem you have is that the provider test doesn’t know how to support both use cases.Just to confirm, this is the consumer (client) side and it will send a status of either DRAFT or ACTIVE.
Matt (pactflow.io / pact-js / pact-go)
Barry
06/12/2024, 11:23 AMMatt (pactflow.io / pact-js / pact-go)