<#575 confusing error message when content should ...
# pact-js-development
g
#575 confusing error message when content should be JSON but wrong content-type is set by provider Issue created by individual-it Issue Classification ☐ Feature request ☑︎ Bug report Bug Report When having an interaction that checks the JSON body of the provider and the provider respond with a JSON body but sets the wrong Content-Type in the header the error message is confusing. Interaction response:
Copy code
...
      .willRespondWith({
        status: 200,
        body: {
          ocs: {
            meta: {
              statuscode: 100
            }
          }
        }
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 ether of: 1. don't check the content-type if its not mentioned in the interaction, only check the body 2. An error message saying that the header is the problem, because the body is actually valid JSON Actual behaviour
Copy code
1) Verifying a pact between owncloud-sdk and oc-server - a capabilities GET request with valid authentication returns a response which 
  1.1) has a matching body
          expected 'application/json' body but was 'text/plain;charset=utf-8'
In case the interaction is set also to check the header the error message is:
Copy code
1) Verifying a pact between owncloud-sdk and oc-server - a capabilities GET request with valid authentication returns a response which 
    1.1) has a matching body
           expected 'application/json;charset=utf-8' body but was 'text/plain;charset=utf-8'
    1.2) includes header 'Content-Type' with value 'application/json; charset=utf-8'
           Expected header 'Content-Type' to have value 'application/json; charset=utf-8' but was 'text/plain; charset=utf-8'
Steps to reproduce Interaction defined as: https://gist.github.com/individual-it/909674801163a994b3701bbbf2e6fe32 provider tests run against github.com/owncloud/core/ work fine, because it returns the correct content-type github.com/owncloud/ocis/ sets the content type wrong and that leads to the described error message Relevant log files
Copy code
PROVIDER_BASE_URL=<https://localhost:9200> yarn test-provider
yarn run v1.22.5
$ jest --runInBand providerTest.js

Verifying a pact between owncloud-sdk and oc-server

 RUNS  tests/providerTest.js
  a capabilities GET request with valid authentication
    returns a response which
      has status code 200 (OK)
      has a matching body (FAILED)


Failures:

1) Verifying a pact between owncloud-sdk and oc-server - a capabilities GET request with valid authentication returns a response which 
    1.1) has a matching body
           expected 'application/json' body but was 'text/plain;charset=utf-8'

 FAIL  tests/providerTest.js
  provider testing
    ✕ verifies the provider (224 ms)

  ● provider testing › verifies the provider

    TypeError: Cannot read property 'message' of null

      29 |     }
      30 |     await new VerifierV3(opts).verifyProvider().catch(function (error) {
    > 31 |       chai.assert.fail(error.message)
         |                              ^
      32 |     })
      33 |   }, 60000)
      34 | })

      at tests/providerTest.js:31:30

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.036 s
Ran all test suites matching /providerTest.js/i.
error Command failed with exit code 1.
pact-foundation/pact-js