0

Need help on solving the above problem 'cannot GET /states' for http:/localhost:8081/states. I have gone through https://groups.google.com/forum/#!topic/pact-support/zGj8o6snf5c, it is very helpful but did not find the answer.

GitHub Repository URL:https://github.com/pactfoundation/pactjs/tree/master/examples/e2e

I have set up the Pact-js e2e example on my machine OS X EI Captain[10.11].

  1. Run the consumer test ./node_modules/.bin/mocha test/consumer.spec.js Got the successful output.

Pact
    when a call to list all animals from the Animal Service is made
      and there are animals in the database
        ✓ returns a list of animals
    when a call to the Animal Service is made to retreive a single animal by ID
      and there is an animal in the DB with ID 1
        ✓ returns the animal
      and there no animals in the database
        ✓ returns a 404
    when interacting with Animal Service
      ✓ should validate the interactions and create a contract
  1. Publish the tests node test/publish.js. Got the successful output.

Pact contract publishing complete!

Head over to https://test.pact.dius.com.au/ and login with
=> Username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M
=> Password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
to see your published contracts.
  1. Run the consumer and provider api npm run api. Got the successful output

Animal Profile Service listening on http://localhost:8081
Animal Matching Service listening on http://localhots:8080
  1. Run the provider test ./node_modules/.bin/mocha test/provider.spec.js.Got the error here

1) Uncaught error outside test suite
  Pact Verification
Pact Verification Failed:  Error: /Users/sakshi.rawal/work/pact-js/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/vendor/ruby/2.1.0/gems/json-1.8.3/lib/json/common.rb:155:in `parse': 757: unexpected token at 'Cannot GET /states (Faraday::ParsingError)
'

Can you please help me in resolving the error on step 4. Another question on Step 3 is when I click on the link in the output it does not ask for username and password.

Thanks,
Sakshi

Sakshi
  • 11
  • 4

2 Answers2

0

Step 3 listed above is not necessary, it is simply to test and use the running APIs.

I suspect step 4 is unable to run the provider with the extra endpoints as it is already running on the same port in step 3 hence the failure. This would mean it is unable to find the endpoint /states during the verification process.

Close all processes and then run step 4 and this endpoint should be added, and the tests should pass.

Matthew Fellows
  • 3,669
  • 1
  • 15
  • 18
  • Sorry for the delay in the response.Thanks for the reply @Matthew Fellows Step 4 worked when I close the processes in Step 3. But now the error is: `Pact Verification Failed: Error: /Users/sakshi.rawal/work/pact-js/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/vendor/ruby/2.1.0/gems/json-1.8.3/lib/json/common.rb:155:in parse: 757: unexpected token at 'TypeError: invalid media type
       at Object.parse (/Users/sakshi.rawal/work/pact-js/examples/e2e/node_modules/content-type/index.js:130:11)
    &nbs".`
    – Sakshi Mar 01 '17 at 09:01
0

Can you double check you have the latest code pulled down? Looks like a transitive depedency shifted which didn't like the existing content type. I patched it the other day.

Matthew Fellows
  • 3,669
  • 1
  • 15
  • 18
  • Thanks :) I did git pull and it worked fine. Just one thing about the /states and /setup. After step 3 when I hit these endpoints, it says cannot GET /states. Same error is for /suggestions/1,/setup. Does the states and setup is only generated when provider spec is run? – Sakshi Mar 01 '17 at 09:52
  • Correct. They are to setup data fixtures for corresponding client tests that are expecting data to be or not be there – Matthew Fellows Mar 01 '17 at 10:20
  • But when the profile api is running, http://localhost:8081/states gives cannot GET /states.It should give the list of states ? – Sakshi Mar 01 '17 at 12:06
  • /states is only needed for the tests, it's not part of the real API hence it is only declared in the spec – Matthew Fellows Mar 01 '17 at 20:00
  • Thank you so much Matthew for the help. – Sakshi Mar 07 '17 at 14:42