From eb2c75561078edf027e34374ef9a5c1b658b820b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 7 Oct 2024 19:58:58 +0200 Subject: [PATCH] Add reproduction spec --- .../spec/workers/project_webhook_job_spec.rb | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/modules/webhooks/spec/workers/project_webhook_job_spec.rb b/modules/webhooks/spec/workers/project_webhook_job_spec.rb index 03f81354a124..3eac1560955a 100644 --- a/modules/webhooks/spec/workers/project_webhook_job_spec.rb +++ b/modules/webhooks/spec/workers/project_webhook_job_spec.rb @@ -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) } @@ -50,6 +49,10 @@ { content_type: "text/plain", x_spec: "foobar" } end + let(:expected_payload) do + {} + end + let(:stub) do stub_request(:post, stubbed_url.sub("http://", "")) .with( @@ -57,7 +60,8 @@ "action" => event, "project" => hash_including( "_type" => "Project", - "name" => "Foo Bar" + "name" => "Foo Bar", + **expected_payload ) ), headers: request_headers @@ -78,7 +82,6 @@ before do allow(Webhooks::Webhook).to receive(:find).with(webhook.id).and_return(webhook) - login_as user stub end @@ -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 @@ -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