diff --git a/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb b/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb index a85e4598d770..20dcc818a11c 100644 --- a/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb +++ b/app/presenters/publishing_api/editionable_worldwide_organisation_presenter.rb @@ -4,6 +4,7 @@ class EditionableWorldwideOrganisationPresenter include ActionView::Helpers::UrlHelper include ApplicationHelper include OrganisationHelper + include Presenters::PublishingApi::DefaultNewsImageHelper attr_accessor :item, :update_type, :state @@ -23,19 +24,7 @@ def content content.merge!( description: item.summary, - details: { - body:, - logo: { - crest: "single-identity", - formatted_title: worldwide_organisation_logo_name(item), - }, - ordered_corporate_information_pages:, - secondary_corporate_information_pages:, - office_contact_associations:, - people_role_associations:, - social_media_links:, - world_location_names:, - }, + details:, document_type:, links: edition_links, public_updated_at: item.updated_at, @@ -80,6 +69,24 @@ def body end end + def details + details = { + body:, + logo: { + crest: "single-identity", + formatted_title: worldwide_organisation_logo_name(item), + }, + ordered_corporate_information_pages:, + secondary_corporate_information_pages:, + office_contact_associations:, + people_role_associations:, + social_media_links:, + world_location_names:, + } + details[:default_news_image] = present_default_news_image(item) if present_default_news_image(item).present? + details + end + def office_staff item.office_staff_roles.map(&:current_person).map(&:content_id) end diff --git a/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb b/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb index 8278a2da57cf..2d0c81f604c4 100644 --- a/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/editionable_worldwide_organisation_presenter_test.rb @@ -12,6 +12,7 @@ def present(...) :with_main_office, :with_home_page_offices, :with_pages, + :with_default_news_image, analytics_identifier: "WO123") primary_role = create(:ambassador_role) @@ -44,6 +45,10 @@ def present(...) description: worldwide_org.summary, details: { body: "

Information about the organisation with italics.

\n
", + default_news_image: { + url: worldwide_org.default_news_image.file.url(:s300), + high_resolution_url: worldwide_org.default_news_image.file.url(:s960), + }, logo: { crest: "single-identity", formatted_title: "Editionable
worldwide
organisation
title", @@ -183,4 +188,28 @@ def present(...) assert_equal [lead_organisation_2.content_id, lead_organisation_1.content_id], presented_item.content.dig(:links, :sponsoring_organisations) end + + test "is valid against the schema when there is no default_news_image" do + worldwide_organisation = create(:editionable_worldwide_organisation, default_news_image: nil) + + presented_item = present(worldwide_organisation) + + assert_valid_against_publisher_schema(presented_item.content, "worldwide_organisation") + end + + test "default_news_image is not present when there is no image" do + worldwide_organisation = create(:editionable_worldwide_organisation, default_news_image: nil) + presented_item = present(worldwide_organisation) + + assert_not presented_item.content[:details].key? :default_news_image + end + + test "default_news_image is not present when variants are not uploaded" do + featured_image = build(:featured_image_data) + featured_image.assets.destroy_all + worldwide_organisation = create(:editionable_worldwide_organisation, default_news_image: featured_image) + presented_item = present(worldwide_organisation) + + assert_not presented_item.content[:details].key? :default_news_image + end end