Hazem Borham
09/27/2022, 8:46 PM{
picklists: atLeastOneLike([
{id: 1, name: 'She/Her'},
{id: 2, name: 'He/Him'},
{id: 3, name: 'They/Them'},
{id: 4, name: 'Other'},
])
}
so that the generated stub response for the consumer definition is:
{
picklists: [
{id: 1, name: 'She/Her'},
{id: 2, name: 'He/Him'},
{id: 3, name: 'They/Them'},
{id: 4, name: 'Other'},
]
}
and the generated matcher for the provider is:
"matchingRules": {
"body": {
"$": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.picklists": {
"combine": "AND",
"matchers": [
{
"match": "type",
"min": 1
}
]
}
},
Timothy Jones
09/27/2022, 9:19 PMMatt (pactflow.io / pact-js / pact-go)
{
picklists: eachLike({id: 1, name: 'She/Her'}, 4)
}
and then if you used it as a stub, you’d get back
[
{id: 1, name: 'She/Her'},
{id: 1, name: 'She/Her'},
{id: 1, name: 'She/Her'},
{id: 1, name: 'She/Her'}
]
Timothy Jones
09/28/2022, 3:09 AMeachLike(itemDescriptionWithMatchers, exampleArray?)
So that you could say:
eachLike(
{id: number(), name: string()},
[
{id: 1, name: 'She/Her'},
{id: 2, name: 'He/Him'},
{id: 3, name: 'They/Them'},
{id: 4, name: 'Other'},
]
)
Timothy Jones
09/28/2022, 3:12 AMi have a pact that i'd also like to reuse as a stub for testing the consumer ui.is the use case, I think that sounds unnecessarily complex. I think it would be better to stub the business object that you assert on in your pact test. For example, if your pact test looks something like:
pact.addInteraction(/* whatever */)
it("returns the correct object", () => {
const businessObject = myApi.getWhatever()
expect(businessObject).toEqual(expectedBusinessObject)
})
Then you can use expectedBusinessObject
in stubs, stubbing out myApi
completely 🙌Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Timothy Jones
09/28/2022, 4:41 AMTimothy Jones
09/28/2022, 4:41 AMHazem Borham
09/28/2022, 4:38 PMeachLike(itemDescriptionWithMatchers, exampleArray?)
apologies, i may have used stub a little too loosely here. 😁 i was referring to the feature in pactfoundation/pact-stub-server
where we can start a local stub-server running our pact definitions. so in this case, i was hoping to define a pact basically as suggested in the eachLike example.Timothy Jones
09/29/2022, 12:53 AMHazem Borham
09/29/2022, 3:51 PMeachLike(itemDescriptionWithMatchers, exampleArray?)
we're using pact-js and this would be a great enhancement for our usage there.Timothy Jones
09/29/2022, 11:59 PMHazem Borham
09/30/2022, 3:50 PM