Skip to content

Commit

Permalink
Present auth_bypass_ids for editionable worldwide organisation offices
Browse files Browse the repository at this point in the history
These values were missed from the presenter. By sending them to
Publishing API, we are able to offer a shareable preview feature to
publishers.

We are using the `auth_bypass_id` from the parents worldwide
organisation to create a seemless journey where users only need a single
token to see all offices that are part of the organisation.

This presenter is used for worldwide offices that are associated with
both editionable and non-editionable worldwide organisations. Therefore
adding a test case for editionable worldwide organisations that was
missing.
  • Loading branch information
brucebolt committed May 29, 2024
1 parent b5cb469 commit abf79ca
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 worldwid 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:)
Expand Down Expand Up @@ -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 worldwid 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)

Expand Down

0 comments on commit abf79ca

Please sign in to comment.