Skip to content

Commit

Permalink
fix: Matching rules were not being applied to repeated query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jun 26, 2023
1 parent e272dc2 commit 28d544e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package au.com.dius.pact.core.matchers

import au.com.dius.pact.core.support.padTo
import mu.KLogging
import org.atteo.evo.inflector.English

Expand Down Expand Up @@ -33,7 +34,9 @@ object QueryMatcher : KLogging() {
path: List<String>,
context: MatchingContext
): List<QueryMismatch> {
return expected.mapIndexed { index, value -> index to value }
return expected
.padTo(actual.size)
.mapIndexed { index, value -> index to value }
.flatMap { (index, value) ->
when {
index < actual.size -> compare(parameter, value, actual[index], context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.com.dius.pact.core.matchers

import au.com.dius.pact.core.model.matchingrules.DateMatcher
import au.com.dius.pact.core.model.matchingrules.MatchingRuleCategory
import au.com.dius.pact.core.model.matchingrules.RegexMatcher
import spock.lang.Specification

class QueryMatcherSpec extends Specification {
Expand Down Expand Up @@ -34,4 +35,14 @@ class QueryMatcherSpec extends Specification {
['1000-01-01', '2000-01-01'], ['2000-01-01', '2000x-01-03'], context)*.mismatch ==
["Expected '2000x-01-03' to match a date of 'yyyy-MM-dd': Unable to parse the date: 2000x-01-03"]
}

def 'applies matching rules to multiple parameter values'() {
given:
context.matchers.addRule('a', new RegexMatcher('\\d+'))

expect:
QueryMatcher.compareQuery('a',
['100'], ['100', '200', '300x'], context)*.mismatch ==
["Expected '300x' to match '\\d+'"]
}
}

0 comments on commit 28d544e

Please sign in to comment.