Marek Urbanowicz
07/27/2023, 12:43 PMMarek Urbanowicz
07/28/2023, 5:31 AM{
rendered: {
'2023-01-01': [0,1],
'2023-05-23': [2],
'2023-06-01: [0]
}
}
In summary rendered is a map, where keys are dates string and values are arrays of numberMatt (pactflow.io / pact-js / pact-go)
eachValueMatches rule is probably what you want. It lets the keys be dynamic, but you can specify the shape of the value.
Here is an example test: https://github.com/pact-foundation/pact-js/blob/master/examples/v4/matchers/consumer.spec.ts#L73Marek Urbanowicz
07/28/2023, 6:56 AMrendered: eachValueMatches({'2023-01-01': [0, 1]}, atLeastOneLike(1, 2))
but it breaks the test as instead of the example value, mockprovider returns “pact’s stuff” around it:
what am I doing wrong?Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Marek Urbanowicz
07/28/2023, 7:06 AMMatt (pactflow.io / pact-js / pact-go)
Marek Urbanowicz
07/28/2023, 7:06 AMMatt (pactflow.io / pact-js / pact-go)
Marek Urbanowicz
07/28/2023, 7:07 AMMarek Urbanowicz
07/28/2023, 7:09 AMMarek Urbanowicz
07/28/2023, 7:12 AM.willRespondWith({
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: reify(expectedPDDData)
});
but it didn’t strip that guffMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
expectedMarek Urbanowicz
07/28/2023, 7:32 AMrendered: [
eachKeyMatches({ '2023-01-01': eachLike(0) }),
eachValueMatches({ '2023-01-01': eachLike(0) }, like(eachLike(0))),
]
$.rendered -> Type mismatch: Expected List [{"2023-01-01":[0]},{"2023-01-01":[0]}] but received Map {"2023-01-01":[0]}
Consumer test went through! Thanks, but the match does not work as we want 😞
We want to allow 0..n keys in that object (rendered).
I will highly appreciate suggestion how to fix thisMarek Urbanowicz
07/28/2023, 11:02 AMMatt (pactflow.io / pact-js / pact-go)
rendered: [
eachKeyMatches({ '2023-01-01': eachLike(0) }),
eachValueMatches({ '2023-01-01': eachLike(0) }, like(eachLike(0))),
]
^^ is rendered an array though?
I think you want:
rendered: eachValueMatches({ '2023-01-01': [0] }, eachLike(0)),