diff --git a/app/presenters/publishing_api/base_item_presenter.rb b/app/presenters/publishing_api/base_item_presenter.rb index 203b56218be..f3822820280 100644 --- a/app/presenters/publishing_api/base_item_presenter.rb +++ b/app/presenters/publishing_api/base_item_presenter.rb @@ -18,7 +18,16 @@ def base_attributes publishing_app: Whitehall::PublishingApp::WHITEHALL, redirects: [], update_type:, + last_edited_by_editor_id:, } end + +private + + def last_edited_by_editor_id + if item.respond_to?(:last_author) + item.last_author.uid + end + end end end diff --git a/test/unit/app/presenters/publishing_api/base_item_presenter_test.rb b/test/unit/app/presenters/publishing_api/base_item_presenter_test.rb index e3a5f437d55..be4d9a39105 100644 --- a/test/unit/app/presenters/publishing_api/base_item_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/base_item_presenter_test.rb @@ -2,19 +2,39 @@ module PublishingApi class BaseItemPresenterTest < ActiveSupport::TestCase - test "it returns the base set of attributes needed by all documents sent to the publishing API" do - stubbed_item = stub(title: "A title") + extend Minitest::Spec::DSL - presenter = PublishingApi::BaseItemPresenter.new(stubbed_item, update_type: "major", locale: "fr") - expected_hash = { - title: stubbed_item.title, - locale: "fr", - publishing_app: Whitehall::PublishingApp::WHITEHALL, - redirects: [], - update_type: "major", - } + describe ".base_attributes" do + let(:presenter) { PublishingApi::BaseItemPresenter.new(stubbed_item, update_type: "major", locale: "fr") } + let(:expected_hash) do + { + title: stubbed_item.title, + locale: "fr", + publishing_app: Whitehall::PublishingApp::WHITEHALL, + redirects: [], + update_type: "major", + last_edited_by_editor_id:, + } + end - assert_equal presenter.base_attributes, expected_hash + context "when the item does not respond to last_author" do + let(:stubbed_item) { stub(title: "A title") } + let(:last_edited_by_editor_id) { nil } + + it "returns the base set of attributes needed by all documents sent to the publishing API" do + assert_equal presenter.base_attributes, expected_hash + end + end + + context "when the item responds to last_author" do + let(:last_edited_by_editor_id) { SecureRandom.uuid } + let(:last_author) { stub(uid: last_edited_by_editor_id) } + let(:stubbed_item) { stub(title: "A title", last_author:) } + + it "returns the base set of attributes needed by all documents sent to the publishing API" do + assert_equal presenter.base_attributes, expected_hash + end + end end end end