Skip to content

Commit

Permalink
Merge pull request #2380 from alphagov/content-modelling/632-send-las…
Browse files Browse the repository at this point in the history
…t_edited_by_editor_id-to-publishing-api

Send `last_edited_by_editor_id` to Publishing API
  • Loading branch information
pezholio authored Oct 25, 2024
2 parents 097a5f6 + 57f5885 commit 744cc9e
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/presenters/formats/edition_format_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def required_fields(republish)
schema_name:,
document_type:,
public_updated_at: public_updated_at.rfc3339(3),
last_edited_by_editor_id:,
publishing_app: "publisher",
rendering_app:,
routes:,
Expand All @@ -36,7 +37,7 @@ def required_fields(republish)
change_note: edition.latest_change_note,
details:,
locale: artefact.language,
}
}.compact
end

def schema_name
Expand Down Expand Up @@ -97,5 +98,12 @@ def major_change?
def public_updated_at
edition.public_updated_at || edition.updated_at
end

# We can't reliably get the exact user who last edited the edition,
# so we rely on who created the edition, which is a fair enough
# approximation
def last_edited_by_editor_id
edition.created_by&.uid
end
end
end
21 changes: 21 additions & 0 deletions test/support/presenter_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module PresenterTestHelpers
def it_includes_last_edited_by_editor_id
test "[:last_edited_by_editor_id] should return the creator of the edition" do
editor = FactoryBot.create(:user)
edition.actions.create!(request_type: Action::CREATE, requester: editor)

assert_equal editor.uid, result[:last_edited_by_editor_id]
end

test "[:last_edited_by_editor_id] should return the creator of a new version" do
editor = FactoryBot.create(:user)
edition.actions.create!(request_type: Action::NEW_VERSION, requester: editor)

assert_equal editor.uid, result[:last_edited_by_editor_id]
end

test "[:last_edited_by_editor_id] should return nil when there are no new version or create actions" do
assert_nil result[:last_edited_by_editor_id]
end
end
end
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require "support/action_processor_helpers"
require "support/factories"
require "support/local_services"
require "support/presenter_test_helpers"
require "govuk_schemas/assert_matchers"
require "govuk_sidekiq/testing"

Expand Down Expand Up @@ -99,4 +100,5 @@ def login_as_homepage_editor
include TabTestHelpers
include HolidaysTestHelpers
include ActionProcessorHelpers
extend PresenterTestHelpers
end
2 changes: 2 additions & 0 deletions test/unit/presenters/formats/answer_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def result
subject.render_for_publishing_api
end

it_includes_last_edited_by_editor_id

should "be valid against schema" do
assert_valid_against_publisher_schema(result, "answer")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def result
subject.render_for_publishing_api
end

it_includes_last_edited_by_editor_id

should "be valid against schema" do
assert_valid_against_publisher_schema(result, "completed_transaction")
end
Expand Down
8 changes: 8 additions & 0 deletions test/unit/presenters/formats/edition_format_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def result
edition.stubs :latest_change_note
edition.stubs :auth_bypass_id
edition.stubs :exact_route?
edition.stubs created_by: FactoryBot.build(:user)

artefact.stubs :language
end
Expand Down Expand Up @@ -160,5 +161,12 @@ def result
expected = { auth_bypass_ids: %w[foo] }
assert_equal expected, result[:access_limited]
end

should "[:last_edited_by_editor_id]" do
uid = SecureRandom.uuid
user = FactoryBot.build(:user, uid:)
edition.expects(:created_by).returns(user)
assert_equal uid, result[:last_edited_by_editor_id]
end
end
end
2 changes: 2 additions & 0 deletions test/unit/presenters/formats/guide_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def result
subject.render_for_publishing_api
end

it_includes_last_edited_by_editor_id

should "be valid against schema" do
assert_valid_against_publisher_schema(result, "guide")
end
Expand Down
2 changes: 2 additions & 0 deletions test/unit/presenters/formats/help_page_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def result
assert_valid_against_publisher_schema(result, "help_page")
end

it_includes_last_edited_by_editor_id

should "[:schema_name]" do
assert_equal "help_page", result[:schema_name]
end
Expand Down
2 changes: 2 additions & 0 deletions test/unit/presenters/formats/licence_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def result
assert_valid_against_publisher_schema(result, "licence")
end

it_includes_last_edited_by_editor_id

should "[:schema_name]" do
assert_equal "licence", result[:schema_name]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def result
assert_valid_against_publisher_schema(result, "local_transaction")
end

it_includes_last_edited_by_editor_id

should "[:schema_name]" do
assert_equal "local_transaction", result[:schema_name]
end
Expand Down
2 changes: 2 additions & 0 deletions test/unit/presenters/formats/place_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def result
assert_valid_against_publisher_schema(result, "place")
end

it_includes_last_edited_by_editor_id

should "[:schema_name]" do
assert_equal "place", result[:schema_name]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def result
subject.render_for_publishing_api
end

it_includes_last_edited_by_editor_id

should "be valid against schema" do
assert_valid_against_publisher_schema(result, "simple_smart_answer")
end
Expand Down
2 changes: 2 additions & 0 deletions test/unit/presenters/formats/transaction_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def result
subject.render_for_publishing_api
end

it_includes_last_edited_by_editor_id

should "be valid against schema" do
assert_valid_against_publisher_schema(result, "transaction")
end
Expand Down

0 comments on commit 744cc9e

Please sign in to comment.