Zebi
09/20/2022, 11:07 AMeachKeyLike. Is it possible to use eachKeyLike for nested (up-to 3 levels) dynamic keys? It seems that it only works on one level but in my use case, we can have nested dynamic keys and I just want to ensure the shape of the request/response payload. Any help would be appreciated. An example payload is as follows:
{
"john-doe1": {
"brown-fox": {
"jumps": "over",
"the": "lazy dog"
}
},
"john-doe2": {
"brown-fox2": {
"jumps": "over",
"the": "lazy dog"
}
}
}
And the matcher which I am trying to use is as follows (roughly). It skips checking the first level of the keys (as expected) but then it compares the other keys literally:
Matchers.eachKeyLike("some string", Matchers.eachKeyLike("some-string", Matchers.eachKeyLike("some-string", Matchers.string())))uglyog
Timothy Jones
09/20/2022, 11:23 PMeachKeyLike(<key definition>, <value definition>), wouldn't we expect nested calls to match the example given here?Timothy Jones
09/20/2022, 11:25 PMeachKeyLike(key: string, template: any)
Object where the keys itself is ignored, but the values must match a particular shape. Variants may be objects containing matching rulesSo, wouldn't we expect the example above to work?
uglyog
Timothy Jones
09/20/2022, 11:47 PMTimothy Jones
09/20/2022, 11:48 PMTimothy Jones
09/20/2022, 11:50 PMMatchers.eachKeyLike("exampleKey", Matchers.eachLike(exampleArrayEntry))uglyog
\w+\-\w+, then "jumps" and "the" are invalid keys.uglyog
Timothy Jones
09/21/2022, 12:15 AMMatchers.eachKeyLike( // top level object has keys that are
// any string, for example
"some string",
// and values that are
Matchers.eachKeyLike( // objects with keys that are
// any string, for example:
"some-string",
// and values that are:
Matchers.eachKeyLike( // objects with keys that are:
// any string, for example
"some-string",
// and values that are
Matchers.string() // also any string
)))Timothy Jones
09/21/2022, 12:17 AMuglyog
Timothy Jones
09/21/2022, 12:18 AMexport const eachKeyLike = <T extends AnyTemplate>(
keyTemplate: string,
template: T
): Matcher<AnyTemplate> => ({
'pact:matcher:type': 'values',
value: {
[keyTemplate]: template,
},
});uglyog
Timothy Jones
09/21/2022, 12:20 AMTimothy Jones
09/21/2022, 12:20 AMTimothy Jones
09/21/2022, 12:21 AMTimothy Jones
09/21/2022, 12:23 AMTimothy Jones
09/21/2022, 12:23 AMTimothy Jones
09/21/2022, 12:23 AMTimothy Jones
09/21/2022, 12:26 AMeachKey and eachValue, but those were introduced later than V3's eachKeyLike, which I think is correctly the values matcher? I'm a bit confuseduglyog
uglyog
eachKeyLike only works on values, and it should be able to apply to multiple levels, however, I imagine the matcher paths are not being setup correctly. It will need some time to investigate what is going on.Timothy Jones
09/21/2022, 12:32 AMuglyog
Timothy Jones
09/21/2022, 12:43 AMuglyog
Timothy Jones
09/21/2022, 12:49 AMZebi
09/21/2022, 8:01 AMTimothy Jones
09/21/2022, 8:03 AMMatt (pactflow.io / pact-js / pact-go)