Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content modelling/550 fix cache busting #9459

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
@@ -1,4 +1,4 @@
module ContentObjectStore
class HostContentItem < Data.define(:title, :base_path, :document_type, :publishing_organisation)
class HostContentItem < Data.define(:title, :base_path, :document_type, :publishing_organisation, :publishing_app)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def items
base_path: item["base_path"],
document_type: item["document_type"],
publishing_organisation: item["primary_publishing_organisation"],
publishing_app: item["publishing_app"],
)
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 @@ -12,6 +12,7 @@ class ContentObjectStore::ContentBlock::Document::Show::HostEditionsTableCompone
"title" => "Some title",
"base_path" => "/foo",
"document_type" => "document_type",
"publishing_app" => "publisher",
"publishing_organisation" => {
"content_id" => SecureRandom.uuid,
"title" => "bar",
Expand Down Expand Up @@ -78,6 +79,7 @@ class ContentObjectStore::ContentBlock::Document::Show::HostEditionsTableCompone
title: "Some title",
base_path: "/foo",
document_type: "document_type",
publishing_app: "publisher",
publishing_organisation: {
"content_id" => SecureRandom.uuid,
"title" => nil,
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 @@ -16,6 +16,7 @@ class ContentObjectStore::GetHostContentItemsTest < ActiveSupport::TestCase
"title" => "foo",
"base_path" => "/foo",
"document_type" => "something",
"publishing_app" => "publisher",
"primary_publishing_organisation" => {
"content_id" => SecureRandom.uuid,
"title" => "bar",
Expand Down Expand Up @@ -63,6 +64,7 @@ class ContentObjectStore::GetHostContentItemsTest < ActiveSupport::TestCase
assert_equal result[0].title, response_body["results"][0]["title"]
assert_equal result[0].base_path, response_body["results"][0]["base_path"]
assert_equal result[0].document_type, response_body["results"][0]["document_type"]
assert_equal result[0].publishing_app, response_body["results"][0]["publishing_app"]
assert_equal result[0].publishing_organisation, expected_publishing_organisation
end

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
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