Skip to content

Commit

Permalink
fix: edge case in webhook description rendering with participants spe…
Browse files Browse the repository at this point in the history
…cified by labels (#512)
  • Loading branch information
rabotyaga authored Oct 5, 2021
1 parent c0008e9 commit 7e6a78d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pact_broker/domain/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def to_s
end

def consumer_name
consumer && (consumer.name || (consumer.label && "labeled '#{consumer.label}'"))
consumer && (consumer.name || (consumer.label && "#{provider ? 'consumers ' : ''}labeled '#{consumer.label}'"))
end

def provider_name
provider && (provider.name || (provider.label && "labeled '#{provider.label}'"))
provider && (provider.name || (provider.label && "#{consumer ? 'providers ' : ''}labeled '#{provider.label}'"))
end

def trigger_on_contract_content_changed?
Expand Down
35 changes: 35 additions & 0 deletions spec/lib/pact_broker/domain/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,53 @@ module Domain

context "with a consumer and provider" do
it { is_expected.to eq "A webhook for the pact between Consumer and Provider" }

context "when provider is specified by a label" do
let(:provider) { WebhookPacticipant.new(label: "provider-label")}

it { is_expected.to eq "A webhook for the pact between Consumer and providers labeled 'provider-label'" }
end

context "when consumer is specified by a label" do
let(:consumer) { WebhookPacticipant.new(label: "consumer-label")}

it { is_expected.to eq "A webhook for the pact between consumers labeled 'consumer-label' and Provider" }
end

context "when both are specified by labels" do
let(:consumer) { WebhookPacticipant.new(label: "consumer-label")}
let(:provider) { WebhookPacticipant.new(label: "provider-label")}

it do
is_expected.to eq(
"A webhook for the pact between consumers labeled 'consumer-label' and providers labeled 'provider-label'"
)
end
end
end

context "with a consumer only" do
let(:provider) { nil }

it { is_expected.to eq "A webhook for all pacts with consumer Consumer" }

context "when specified by a label" do
let(:consumer) { WebhookPacticipant.new(label: "consumer-label")}

it { is_expected.to eq "A webhook for all pacts with consumer labeled 'consumer-label'" }
end
end

context "with a provider only" do
let(:consumer) { nil }

it { is_expected.to eq "A webhook for all pacts with provider Provider" }

context "when specified by a label" do
let(:provider) { WebhookPacticipant.new(label: "provider-label")}

it { is_expected.to eq "A webhook for all pacts with provider labeled 'provider-label'" }
end
end

context "with neither a consumer nor a provider" do
Expand Down

0 comments on commit 7e6a78d

Please sign in to comment.