diff --git a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt index e0be7ac9b..0964e2956 100644 --- a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt +++ b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt @@ -579,14 +579,15 @@ open class PactBrokerClient( body["includePendingStatus"] = enablePending if (enablePending) { body["providerVersionTags"] = jsonArray(providerTags) - if (providerBranch.isNotEmpty()) { - body["providerVersionBranch"] = providerBranch - } if (includeWipPactsSince.isNotEmpty()) { body["includeWipPactsSince"] = includeWipPactsSince } } + if (providerBranch.isNotEmpty()) { + body["providerVersionBranch"] = providerBranch + } + return handleWith { halClient.postJson(pactsForVerification, mapOf("provider" to providerName), body.serialise()).mapOk { result -> result["_embedded"]["pacts"].asArray().map { pactJson -> diff --git a/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy b/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy index 073999b58..5f2206a66 100644 --- a/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy +++ b/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy @@ -812,4 +812,35 @@ class PactBrokerClientSpec extends Specification { result.ok result.verificationResultUrl == 'verificationResultUrl' } + + @Issue('#1769') + def 'fetching pacts with selectors includes providerVersionBranch when matchingBranch is set and pending status is false'() { + given: + def halClient = Mock(IHalClient) + PactBrokerClient client = Spy(PactBrokerClient, constructorArgs: ['baseUrl']) { + newHalClient() >> halClient + } + def selectors = [ + ConsumerVersionSelectors.MatchingBranch.INSTANCE, + ConsumerVersionSelectors.MainBranch.INSTANCE + ] + def expectedJson = '{"consumerVersionSelectors":[{"matchingBranch":true},{"mainBranch":true}],' + + '"includePendingStatus":false,"providerVersionBranch":"BRANCH"}' + def jsonResult = JsonParser.INSTANCE.parseString(''' + { + "_embedded": { + "pacts": [ + ] + } + } + ''') + when: + def result = client.fetchConsumersWithSelectorsV2('provider', selectors, [], 'BRANCH', false, null) + + then: + 1 * halClient.navigate() >> halClient + 1 * halClient.linkUrl('pb:provider-pacts-for-verification') >> 'URL' + 1 * halClient.postJson('pb:provider-pacts-for-verification', [provider: 'provider'], expectedJson) >> new Result.Ok(jsonResult) + result instanceof Result.Ok + } }