-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9447 from alphagov/550-cache-busting
content-modelling/550 cache busting
- Loading branch information
Showing
8 changed files
with
292 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
lib/engines/content_object_store/app/workers/content_object_store/publish_intent_worker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "sidekiq/api" | ||
|
||
module ContentObjectStore | ||
class PublishIntentWorker < WorkerBase | ||
sidekiq_options queue: :content_block_publishing | ||
|
||
def perform(base_path, publish_timestamp) | ||
publish_timestamp = Time.zone.parse(publish_timestamp) | ||
publish_intent = PublishingApi::PublishIntentPresenter.new(base_path, publish_timestamp) | ||
|
||
Services.publishing_api.put_intent(base_path, publish_intent.as_json) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,14 @@ class ContentObjectStore::ContentBlock::WorkflowTest < ActionDispatch::Integrati | |
"major", | ||
] | ||
|
||
fake_embedded_content_response = GdsApi::Response.new(stub("http_response", | ||
code: 200, body: { | ||
"total" => 0, | ||
"results" => [], | ||
}.to_json)) | ||
|
||
publishing_api_mock.expect :get_content_by_embedded_document, fake_embedded_content_response, [@content_id] | ||
|
||
Services.stub :publishing_api, publishing_api_mock do | ||
post content_object_store.publish_content_object_store_content_block_edition_path(id: edition.id), params: { | ||
id: edition.id, | ||
|
@@ -67,6 +75,86 @@ class ContentObjectStore::ContentBlock::WorkflowTest < ActionDispatch::Integrati | |
end | ||
end | ||
|
||
test "#publish creates publish intents for all host documents" do | ||
details = { | ||
foo: "Foo text", | ||
bar: "Bar text", | ||
} | ||
|
||
organisation = create(:organisation) | ||
document = create(:content_block_document, :email_address, content_id: @content_id, title: "Some Title") | ||
edition = create(:content_block_edition, document:, details:, organisation:) | ||
|
||
fake_put_content_response = GdsApi::Response.new( | ||
stub("http_response", code: 200, body: {}), | ||
) | ||
fake_publish_content_response = GdsApi::Response.new( | ||
stub("http_response", code: 200, body: {}), | ||
) | ||
|
||
publishing_api_mock = Minitest::Mock.new | ||
publishing_api_mock.expect :put_content, fake_put_content_response, [ | ||
@content_id, | ||
{ | ||
schema_name: "content_block_type", | ||
document_type: "content_block_type", | ||
publishing_app: "whitehall", | ||
title: "Some Title", | ||
details: { | ||
"foo" => "Foo text", | ||
"bar" => "Bar text", | ||
}, | ||
links: { | ||
primary_publishing_organisation: [organisation.content_id], | ||
}, | ||
}, | ||
] | ||
publishing_api_mock.expect :publish, fake_publish_content_response, [ | ||
@content_id, | ||
"major", | ||
] | ||
|
||
host_content = | ||
[ | ||
{ | ||
"title" => "Content title", | ||
"document_type" => "document", | ||
"base_path" => "/host-document", | ||
"content_id" => "1234abc", | ||
"primary_publishing_organisation" => { | ||
"content_id" => "456abc", | ||
"title" => "Organisation", | ||
"base_path" => "/organisation/org", | ||
}, | ||
}, | ||
] | ||
|
||
fake_embedded_content_response = GdsApi::Response.new(stub("http_response", | ||
code: 200, body: { | ||
"total" => 1, | ||
"results" => host_content, | ||
}.to_json)) | ||
|
||
publishing_api_mock.expect :get_content_by_embedded_document, fake_embedded_content_response, [@content_id] | ||
|
||
publishing_api_mock.expect :put_intent, {}, ["/host-document", | ||
{ | ||
publish_time: Time.zone.now, | ||
publishing_app: "whitehall", | ||
rendering_app: "government-frontend", | ||
routes: [{ path: "/host-document", type: "exact" }], | ||
}] | ||
|
||
Sidekiq::Testing.inline! do | ||
Services.stub :publishing_api, publishing_api_mock do | ||
post content_object_store.publish_content_object_store_content_block_edition_path(id: edition.id), params: { | ||
id: edition.id, | ||
} | ||
publishing_api_mock.verify | ||
end | ||
end | ||
end | ||
|
||
test "#update schedules the publication of an edition" do | ||
organisation = create(:organisation) | ||
|
||
|
@@ -145,6 +233,99 @@ class ContentObjectStore::ContentBlock::WorkflowTest < ActionDispatch::Integrati | |
assert_not_equal first_job_id, second_job_id | ||
end | ||
end | ||
|
||
test "#update creates publish intents for host content" do | ||
details = { | ||
foo: "Foo text", | ||
bar: "Bar text", | ||
} | ||
|
||
organisation = create(:organisation) | ||
document = create(:content_block_document, :email_address, content_id: @content_id, title: "Some Title") | ||
edition = create(:content_block_edition, document:, details:, organisation:) | ||
|
||
fake_put_content_response = GdsApi::Response.new( | ||
stub("http_response", code: 200, body: {}), | ||
) | ||
fake_publish_content_response = GdsApi::Response.new( | ||
stub("http_response", code: 200, body: {}), | ||
) | ||
|
||
publishing_api_mock = Minitest::Mock.new | ||
publishing_api_mock.expect :put_content, fake_put_content_response, [ | ||
@content_id, | ||
{ | ||
schema_name: "content_block_type", | ||
document_type: "content_block_type", | ||
publishing_app: "whitehall", | ||
title: "Another email", | ||
details: { | ||
"foo" => "[email protected]", | ||
"bar" => "edited", | ||
}, | ||
links: { | ||
primary_publishing_organisation: [organisation.content_id], | ||
}, | ||
}, | ||
] | ||
publishing_api_mock.expect :publish, fake_publish_content_response, [ | ||
@content_id, | ||
"major", | ||
] | ||
|
||
host_content = | ||
[ | ||
{ | ||
"title" => "Content title", | ||
"document_type" => "document", | ||
"base_path" => "/host-document", | ||
"content_id" => "1234abc", | ||
"primary_publishing_organisation" => { | ||
"content_id" => "456abc", | ||
"title" => "Organisation", | ||
"base_path" => "/organisation/org", | ||
}, | ||
}, | ||
] | ||
|
||
fake_embedded_content_response = GdsApi::Response.new(stub("http_response", | ||
code: 200, body: { | ||
"total" => 1, | ||
"results" => host_content, | ||
}.to_json)) | ||
|
||
publishing_api_mock.expect :get_content_by_embedded_document, fake_embedded_content_response, [@content_id] | ||
|
||
publishing_api_mock.expect :put_intent, {}, ["/host-document", | ||
{ | ||
publish_time: Time.zone.now, | ||
publishing_app: "whitehall", | ||
rendering_app: "government-frontend", | ||
routes: [{ path: "/host-document", type: "exact" }], | ||
}] | ||
|
||
Sidekiq::Testing.inline! do | ||
Services.stub :publishing_api, publishing_api_mock do | ||
patch content_object_store.content_object_store_content_block_edition_path(edition), params: { | ||
id: edition.id, | ||
schedule_publishing: "schedule", | ||
scheduled_at: { | ||
"scheduled_publication(3i)": "2", | ||
"scheduled_publication(2i)": "9", | ||
"scheduled_publication(1i)": "2024", | ||
"scheduled_publication(4i)": "10", | ||
"scheduled_publication(5i)": "05", | ||
}, | ||
"content_block/edition": { | ||
creator: "1", | ||
details: { foo: "[email protected]", bar: "edited" }, | ||
document_attributes: { block_type: "email_address", title: "Another email" }, | ||
organisation_id: organisation.id, | ||
}, | ||
} | ||
end | ||
end | ||
end | ||
end | ||
|
||
def stub_request_for_schema(block_type) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
lib/engines/content_object_store/test/unit/app/workers/publish_intent_worker_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "test_helper" | ||
|
||
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 | ||
publish_intent = { foo: "bar" } | ||
|
||
PublishingApi::PublishIntentPresenter.expects(:new).with(base_path, timestamp).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) | ||
end | ||
end |
File renamed without changes.