Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ProviderStates is not generated when no pact version is defined #1705

Closed
VictorEnaud opened this issue Jul 28, 2023 · 2 comments
Closed

Comments

@VictorEnaud
Copy link

VictorEnaud commented Jul 28, 2023

Subject: au.com.dius.pact.consumer:junit5:4.6.1

Given I have a test class anotated like this

@PactTestFor(providerName = "ArticleAPI")

When setting a state with some parameters

builder.given("an article exists", Map.of("id", "42")
...

Then only this is generated in my pact file:

"providerState": "an article exists"

while the expected behavior is to have this generated:

"providerStates": [
  {
    "name": "an article exists",
    "params": {
      "id": "42"
    }
  }
],

I believe the cause for that bug is in RequestResponseInteraction.kt at the line 32:

    if (pactSpecVersion < PactSpecVersion.V3 && providerStates.isNotEmpty()) {
      interactionJson["providerState"] = providerStates.first().name.toString()
    } else if (providerStates.isNotEmpty()) {
      interactionJson["providerStates"] = providerStates.map { it.toMap() }
    }

As I've not defined the pact version in my test, it is set as PactSpecVersion.UNSPECIFIED, which in the above if is considered as inferior to PactSpectVersion.V3, and so only the providerState is generated, and not the full providerStates.
Shouldn't this if be fixed to default PactSpecVersion to V3 as it is done everywhere else?

@rholshausen
Copy link
Contributor

Good point, it is probably time to set the default to V3. The reason it was not, is that there are lots of implementations that only support up to V2. But this is slowly changing.

rholshausen added a commit that referenced this issue Jul 31, 2023
@rholshausen
Copy link
Contributor

Default is now V3, but can be overridden with the system property pact.defaultVersion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants