DiUS / pact-consumer-js-dsl

*DEPRECATED* A Javascript DSL for creating pacts, superceded by Pact JS
https://github.com/pact-foundation/pact-js
Other
56 stars 26 forks source link

Error calling http://127.0.0.1:1704/interactions #38

Closed moroshko closed 9 years ago

moroshko commented 9 years ago

I get the following error:

LOG: Error{message: 'Error calling http://127.0.0.1:1704/interactions'} PhantomJS 1.9.8 (Mac OS X) test should be ok FAILED AssertionError: expected [Error: Error calling http://127.0.0.1:1704/interactions] to be null (/Users/mishamoroshko/job-search-panel/pact/test.js:2588) PhantomJS 1.9.8 (Mac OS X): Executed 1 of 1 (1 FAILED) ERROR (0.018 secs / NaN secs)

What am I doing wrong?

client.js

import xhr from 'xhr';
import config from './config';

function getSuggestions(query, success, error) {
  xhr({
    uri: `http://localhost:${config.port}/v3?q=${encodeURIComponent(query)}`
  }, function(err, response) {
    if (err) {
      error();
    } else {
      success(response);
    }
  });
}

export default { getSuggestions };

config.js

export default {
  port: 1704
}

test.js

import { expect } from 'chai';
import path from 'path';
import config from './config';
import client from './client';

const autosuggestProvider = Pact.mockService({
  consumer: 'My Consumer',
  provider: 'My Provider',
  port: config.port,
  done: error => {
    console.log(error);
    expect(error).to.be.null;
  }
});

describe('test', () => {
  it('should be ok', done => {
    autosuggestProvider
      .uponReceiving('request for suggestions')
      .withRequest({
        method: 'GET',
        path: '/v3',
        headers: {
          'Accept': 'application/json'
        },
        query: {
          q: 'mel'
        }
      })
      .willRespondWith({
        status: 200,
        headers: {
          'Content-Type': 'application/json'
        },
        body: {
          something: 'ok'
        }
      });

    autosuggestProvider.run(done, runComplete => {
      function success(response) {
        expect(response).to.deep.equal({ a: 1 });
        runComplete();
      }

      function error() {
        runComplete();
        expect(true).to.be.false;
      }

      client.getSuggestions('mel', success, error);
    });
  });
});
bethesque commented 9 years ago

Have you started the mock service? This is a separate process. If you have started it, then check the logs to see if the request actually made it to the mock service. If it didn't, I'd be looking at the CORS permissions. Have a read of the wiki page here: https://github.com/bethesque/pact-mock_service/wiki/Using-the-mock-service-with-CORS

bethesque commented 9 years ago

Please look at the node examples in the example dir too.

moroshko commented 9 years ago

Thanks @bethesque. The problem was that the server was running on a different port number. Have a nice weekend!