Skip to content

Commit

Permalink
add optional publishing_app param in PublishIntentPresenter
Browse files Browse the repository at this point in the history
we want to send Publish Intents for Host Content (e.g. Editions that
are using embedded content/Content Blocks) [1] that is published
by other apps - this allows an optional app to be passed in, but retains
the default Whitehall value in order not to break existing functionality.

[1] #9447
  • Loading branch information
Harriethw committed Sep 20, 2024
1 parent 2d56b71 commit c659c4e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/presenters/publishing_api/publish_intent_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module PublishingApi
class PublishIntentPresenter
def initialize(base_path, publish_timestamp)
def initialize(base_path, publish_timestamp, publishing_app = Whitehall::PublishingApp::WHITEHALL)
@base_path = base_path
@publish_timestamp = publish_timestamp
@publishing_app = publishing_app
end

def as_json
{
publish_time: @publish_timestamp,
publishing_app: Whitehall::PublishingApp::WHITEHALL,
publishing_app: @publishing_app,
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND,
routes: [{ path: @base_path, type: "exact" }],
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require "test_helper"

module PublishingApi
class PublishIntentPresenterTest < ActiveSupport::TestCase
test "it returns Whitehall as default publisher" do
base_path = "/example-path"
publish_timestamp = Time.zone.now.to_s

presenter = PublishingApi::PublishIntentPresenter.new(base_path, publish_timestamp)
expected_hash = {
publish_time: publish_timestamp,
publishing_app: Whitehall::PublishingApp::WHITEHALL,
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND,
routes: [{ path: base_path, type: "exact" }],
}

assert_equal presenter.as_json, expected_hash
end

test "it returns publishing app if provided" do
base_path = "/example-path"
publish_timestamp = Time.zone.now.to_s
publishing_app = "example-publishing-app"

presenter = PublishingApi::PublishIntentPresenter.new(base_path, publish_timestamp, publishing_app)
expected_hash = {
publish_time: publish_timestamp,
publishing_app: "example-publishing-app",
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND,
routes: [{ path: base_path, type: "exact" }],
}

assert_equal presenter.as_json, expected_hash
end
end
end

0 comments on commit c659c4e

Please sign in to comment.