Skip to content

Commit

Permalink
Send last_edited_by_editor_id to Publishing API
Browse files Browse the repository at this point in the history
This is a new field that will allow us to identify the last person who
has edited an Edition within the Publishing API
  • Loading branch information
pezholio committed Oct 17, 2024
1 parent 3c8a29f commit 0634efb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
9 changes: 9 additions & 0 deletions app/presenters/publishing_api/base_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ def base_attributes
publishing_app: Whitehall::PublishingApp::WHITEHALL,
redirects: [],
update_type:,
last_edited_by_editor_id:,
}
end

private

Check failure on line 25 in app/presenters/publishing_api/base_item_presenter.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/AccessModifierIndentation: Outdent access modifiers like `private`. (https://rubystyle.guide#indent-public-private-protected)

def last_edited_by_editor_id
if item.respond_to?(:last_author)
item.last_author.uid
end
end
end
end
42 changes: 31 additions & 11 deletions test/unit/app/presenters/publishing_api/base_item_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0634efb

Please sign in to comment.