Skip to content

Commit

Permalink
fix: Provider branch not sent to Pact Broker in consumer version sele…
Browse files Browse the repository at this point in the history
…ctors if enablePending=false #1769
  • Loading branch information
rholshausen committed Feb 15, 2024
1 parent d50ad08 commit 9480fdc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 9480fdc

Please sign in to comment.