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

Using pact-mock-server as mock data provider? #35

Closed
ichyr opened this issue Dec 3, 2015 · 5 comments
Closed

Using pact-mock-server as mock data provider? #35

ichyr opened this issue Dec 3, 2015 · 5 comments

Comments

@ichyr
Copy link

ichyr commented Dec 3, 2015

Can I use the pact-mock-service as data-provider for my integration and unit test?

If it possible to implement the following scenario:

  1. Define interactions (in the simplest variant with the same provider and consumer values for different tests)
  2. run those consumer contract definitions against pact-mock-server ( e.g. in current implementation run code that will populate the pact files).
  3. query pack-mock-server with XHR requests to get responses, from interactions ( from step 0. )

Thus populate the pack-mock-server with interactions and query it for responses from those interactions.

So we will use the interaction definitions as definition of mock data for our tests.

@ichyr
Copy link
Author

ichyr commented Dec 6, 2015

@bethesque sorry for disturbance. I guess the library was not intented to work as I would like it to :) Great job for doing it by the way. I will investigate the ruby source code deeper, becasue this is the most complicated source code that works that I've seen in my life :). I would like to understand how it works. Looks beautiful.

We will use it in the following way to use generated pacts as data-providers for our test:

  1. Write down the test in js-dsl
  2. run specilized gulp task that will run the pack mock server, run all test with pact js consumer dsl, hut the server.
  3. then read the generated pact files in the onPrepare method of protractor.js to populate some accessible in all of the e2e test variable
  4. use the data from pact.json's in $httpBackend to set up request|response in different use cases.

@ICEDLEE337
Copy link

This would be a great feature. How is this not possible already?

@bethesque
Copy link
Member

Mainly because the mock server was not designed to be used in this way, and partially just because of time. We're actually close to being able to use it this way now, as the matching rules for the request are now serialised in the pact. Previously, these were discarded, as they were not needed in the provider verification.

@ICEDLEE337
Copy link

Understood. This will add tremendous value because it enables accurate, pre-fabbed mocks for developing the client code now with bonafide contracts thereby greatly reducing unknowns at dev time! Personally, I just wrote a simple node service that picks up the outputted Pact json contracts and registers the Pact '$.path' regexes as Express endpoints, which then return the defined Pact response. A basic implementation is like ~40 lines of JS so it wasn't bad at all, but it'll be great to see this feature integrated in the Pact suite. Anyway, thanks and keep up the great work!

@cbornet
Copy link

cbornet commented Jun 2, 2017

@ICEDLEE337 did you see https://github.com/pact-foundation/pact-stub-server ?

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

4 participants