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

Content type is overridden to application/json for message providers #1112

Open
3 tasks done
matdodgson opened this issue Aug 30, 2023 · 1 comment
Open
3 tasks done
Labels
bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer

Comments

@matdodgson
Copy link

matdodgson commented Aug 30, 2023

Software versions

  • OS: Ubuntu 22.04
  • Consumer Pact library: Pact JS 9.18.1
  • Provider Pact library: Pact JS 12.1.0
  • Node Version: 18.17.0

Issue Checklist

Please confirm the following:

  • I have upgraded to the latest
  • I have the read the FAQs in the Readme
  • I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures

Expected behaviour

That I can return an XML string from a message provider and be able to verify a pact from a message consumer that is also based on an XML string.

Actual behaviour

The content type on the provider is overridden to application/json so the verification always fails. See here:

res.header('Content-Type', 'application/json; charset=utf-8');

Additionally, from first glance it appears that MessageProviderPact assumes that message providers only return JSON. See here:

// Invoke the handler, and return the JSON response body

Steps to reproduce

  • Create a consumer message contract where the content is XML (ie. not JSON).
  • Create a message provider that returns an XML string
  • Verify the message contract
@matdodgson matdodgson added bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer labels Aug 30, 2023
@mefellows
Copy link
Member

Thanks for raising.

I think one way to address it, is to set the content-type header in

res.header('PACT_MESSAGE_METADATA', metadata);
. It would have to extract the content type from either the metadata or we would need to find another way to explicitly pass this through.

We would also need to fix

return res.json(messageFromHandler.message);
which currently sends it as JSON, instead of whatever type it should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer
Projects
Status: New Issue
Development

No branches or pull requests

2 participants