Skip to content

Correctly map the Pact Interaction Description property #1331

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

Merged
merged 3 commits into from
Jul 18, 2025
Merged

Conversation

StefH
Copy link
Collaborator

@StefH StefH commented Jul 16, 2025

No description provided.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures the Pact interaction description field is always populated (falling back to title when explicit description is missing) and updates related tests and fixtures to use description instead of providerState.

  • Update PactMapper to prefer mapping.Description and fall back to mapping.Title
  • Modify JSON fixtures to replace providerState with description
  • Add VerifyXunit support and a new POST-description test

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/WireMock.Net.Tests/Pact/files/pact-post.json New fixture for POST interaction using description
test/WireMock.Net.Tests/Pact/files/pact-multiple.json Replaced providerState with description in multiple interactions
test/WireMock.Net.Tests/Pact/files/pact-get.json Replaced providerState with description in GET interaction
test/WireMock.Net.Tests/Pact/PactTests.cs Added VerifyXunit, made tests async, and added POST-description test
test/WireMock.Net.Tests/Pact/PactTests.SavePact_Get_Request_WithDescription.verified.json New snapshot for the description test
test/WireMock.Net.Tests/Pact/PactTests.SavePact_Get_Request_And_Response_WithBodyAsJson.verified.json Updated snapshot for GET response test
test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.cs Removed unused WireMock.Models import
src/WireMock.Net.Minimal/Serialization/PactMapper.cs Consolidated description/title mapping into a single Description assignment
Comments suppressed due to low confidence (1)

test/WireMock.Net.Tests/Pact/PactTests.cs:246

  • This test still uses a generic length assertion; consider switching to await Verifier.VerifyFile(path) so the generated JSON (including description) is validated against a snapshot.
        File.ReadAllBytes(Path.Combine(folder, file)).Length.Should().BeGreaterThan(1);

Copy link

codecov bot commented Jul 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.16%. Comparing base (aeb1572) to head (040ba1f).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1331      +/-   ##
==========================================
- Coverage   37.17%   37.16%   -0.01%     
==========================================
  Files         176      176              
  Lines       40858    40861       +3     
==========================================
- Hits        15188    15187       -1     
- Misses      25246    25250       +4     
  Partials      424      424              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@basdijkstra
Copy link

@StefH yup, this is what I was looking for. I'd still have to test it properly when you have released this fix, but it looks good.

I wanted to publish the pact that you generated, the PactTests.SavePact_Get_Request_And_Response_WithBodyAsJson.verified.json one, but my Pact Broker complained it wasn't valid. No idea why, jsonlint.com thought it was fine. Changing description back to providerState wasn't the solution so it must be something else.

Again, this looks good, I'm happy to test it with my own contract and code once you've released the update.

@StefH
Copy link
Collaborator Author

StefH commented Jul 17, 2025

I would think that the generated JSON file would be valid? Can you more details on why it fails?

@basdijkstra
Copy link

This is the command I use to publish the contract to the broker:

pact-broker publish PactTests.SavePact_Get_Request_And_Response_WithBodyAsJson.verified.json --consumer-app-version 1.0.0

and this is the output from the pact-broker command:

C:/Tools/pact/lib/ruby/lib/ruby/3.3.0/json/common.rb:219:in `parse': unexpected token at '{ (JSON::ParserError)
  "consumer": {
    "name": "Something API Consumer Get"
  },
  "interactions": [
    {
      "description": "A GET request to retrieve the something",
      "request": {
        "headers": {
          "Accept": "application/json"
        },
        "method": "GET",
        "path": "/tester",
        "query": "q1=test&q2=ok"
      },
      "response": {
        "body": {
          "id": "tester",
          "firstName": "Totally",
          "lastName": "Awesome"
        },
        "headers": {
          "Content-Type": "application/json; charset=utf-8"
        },
        "status": 200
      }
    }
  ],
  "provider": {
    "name": "Something API"
  }
}'
        from C:/Tools/pact/lib/ruby/lib/ruby/3.3.0/json/common.rb:219:in `parse'
        from C:/Tools/pact/lib/vendor/ruby/3.3.0/gems/pact_broker-client-1.77.0/lib/pact_broker/client/pact_file.rb:28:in `pact_hash'
        from C:/Tools/pact/lib/vendor/ruby/3.3.0/gems/pact_broker-client-1.77.0/lib/pact_broker/client/pact_file.rb:20:in `consumer_name'
...

I really can't see anything that's wrong with the .json file.

I also tried publishing another contract, generated with an earlier version of WireMock .Net, and manually replace providerState with description, and that led to the desired result, so I think the code change itself is OK:

image

@StefH
Copy link
Collaborator Author

StefH commented Jul 17, 2025

If you want to test wiremock, you can try preview version 1.8.14-ci-110308

See
https://github.com/wiremock/WireMock.Net/wiki/MyGet-preview-versions

@basdijkstra
Copy link

I'll set a reminder and do that tomorrow morning!

@basdijkstra
Copy link

@StefH I used this new preview version for a test with my code and it worked like a charm:
image

Thanks so much, ready to release this as far as I'm concerned.

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

Successfully merging this pull request may close these issues.

2 participants