Skip to content

Commit 28ff522

Browse files
committed
fix: queryMatchingDatetime creates invalid genetator #1612
1 parent aece98d commit 28ff522

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslRequestBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected PactDslRequestBase queryMatchingDateBase(String field, String pattern,
8383
if (StringUtils.isNotEmpty(example)) {
8484
query.put(field, Collections.singletonList(example));
8585
} else {
86-
requestGenerators.addGenerator(Category.BODY, field, new DateGenerator(pattern, null));
86+
requestGenerators.addGenerator(Category.QUERY, field, new DateGenerator(pattern, null));
8787
FastDateFormat instance = FastDateFormat.getInstance(pattern);
8888
query.put(field, Collections.singletonList(instance.format(new Date(DATE_2000))));
8989
}
@@ -95,7 +95,7 @@ protected PactDslRequestBase queryMatchingTimeBase(String field, String pattern,
9595
if (StringUtils.isNotEmpty(example)) {
9696
query.put(field, Collections.singletonList(example));
9797
} else {
98-
requestGenerators.addGenerator(Category.BODY, field, new TimeGenerator(pattern, null));
98+
requestGenerators.addGenerator(Category.QUERY, field, new TimeGenerator(pattern, null));
9999
FastDateFormat instance = FastDateFormat.getInstance(pattern);
100100
query.put(field, Collections.singletonList(instance.format(new Date(DATE_2000))));
101101
}
@@ -107,7 +107,7 @@ protected PactDslRequestBase queryMatchingDatetimeBase(String field, String patt
107107
if (StringUtils.isNotEmpty(example)) {
108108
query.put(field, Collections.singletonList(example));
109109
} else {
110-
requestGenerators.addGenerator(Category.BODY, field, new DateTimeGenerator(pattern, null));
110+
requestGenerators.addGenerator(Category.QUERY , field, new DateTimeGenerator(pattern, null));
111111
FastDateFormat instance = FastDateFormat.getInstance(pattern);
112112
query.put(field, Collections.singletonList(instance.format(new Date(DATE_2000))));
113113
}

consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslRequestWithPathSpec.groovy

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package au.com.dius.pact.consumer.dsl
22

33
import au.com.dius.pact.consumer.ConsumerPactBuilder
44
import au.com.dius.pact.core.model.OptionalBody
5+
import au.com.dius.pact.core.model.PactSpecVersion
56
import au.com.dius.pact.core.model.generators.Generators
67
import au.com.dius.pact.core.model.matchingrules.MatchingRulesImpl
78
import au.com.dius.pact.core.model.matchingrules.RegexMatcher
@@ -149,4 +150,28 @@ class PactDslRequestWithPathSpec extends Specification {
149150
request.requestHeaders == ['content-type': ['text/plain']]
150151
}
151152
153+
@Issue('#1612')
154+
def 'queryMatchingDatetime creates invalid generator'() {
155+
given:
156+
PactDslWithProvider consumerPactBuilder = ConsumerPactBuilder
157+
.consumer('spec')
158+
.hasPactWith('spec')
159+
160+
when:
161+
def pact = consumerPactBuilder
162+
.uponReceiving("a request")
163+
.path("/api/myrequest")
164+
.method("POST")
165+
.queryMatchingDatetime("startDateTime", "yyyy-MM-dd'T'hh:mm:ss'Z'")
166+
.willRespondWith()
167+
.status(200)
168+
.toPact()
169+
def request = pact.interactions.first()
170+
def generators = request.request.generators
171+
172+
then:
173+
generators.toMap(PactSpecVersion.V3) == [
174+
query: [startDateTime: [type: 'DateTime', format: "yyyy-MM-dd'T'hh:mm:ss'Z'"]]
175+
]
176+
}
152177
}

0 commit comments

Comments
 (0)