Comments (6)
I believe this will solve your problem if you are using ruby (wrapper) on both sides (consumer and provider):
https://github.com/DiUS/pact-consumer-js-dsl/wiki/Flexible-matching
If you are not, then you'll have to wait for v2 matching which is a WIP.
from pact-mock_service.
@bethesque I've finally used the somethingLike function within our project and I found a major flaw; There's no concept of 'optional' variables, or extra keys. For instance, I was testing for an object that has, at the very least, the property 'id' as a string and 'schema' as an array. In that same object, I also had a key of 'label'. Because of this label, the request didn't work since the parsing was failing (wasn't matching). I see json schema matching as a 'minimum requirement', not a hard requirement.
We definitely also need for optional params in there. For instance, our schema has a parent child relationship which can be 3 deep at most, but is optional. With the somethingLike matcher, all children would have to be there or an error would occur. This is problematic for us since we now have to create a mock match for every single 'variability' of our data.
from pact-mock_service.
Hi Michael,
This design is quite deliberate, as we follow Postel's law of saying "we're going to be very strict with what we send out, but liberal with what we accept". We don't want our real code sending out data that our test code does not know about, as this would create a difference between the test scenarios and real life scenarios that would allow some code paths to not be properly tested, and might hide the existence of bugs.
Having said that, I know that sometimes it's a real pain! If you are finding this too painful and your use case is low risk enough that you're willing to risk differences between test/prod requests, there is an option you can add to the request setup to let it ignore extra keys. It's not currently supported by the js library, but you could add it quite easily. The following hash would need to be included to the request setup.
{
"request" : {
"options" : {
"allow_unexpected_keys_in_body" : true
}
}
}
from pact-mock_service.
Aren't you contradicting yourself if the design to be 'liberal with was we accept' but creating an error when I send a key that wasn't specified in pact?
Our case is this: we have form data that we want to save. The 'value' of the fields within the form can either change from string, to number, to array, to object or not have one at all. How can we specify this using somethingLike?
I really believe that somethingLike should be a schema DSL of sorts, a way to describe how it's suppose to look, what it's suppose to accept, if parameters are optional or required (and throw an error if an unspecified one is sent over).
from pact-mock_service.
Pact is strict with what the Consumer sends out - that's why we don't, by default, allow extra keys in the requests bodies. It is liberal with what the Consumer accepts from the Provider - that's why extra keys are allowed.
Pact is "specification by example", not "specification by schema", so you would just set up a different interaction for each variation you expect at that key. Your use case is quite unusual - it is not common to have a key that will accept multiple types of values, and I'd suggest that it actually indicates there might be some improvements that could be made to the design.
from pact-mock_service.
Not that unusual. I'd say that at the very least, the optional data points are something that I've seen happen many times. The different values is something a bit more rare, but definitely not unheard of.
from pact-mock_service.
Related Issues (20)
- Feature Request - Log level CLI Option on pact-stub-service HOT 1
- Can't start mock service wrong number of arguments (given 4, expected 2..3) (ArgumentError) HOT 1
- Internal server error when request payload cannot be encoded to UTF-8 HOT 9
- Count the number requests matching an interaction HOT 1
- Request to '/pact' endpoint without body is failing making python-pact verification unusable HOT 1
- Feature Request - support dynamic responses based on ID in request HOT 5
- given pacts dir not used HOT 2
- pactfile_write_mode - "usage" text is missing the option to 'update' HOT 2
- Ruby 2.7 cannot load such file -- thwait HOT 9
- Allow Access-Control-Allow-Credentials to be set for --cors mode HOT 13
- Feature request: json response from /interactions/verification
- Chore: migrate away from TravisCI HOT 1
- iam not able to generate pact files ,just the this infoi iam getting "INFO WEBrick::HTTPServer#start: pid=15660 port=1234" HOT 2
- Return more informative response codes HOT 2
- Feature request - Response based on provider state HOT 1
- Return most specific match when multiple matches are found HOT 4
- Can you please provide me the response model for POST /pact endpoint. HOT 2
- Pact stub service throws error for query values with matching rules HOT 5
- GH repo notifications on release HOT 1
- Update to rack 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pact-mock_service.