You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
... This is why you can only specify an array with minimum length 1 OR a zero length array.
But I still can set min = 0 in consumer test. Pact file is generated. Provider verification is passed if attribute/field is empty array. Here is how I did it:
Instead of using eachLike in pact-js, I replace it with custom code like this
describe('Test',()=>{test('User has full information',async()=>{constuser={id: uuid(id),rels: {children: {value: [uuid(child)],getValue: ()=>[uuid(child)],'pact:matcher:type': 'type',min: 0,}}};pact.addInteraction({states: [{description: 'Users with full information'}],uponReceiving: 'get list users with full information',withRequest: {method: 'GET',path: '/tree',headers: {Accept: '*/*',}},willRespondWith: {status: 200,headers: {'Content-Type': 'application/json',},body: eachLike(user),},});awaitpact.executeTest(async(mockserver: V3MockServer)=>{awaitwaitPort({host: '127.0.0.1',port: mockserver.port,});awaitfetch(`${mockserver.url}/tree`);});});});
Consumer test is passed and pact file is generated without any error from ffi library:
Provider verification is passed as expected, indicate that min=0 is supported by ffi library (it should not support according to the article above):
Verifying a pact between admin and relationship
get list users with full information (0s loading, 53ms verification)
Given Users with full information
returns a response which
has status code 200 (OK)
includes headers
"Content-Type" with value "application/json" (OK)
has a matching body (OK)
This is were I disagree with the statement linked above. I believe that things should be explicit and we should avoid implicit rules. If you want the matching to not accept empty arrays, you must set min = 1. If you set min = 0, then you have declared your intent and the Rust matching will accept that.
According to https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes, array with
min=0
is not supported at all.But I still can set
min = 0
in consumer test. Pact file is generated. Provider verification is passed if attribute/field is empty array. Here is how I did it:Instead of using
eachLike
in pact-js, I replace it with custom code like thisFull consumer test
Consumer test is passed and pact file is generated without any error from ffi library:
Pact file
Provider response look like this:
Provider response
Provider verification is passed as expected, indicate that
min=0
is supported by ffi library (it should not support according to the article above):Provider verification full log
provider-verification-log.txt
Updated: Slack's discussion https://pact-foundation.slack.com/archives/C9VBGLUM9/p1690524409460549
The text was updated successfully, but these errors were encountered: