Hi! :wave::skin-tone-5:, I have a question regard...
# pact-js
c
Hi! ๐Ÿ‘‹๐Ÿพ, I have a question regarding pact, given a request which is sent with one of the following possible values:
Copy code
enum value {
    optionA
    optionB
    optionC
}
The response returns the value which was sent in the request like this(assuming โ€˜optionAโ€™ was sent in the request):
Copy code
data: {
    value: {
        selectedValue: 'optionA'
    }
}
My question is, what is the best way in
pact-js
to verify that only one of the possible 3 values is accepted? is there some sort of way of checking that only one of these values is accepted in the response? Thanks in advance for your help! ๐Ÿ™๐Ÿพ๐Ÿ™Œ๐Ÿพ.
m
Yes, you would simply expect the exact value and not use a matcher. Is this question hypothetical or are you having issues?
You would need to test each scenario explicitly though
c
Thanks! Not hypothetical as Iโ€™m actually testing this at the moment, but was wondering what the best option would be, I did think of testing each scenario explicitly but then I wondered if that would then be venturing into functional testing space, but in this specific scenario all three values have to be verified anyway so it makes sense ๐Ÿ™‚.
๐Ÿ‘ 2
m
All good, always good to get a second opinion!
๐Ÿ™Œ 2
t
I use the following guideline: โ€ข Test everything you expect each side to be able to understand โ€ข Don't use pact to drive functional testing, but it's ok if your tests happen to have incidental functional coverage
๐Ÿ™Œ 1
On whether or not to use a matcher: โ€ข There are cases where it's valid for the provider to return any of the following options - for example - a
userType
in response to
GET /users/{someid}
. In that case, I would use a matcher. โ€ข There are cases where although the spec says there could be multiple answers, only one of them would be valid in that response - for example, if the full user entity is returned in response to a POST request that sets the user's
type
to
admin
, you'd expect it to be exactly
admin
. In that case, I don't use a matcher.
๐Ÿ™Œ 1