Fixed the issue that a null value wasn't considered an optional property
without this change an optional property was such that had an empty or non empty string. Null wasn't supported with this change we're adding null back fixes gh-1257
This commit is contained in:
@@ -233,7 +233,7 @@ class Common {
|
||||
}
|
||||
|
||||
void assertThatSidesMatch(OptionalProperty stubSide, Object testSide) {
|
||||
assert testSide ==~ Pattern.compile(stubSide.optionalPattern())
|
||||
assert testSide == null || testSide ==~ Pattern.compile(stubSide.optionalPattern())
|
||||
}
|
||||
|
||||
void assertThatSidesMatch(Pattern pattern, String value) {
|
||||
@@ -245,7 +245,7 @@ class Common {
|
||||
}
|
||||
|
||||
void assertThatSidesMatch(MatchingStrategy firstSide, MatchingStrategy secondSide) {
|
||||
if (firstSide.type == MatchingStrategy.Type.ABSENT && secondSide != MatchingStrategy.Type.ABSENT) {
|
||||
if (firstSide.type == MatchingStrategy.Type.ABSENT && secondSide.type != MatchingStrategy.Type.ABSENT) {
|
||||
throwAbsentError()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,4 +398,28 @@ then:
|
||||
assertThat(contract.request.bodyMatchers.hasMatchers()).isTrue()
|
||||
assertThat(contract.response.bodyMatchers.hasMatchers()).isTrue()
|
||||
}
|
||||
|
||||
def 'should work with optional and null value of a field'() {
|
||||
given:
|
||||
def contract = Contract.make {
|
||||
description("Creating user")
|
||||
name("Create user")
|
||||
request {
|
||||
method 'POST'
|
||||
url '/api/user'
|
||||
body(
|
||||
address: $(consumer(optional(regex(alphaNumeric()))), producer(null)),
|
||||
name: $(consumer(optional(regex(alphaNumeric()))), producer(''))
|
||||
)
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 201
|
||||
}
|
||||
}
|
||||
expect:
|
||||
contract != null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user