Skip to content

Commit

Permalink
Merge pull request #9086 from alphagov/add-ww-org-auth-bypass
Browse files Browse the repository at this point in the history
Present `auth_bypass_ids` for Editionable Worldwide Organisations and their associated documents
brucebolt authored May 30, 2024
2 parents 41fe244 + 2e9bdca commit 18b455a
Showing 6 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ def content
public_updated_at: item.updated_at,
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND,
schema_name: "worldwide_organisation",
auth_bypass_ids: [item.auth_bypass_id],
)
content.merge!(PayloadBuilder::PolymorphicPath.for(item))
content.merge!(PayloadBuilder::AnalyticsIdentifier.for(item))
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ def content
schema_name: "worldwide_office",
)

content.merge!(auth_bypass_ids: [item.edition.auth_bypass_id]) if item.edition
content.merge!(PayloadBuilder::PolymorphicPath.for(item))
end

Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ def content
schema_name: "worldwide_corporate_information_page",
document_type:,
links: edition_links,
auth_bypass_ids: [item.edition.auth_bypass_id],
)

content.merge!(PayloadBuilder::PolymorphicPath.for(item))
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ def present(...)
public_path = worldwide_org.public_path

expected_hash = {
auth_bypass_ids: [worldwide_org.auth_bypass_id],
base_path: public_path,
title: worldwide_org.title,
schema_name: "worldwide_organisation",
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ def present(...)
PublishingApi::WorldwideOfficePresenter.new(...)
end

test "presents a Worldwide Office ready for adding to the publishing API" do
test "presents a Worldwide Office belonging to a non-editionable worldwide organisation ready for adding to the publishing API" do
access_and_opening_times = "## About us\r\n\r\nVisit our [profile page](https://www.gov.uk/government/world/organisations/british-consulate-general-atlanta)"
worldwide_office = build(:worldwide_office, access_and_opening_times:)
worldwide_office_service = create(:worldwide_office_worldwide_service, worldwide_office:)
@@ -59,6 +59,61 @@ def present(...)
assert_valid_against_links_schema({ links: presented_item.links }, "worldwide_office")
end

test "presents a Worldwide Office belonging to an editionable worldwide organisation ready for adding to the publishing API" do
access_and_opening_times = "## About us\r\n\r\nVisit our [profile page](https://www.gov.uk/government/world/organisations/british-consulate-general-atlanta)"
worldwide_office = build(:worldwide_office, access_and_opening_times:, worldwide_organisation: nil, edition: create(:editionable_worldwide_organisation))
worldwide_office_service = create(:worldwide_office_worldwide_service, worldwide_office:)
public_path = worldwide_office.public_path

expected_hash = {
auth_bypass_ids: [worldwide_office.edition.auth_bypass_id],
base_path: public_path,
title: worldwide_office.worldwide_organisation.name,
schema_name: "worldwide_office",
document_type: "worldwide_office",
locale: "en",
publishing_app: Whitehall::PublishingApp::WHITEHALL,
rendering_app: Whitehall::RenderingApp::GOVERNMENT_FRONTEND,
public_updated_at: worldwide_office.updated_at,
routes: [{ path: public_path, type: "exact" }],
redirects: [],
details: {
access_and_opening_times: Whitehall::GovspeakRenderer.new.govspeak_to_html(worldwide_office.access_and_opening_times),
services: [
{
title: worldwide_office_service.worldwide_service.name,
type: worldwide_office_service.worldwide_service.service_type.name,
},
],
type: worldwide_office.worldwide_office_type.name,
},
update_type: "major",
links: {
contact: [
worldwide_office.contact.content_id,
],
parent: [
worldwide_office.worldwide_organisation.content_id,
],
worldwide_organisation: [
worldwide_office.worldwide_organisation.content_id,
],
},
}

expected_links = {}

presented_item = present(worldwide_office)

assert_equal expected_hash, presented_item.content
assert_hash_includes presented_item.links, expected_links
assert_equal "major", presented_item.update_type
assert_equal worldwide_office.content_id, presented_item.content_id

assert_valid_against_publisher_schema(presented_item.content, "worldwide_office")
assert_valid_against_links_schema({ links: presented_item.links }, "worldwide_office")
end

test "sets access_and_opening_times as nil when they are blank" do
worldwide_office = create(:worldwide_office)

Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ class BasicWorldwideOrganisationPageTest < TestCase
public_path = page.public_path

expected_hash = {
auth_bypass_ids: [page.edition.auth_bypass_id],
base_path: public_path,
title: page.title,
schema_name: "worldwide_corporate_information_page",

0 comments on commit 18b455a

Please sign in to comment.