Hiya, sorry if this is a silly question, but is th...
# pact-broker
p
Hiya, sorry if this is a silly question, but is there any way to register supported provider states with the broker? I get that this is consumer-driven, but it seems strange that a consumer can't query the broker to find out what states a provider supports. It feels like a feature that should exist, but if its exclusion is by-design, could someone explain the rationale to me? Example in thread 🧵
For more context: Our team maintains a provider-only service that will be consumed by numerous other services. We anticipate a deluge of consumer test cases that (ideally) can be written without our involvement using only the published API spec. So far all consumers have used differing state strings where a common one would have sufficed: •
Given a valid device exists...
â—¦
deviceId
in path:
ff2cc060-dd83-4126-b6bf-192a2e3ca033
•
Given a trad single-register electricity device
â—¦
deviceId
in path:
example-device-id
We now return
{ deviceId }
in the provider-state callback, but it seems a consumer can't know what named values exist in this
JsonMap
, so it's reliant on a very specific back-and-forth. We ultimately want consumers to be able to self-serve
y
I’m sure there has been a request in the past to create an aggregated pact view / query, so for a given provider, they could find out all of the provider states requested, but I don’t believe it currently exists. I certainly think it would be a valuable addition. I’m not sure how the provider would be able to advertise what provider states are supported, so that might be something to consider. (if you want a view from the providers perspective of what they have coded for, vs what is in all the their consumer pacts) You can use provider state callbacks (see section - Having values injected from provider state callbacks ) , to use values from provider states in the response bodies, paths etc, which is useful if you have dynamically created id’s. If you have internal documentation for your teams on pact usage, you could maybe add a section for providers to register states names they will support, and ask teams to contact them prior to generating contracts, if they are going to create something different. I am assuming these pacts are which might fail because they don’t have the correct mapped state name, are on a separate workflow, so it isn’t blocking your provider from deploying, until the contract is verified, allowing the consumer/provider team time to align on naming.
p
You can use provider state callbacks
Yea, we're using provider state callbacks in our POC, and it's working like a charm (although docs and examples were a little tough to follow for js)
internal documentation... you could maybe add a section for providers to register states names they will support
That's my stand-in option, but it's a shame to need to host this away from the broker, which is otherwise the font of such knowledge
[consumers] are on a separate workflow
Yea, that's right. They publish as part of their CI pipeline. We (producers) validate as part of ours. Presently we have a lot of consumers writing their tests in advance as we all work towards delivery (against the pre-agreed api spec)
I presume that if we use the
[null]
default state handler and
throw
an error... this would provide adequate incentive to use supported states? Feels a little nuclear though 😅
It would however give us a vehicle to return the valid states, via the error payload 🤔