Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: edge case in webhook description rendering with participants specified by labels #512

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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