Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pact: How do I match an object whose keys match a regular expression?

I am trying to write a pact consumer test to match the following response.

[
  {
      "accountId" : 1,
      "permissions" : [
         {
            "schedule" : {
               "01/01/2018" : false,
               "01/01/1900" : true
            },
            "permissionId" : 3
         }
      ]
   }
]

Each schedule object is composed of an unknown number of keys which match a simple regular expression. But I don't see a way to match a key using a regular expression while having the value map to a simple boolean.

For instance, I see the following method in the API.

public LambdaDslObject eachKeyLike(
        String exampleKey,
        Consumer<LambdaDslObject> nestedObject)

But that is going to expect a new object as the value, instead of a primitive type.

"schedule" : {
  "01/01/2018" : { ... },    // not what I want to match
  "01/01/1900" : false       // what I want to match
}

Is there a way to specify an imprecise key mapped to a primitive value in pact-jvm?

like image 609
Quincy Bowers Avatar asked May 25 '18 14:05

Quincy Bowers


1 Answers

Sorry, this feature doesn't exist yet, but it's been discussed for the next version of the pact specification. You can add your thoughts on this issue: https://github.com/pact-foundation/pact-specification/issues/47

like image 191
Beth Skurrie Avatar answered Oct 11 '22 05:10

Beth Skurrie