Skip to content

Commit

Permalink
Add reproduction spec
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Oct 7, 2024
1 parent 33c47ee commit ba77a0c
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions modules/webhooks/spec/workers/project_webhook_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
require "spec_helper"

RSpec.describe ProjectWebhookJob, :webmock, type: :job do
shared_let(:user) { create(:admin) }
shared_let(:request_url) { "http://example.net/test/42" }
shared_let(:project) { create(:project, name: "Foo Bar") }
shared_let(:webhook) { create(:webhook, all_projects: true, url: request_url, secret: nil) }
Expand All @@ -50,14 +49,19 @@
{ content_type: "text/plain", x_spec: "foobar" }
end

let(:expected_payload) do
{}
end

let(:stub) do
stub_request(:post, stubbed_url.sub("http://", ""))
.with(
body: hash_including(
"action" => event,
"project" => hash_including(
"_type" => "Project",
"name" => "Foo Bar"
"name" => "Foo Bar",
**expected_payload
)
),
headers: request_headers
Expand All @@ -78,7 +82,6 @@

before do
allow(Webhooks::Webhook).to receive(:find).with(webhook.id).and_return(webhook)
login_as user
stub
end

Expand Down Expand Up @@ -133,7 +136,7 @@
end
end

describe "triggering a projec creation" do
describe "triggering a project creation" do
it_behaves_like "a project webhook call" do
let(:event) { "project:created" }
end
Expand All @@ -146,4 +149,30 @@
let(:response_body) { "not found" }
end
end

describe "triggering an update with a custom field set" do
shared_let(:custom_field) { create(:project_custom_field, :string, projects: [project]) }
shared_let(:custom_value) do
create(:custom_value,
custom_field:,
customized: project,
value: "wat")
end

it_behaves_like "a project webhook call" do
let(:expected_payload) do
{ custom_field.attribute_name(:camel_case) => "wat" }
end

it "includes the custom field value" do
subject

expect(stub).to have_been_requested

log = Webhooks::Log.last
request = JSON.parse(log.request_body)
expect(request["project"][custom_field.attribute_name(:camel_case)]).to eq "wat"
end
end
end
end

0 comments on commit ba77a0c

Please sign in to comment.