GitHub
03/23/2023, 4:26 PM"pactRust": {
"ffi": "0.4.0",
"models": "1.0.4"
},
Issue Checklist
Please confirm the following:
☑︎ I have upgraded to the latest
☑︎ I have the read the FAQs in the Readme
☑︎ I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures
☑︎ I have set my log level to debug and attached a log file showing the complete request/response cycle
☑︎ For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem
Expected behaviour
Given this interaction:
interaction('pact integration', ({ provider, execute }) => {
beforeEach(() =>
provider
.given('A pet 1845563262948980200 exists')
.uponReceiving('A get request to get a pet 1845563262948980200')
.withRequest({
method: 'GET',
path: '/v2/pet/1845563262948980200',
headers: { api_key: '[]' },
})
.willRespondWith({
status: 200,
// Hypothetical response from an API
// body: {
// options: {
// 'DEFAULT': {
// value: MatchersV3.integer(12),
// selected: MatchersV3.boolean(false)
// },
// 'SUPER': {
// value: MatchersV3.integer(120),
// selected: MatchersV3.boolean(true)
// },
// 'LUXERY': {
// value: MatchersV3.integer(12000),
// selected: MatchersV3.boolean(false)
// }
// }
// }
// Pact for this API
body: {
options: MatchersV3.eachKeyLike('SUPER', {
value: MatchersV3.integer(120),
selected: MatchersV3.boolean(true),
}),
optionArray: MatchersV3.eachLike({
value: MatchersV3.integer(120),
selected: MatchersV3.boolean(true),
}),
},
})
);
I would expect matchingRules in the resulting pact-file for the body that look like this:
"matchingRules": {
"body": {
"$.options": {
"combine": "AND",
"matchers": [
{
"match": "values"
}
]
},
"$.options.*.selected": {
"combine": "AND",
"matchers": [
{
"match": "type"
},
]
},
"$.options.*.value": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
}
}
},
Similar to the result from eachLike() used in the example for optionArray:
"$.optionArray[*].selected": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.optionArray[*].value": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
Actual behaviour
"matchingRules": {
"body": {
"$.options": {
"combine": "AND",
"matchers": [
{
"match": "values"
}
]
},
"$.options.*.*": {
"combine": "AND",
"matchers": [
{
"match": "type"
},
{
"match": "integer"
}
]
}
}
},
Note: $.options.*.* with the accumulated matchers for all the fields.
Nesting of eachKeyLike() works and results in more paths with *. in combination with eachLike() down the body I get paths like this $.options.*.*.*[*].*[*].*.*.* and all the paths contain just contain all the matchers for the respective fields together.
Here is a excerpt from a more complex example:
"$.angebote.*.*": {
"combine": "AND",
"matchers": [
{
"match": "type"
},
{
"match": "type"
},
{
"match": "type"
},
{
"match": "type"
},
{
"match": "type"
},
{
"match": "type"
},
{
"match": "type"
},
{
"match": "type"
}
]
},
Together with "combine": "AND", there is no way this will ever properly match.
I think it's related to this issue here: pact-foundation/pact-reference#216 but I lack the necessary Rust Knowhow to dive into that.
Steps to reproduce
I forked the jest-pact Repository and adapted the v3 test to show the issue. I also added the resulting pact-file for easier reference here:
Repo: https://github.com/eburi/jest-pact
=> npm install && npm run test
https://github.com/eburi/jest-pact/blob/master/src/v3/pactwith.v3.test.ts#L18
Resulting Pact File:
https://github.com/eburi/jest-pact/blob/master/pact/pacts/MyConsumer-pactWith%20v3.json
Relevant log files
debug.log
pact-foundation/pact-js