pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.59k stars 343 forks source link

Provider `v3` drops state params in Pact file with spec `v2` #1079

Open martinslota opened 1 year ago

martinslota commented 1 year ago

Software versions

Issue Checklist

Please confirm the following:

Expected behaviour

When using the v3 Pact provider with spec version 2, state parameters (as well as multiple states) should be present in the providerState field of interactions in the generated Pact file.

Actual behaviour

Only the description of the first state is copied into the providerState field for each interaction.

Steps to reproduce

See https://github.com/martinslota/pact-js-bug-state-params-dropped.

Relevant files

TimothyJones commented 1 year ago

When using the v3 Pact provider with spec version 2, state parameters (as well as multiple states) should be present in the providerState field of interactions in the generated Pact file.

I don't think this is the expected behaviour. Pact spec version 2 does not support state parameters or multiple states.

mefellows commented 1 year ago

That's correct. Perhaps we shouldn't allow it in the DSL

martinslota commented 1 year ago

I don't think this is the expected behaviour. Pact spec version 2 does not support state parameters or multiple states.

That's a good point.

The bug report originates from my effort to upgrade from @pact-foundation/pact version 9. The original code put an entire stringified JSON array into the state field of an interaction. I guess I expected that if I upgrade and put the original data into states, it bubbles all the way to the providerState field in the resulting pact file.

I suppose I could in principle put the stringified array into the description field of the first element of an interaction's states field and I'd get the effect I want.

As far as I'm concerned, we can close this bug report.

martinslota commented 1 year ago

That's correct. Perhaps we shouldn't allow it in the DSL

That would be a very nice touch! 💯

mefellows commented 1 year ago

In the V4 interface, the API itself doesn't allow incompatible things to be done like this. It's a bit harder to do with the V3 API because we allow the spec as an option in the constructor and that changes what can/can't be done later in the API, making the checks complicated/messy.

I'll leave it open for now as a potential enhancement.