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

V3 consumer test expects extra " for x-www-form-urlencoded bodies #577

Closed
5 of 7 tasks
individual-it opened this issue Jan 15, 2021 · 3 comments
Closed
5 of 7 tasks

Comments

@individual-it
Copy link
Contributor

Issue Classification

  • Feature request
  • Bug report

Bug Report

Having a request in the interaction that specifies "Content-Type": "application/x-www-form-urlencoded" and an url-encoded body makes the consumer tests fail with BodyMismatch

Software versions

  • OS: Ubuntu 20
  • Consumer Pact library: Pact JS v10.0.0-beta.25
  • Provider Pact library: Pact JS v10.0.0-beta.25
  • Node Version: v12.20.1

Issue Checklist

Confirm the following:

  • I have upgraded to the latest
  • I have created a reproducable git repository (see below) to illuminate the problem
  • I have the read the FAQs in the Readme
  • I have triple checked, that there are no unhandled promises in my code
  • I have set my log level to debug and attached a log file showing the complete request/response cycle

Expected behaviour

tests should not fail when the correct form-data is send

Actual behaviour

tests fail saying they expect an extra 34 at the beginning and the end of the data

Steps to reproduce

  1. create an interaction with a request that uses content-type and a url-encoded body e.g.
          body: "first_name=Nanny&last_name=Doe",
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
    
  2. create a consumer test that sends those data to the mock server
  3. run the consumer tests

Example:

  1. clone this branch https://github.com/individual-it/pact-js/tree/formDataContenTypeBug (changes made to the feat/v3.0.0 branch: https://github.com/individual-it/pact-js/commit/0ce2d49d4bd87262b72f39888d4032f0158f4c92)
  2. in examples/v3/e2e run consumer tests: npm install; npm run test:consumer

sending extra quotes " at the beginning and the end of the body make the test pass

return expect(createMateForDates(
          '"first_name=Nanny&last_name=Doe"',
          () => mockserver.url,
          "application/x-www-form-urlencoded")).to
          .eventually.be.fulfilled
      })

Relevant log files

  1) Pact V3
       when a call to the Animal Service is made to create a new mate using form-data body
         creates a new mate with application/x-www-form-urlencoded:
     Error: Test failed for the following reasons:

	Test code failed with an error: expected promise to be fulfilled but it was rejected with 'Error: Internal Server Error'

	Mock server failed with the following mismatches: 
		1) BodyMismatch (at $) Expected text '[34, 102, 105, 114, 115, 116, 95, 110, 97, 109, 101, 61, 78, 97, 110, 110, 121, 38, 108, 97, 115, 116, 95, 110, 97, 109, 101, 61, 68, 111, 101, 34]' but received '[102, 105, 114, 115, 116, 95, 110, 97, 109, 101, 61, 78, 97, 110, 110, 121, 38, 108, 97, 115, 116, 95, 110, 97, 109, 101, 61, 68, 111, 101]'
      at /home/artur/www/pact/pact-js/examples/v3/e2e/node_modules/@pact-foundation/src/v3/pact.ts:152:33
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
@individual-it
Copy link
Contributor Author

I think the problem is in https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/v3/pact.ts#L139
it does JSON.stringify on the body and by that adds and extra pair of "

@mefellows
Copy link
Member

Thanks for raising, discussing and then fixing this - we'll get it sorted. 🙏

@individual-it
Copy link
Contributor Author

fixed in #578

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

No branches or pull requests

2 participants