Skip to content

Commit

Permalink
pass publishing app name to Publish Intents for Host Content
Browse files Browse the repository at this point in the history
We want to remove the cache Host Content that is not published by Whitehall,
as embedded content can be used across all Publishing apps.

[1] alphagov/publishing-api#2876
  • Loading branch information
Harriethw committed Sep 20, 2024
1 parent e596757 commit 6c4f1dc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def remove_cache_for_host_content(content_block_edition:)
content_block_document: content_block_edition.document,
)
host_content_items.each do |host_content_item|
ContentObjectStore::PublishIntentWorker.perform_async(host_content_item.base_path, Time.zone.now.to_s)
ContentObjectStore::PublishIntentWorker.perform_async(
host_content_item.base_path,
host_content_item.publishing_app,
Time.zone.now.to_s,
)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module ContentObjectStore
class PublishIntentWorker < WorkerBase
sidekiq_options queue: :content_block_publishing

def perform(base_path, publish_timestamp)
def perform(base_path, publishing_app, publish_timestamp)
publish_timestamp = Time.zone.parse(publish_timestamp)
publish_intent = PublishingApi::PublishIntentPresenter.new(base_path, publish_timestamp)
publish_intent = PublishingApi::PublishIntentPresenter.new(base_path, publish_timestamp, publishing_app)

Services.publishing_api.put_intent(base_path, publish_intent.as_json)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ContentObjectStore::ContentBlock::WorkflowTest < ActionDispatch::Integrati
"document_type" => "document",
"base_path" => "/host-document",
"content_id" => "1234abc",
"publishing_app" => "host_publisher",
"primary_publishing_organisation" => {
"content_id" => "456abc",
"title" => "Organisation",
Expand All @@ -140,7 +141,7 @@ class ContentObjectStore::ContentBlock::WorkflowTest < ActionDispatch::Integrati
publishing_api_mock.expect :put_intent, {}, ["/host-document",
{
publish_time: Time.zone.now,
publishing_app: "whitehall",
publishing_app: "host_publisher",
rendering_app: "government-frontend",
routes: [{ path: "/host-document", type: "exact" }],
}]
Expand Down Expand Up @@ -280,6 +281,7 @@ class ContentObjectStore::ContentBlock::WorkflowTest < ActionDispatch::Integrati
"document_type" => "document",
"base_path" => "/host-document",
"content_id" => "1234abc",
"publishing_app" => "host_publisher",
"primary_publishing_organisation" => {
"content_id" => "456abc",
"title" => "Organisation",
Expand All @@ -299,7 +301,7 @@ class ContentObjectStore::ContentBlock::WorkflowTest < ActionDispatch::Integrati
publishing_api_mock.expect :put_intent, {}, ["/host-document",
{
publish_time: Time.zone.now,
publishing_app: "whitehall",
publishing_app: "host_publisher",
rendering_app: "government-frontend",
routes: [{ path: "/host-document", type: "exact" }],
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ContentObjectStore::PublishEditionServiceTest < ActiveSupport::TestCase
"document_type" => "document",
"base_path" => "/host-document",
"content_id" => "1234abc",
"publishing_app" => "example-app",
"primary_publishing_organisation" => {
"content_id" => "456abc",
"title" => "Organisation",
Expand All @@ -93,7 +94,11 @@ class ContentObjectStore::PublishEditionServiceTest < ActiveSupport::TestCase

stub_publishing_api_has_embedded_content(content_id:, total: 0, results: host_content)

ContentObjectStore::PublishIntentWorker.expects(:perform_async).with("/host-document", Time.zone.now.to_s).once
ContentObjectStore::PublishIntentWorker.expects(:perform_async).with(
"/host-document",
"example-app",
Time.zone.now.to_s,
).once

ContentObjectStore::PublishEditionService.new(schema).call(edition)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class ContentObjectStore::UpdateEditionServiceTest < ActiveSupport::TestCase
"document_type" => "document",
"base_path" => "/host-document",
"content_id" => "1234abc",
"publishing_app" => "example-app",
"primary_publishing_organisation" => {
"content_id" => "456abc",
"title" => "Organisation",
Expand All @@ -261,7 +262,11 @@ class ContentObjectStore::UpdateEditionServiceTest < ActiveSupport::TestCase

stub_publishing_api_has_embedded_content(content_id:, total: 0, results: dependent_content)

ContentObjectStore::PublishIntentWorker.expects(:perform_async).with("/host-document", Time.zone.now.to_s).once
ContentObjectStore::PublishIntentWorker.expects(:perform_async).with(
"/host-document",
"example-app",
Time.zone.now.to_s,
).once

ContentObjectStore::UpdateEditionService
.new(schema, @original_content_block_edition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class ContentObjectStore::PublishIntentWorkerTest < ActiveSupport::TestCase
test "#perform adds a publishing intent to the Publishing API" do
base_path = "/base-path"
timestamp = Time.zone.now.to_s
publishing_app = "publisher"
publish_intent = { foo: "bar" }

PublishingApi::PublishIntentPresenter.expects(:new).with(base_path, timestamp).once.returns(publish_intent)
PublishingApi::PublishIntentPresenter.expects(:new).with(base_path, timestamp, publishing_app).once.returns(publish_intent)
Services.publishing_api.expects(:put_intent).once.with(base_path, publish_intent.as_json)
ContentObjectStore::PublishIntentWorker.new.perform(base_path, timestamp)
ContentObjectStore::PublishIntentWorker.new.perform(base_path, publishing_app, timestamp)
end
end

0 comments on commit 6c4f1dc

Please sign in to comment.