Skip to content

Commit

Permalink
fix: queryMatchingDatetime creates invalid genetator #1612
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Nov 25, 2022
1 parent aece98d commit 28ff522
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected PactDslRequestBase queryMatchingDateBase(String field, String pattern,
if (StringUtils.isNotEmpty(example)) {
query.put(field, Collections.singletonList(example));
} else {
requestGenerators.addGenerator(Category.BODY, field, new DateGenerator(pattern, null));
requestGenerators.addGenerator(Category.QUERY, field, new DateGenerator(pattern, null));
FastDateFormat instance = FastDateFormat.getInstance(pattern);
query.put(field, Collections.singletonList(instance.format(new Date(DATE_2000))));
}
Expand All @@ -95,7 +95,7 @@ protected PactDslRequestBase queryMatchingTimeBase(String field, String pattern,
if (StringUtils.isNotEmpty(example)) {
query.put(field, Collections.singletonList(example));
} else {
requestGenerators.addGenerator(Category.BODY, field, new TimeGenerator(pattern, null));
requestGenerators.addGenerator(Category.QUERY, field, new TimeGenerator(pattern, null));
FastDateFormat instance = FastDateFormat.getInstance(pattern);
query.put(field, Collections.singletonList(instance.format(new Date(DATE_2000))));
}
Expand All @@ -107,7 +107,7 @@ protected PactDslRequestBase queryMatchingDatetimeBase(String field, String patt
if (StringUtils.isNotEmpty(example)) {
query.put(field, Collections.singletonList(example));
} else {
requestGenerators.addGenerator(Category.BODY, field, new DateTimeGenerator(pattern, null));
requestGenerators.addGenerator(Category.QUERY , field, new DateTimeGenerator(pattern, null));
FastDateFormat instance = FastDateFormat.getInstance(pattern);
query.put(field, Collections.singletonList(instance.format(new Date(DATE_2000))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.com.dius.pact.consumer.dsl

import au.com.dius.pact.consumer.ConsumerPactBuilder
import au.com.dius.pact.core.model.OptionalBody
import au.com.dius.pact.core.model.PactSpecVersion
import au.com.dius.pact.core.model.generators.Generators
import au.com.dius.pact.core.model.matchingrules.MatchingRulesImpl
import au.com.dius.pact.core.model.matchingrules.RegexMatcher
Expand Down Expand Up @@ -149,4 +150,28 @@ class PactDslRequestWithPathSpec extends Specification {
request.requestHeaders == ['content-type': ['text/plain']]
}
@Issue('#1612')
def 'queryMatchingDatetime creates invalid generator'() {
given:
PactDslWithProvider consumerPactBuilder = ConsumerPactBuilder
.consumer('spec')
.hasPactWith('spec')
when:
def pact = consumerPactBuilder
.uponReceiving("a request")
.path("/api/myrequest")
.method("POST")
.queryMatchingDatetime("startDateTime", "yyyy-MM-dd'T'hh:mm:ss'Z'")
.willRespondWith()
.status(200)
.toPact()
def request = pact.interactions.first()
def generators = request.request.generators
then:
generators.toMap(PactSpecVersion.V3) == [
query: [startDateTime: [type: 'DateTime', format: "yyyy-MM-dd'T'hh:mm:ss'Z'"]]
]
}
}

0 comments on commit 28ff522

Please sign in to comment.