-
Notifications
You must be signed in to change notification settings - Fork 193
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 #8962 from alphagov/worldwide-organisation-pages-p…
…ublishing Worldwide organisation pages publishing
- Loading branch information
Showing
11 changed files
with
385 additions
and
18 deletions.
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
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
49 changes: 49 additions & 0 deletions
49
app/presenters/publishing_api/worldwide_organisation_page_presenter.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,49 @@ | ||
module PublishingApi | ||
class WorldwideOrganisationPagePresenter | ||
attr_accessor :item, :update_type | ||
|
||
def initialize(item, update_type: nil) | ||
self.item = item | ||
self.update_type = update_type || "major" | ||
end | ||
|
||
delegate :content_id, to: :item | ||
|
||
def content | ||
content = BaseItemPresenter.new( | ||
item, | ||
title: item.title, | ||
update_type:, | ||
).base_attributes | ||
|
||
content.merge!( | ||
details: { | ||
body: Whitehall::GovspeakRenderer.new.govspeak_with_attachments_to_html(item.body, item.attachments), | ||
}, | ||
description: item.summary, | ||
public_updated_at: item.updated_at, | ||
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND, | ||
schema_name: "worldwide_corporate_information_page", | ||
document_type:, | ||
links: edition_links, | ||
) | ||
|
||
content.merge!(PayloadBuilder::PolymorphicPath.for(item)) | ||
end | ||
|
||
def edition_links | ||
{ | ||
parent: [item.edition.content_id], | ||
worldwide_organisation: [item.edition.content_id], | ||
} | ||
end | ||
|
||
def links | ||
{} | ||
end | ||
|
||
def document_type | ||
item.display_type_key | ||
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
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
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
65 changes: 65 additions & 0 deletions
65
test/unit/app/presenters/publishing_api/worldwide_organisation_page_presenter_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,65 @@ | ||
require "test_helper" | ||
|
||
module PublishingApi::WorldwideOrganisationPagePresenterTest | ||
class TestCase < ActiveSupport::TestCase | ||
attr_accessor :page, :update_type | ||
|
||
def presented_page | ||
PublishingApi::WorldwideOrganisationPagePresenter.new( | ||
page, | ||
update_type:, | ||
) | ||
end | ||
|
||
class BasicWorldwideOrganisationPageTest < TestCase | ||
setup do | ||
self.page = create(:worldwide_organisation_page) | ||
end | ||
|
||
test "presents a Worldwide Organisation Page ready for adding to the publishing API" do | ||
public_path = page.public_path | ||
|
||
expected_hash = { | ||
base_path: public_path, | ||
title: page.title, | ||
schema_name: "worldwide_corporate_information_page", | ||
document_type: page.display_type_key, | ||
locale: "en", | ||
publishing_app: Whitehall::PublishingApp::WHITEHALL, | ||
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND, | ||
public_updated_at: page.updated_at, | ||
routes: [{ path: public_path, type: "exact" }], | ||
redirects: [], | ||
description: "Some summary", | ||
details: { | ||
body: "<div class=\"govspeak\"><p>Some body</p>\n</div>", | ||
}, | ||
update_type: "major", | ||
links: { | ||
parent: [page.edition.content_id], | ||
worldwide_organisation: [page.edition.content_id], | ||
}, | ||
} | ||
|
||
expected_links = { | ||
parent: [ | ||
page.edition.content_id, | ||
], | ||
worldwide_organisation: [ | ||
page.edition.content_id, | ||
], | ||
} | ||
|
||
presented_item = presented_page | ||
|
||
assert_equal expected_hash, presented_item.content | ||
assert_hash_includes presented_item.edition_links, expected_links | ||
assert_equal "major", presented_item.update_type | ||
assert_equal page.content_id, presented_item.content_id | ||
|
||
assert_valid_against_publisher_schema(presented_item.content, "worldwide_corporate_information_page") | ||
assert_valid_against_links_schema({ links: presented_item.edition_links }, "worldwide_corporate_information_page") | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.