Skip to content

Commit

Permalink
Include default_news_image for editionable worldwide organisation
Browse files Browse the repository at this point in the history
This attribute is included in the presenter for non-editionable
worldwide organisations, but not the editionable worldwide organisation.

Therefore adding it to the presenter and copying the tests that are
included for the non-editionable presenter.
  • Loading branch information
brucebolt committed Apr 29, 2024
1 parent bc53cfa commit 7e6a67e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class EditionableWorldwideOrganisationPresenter
include ActionView::Helpers::UrlHelper
include ApplicationHelper
include OrganisationHelper
include Presenters::PublishingApi::DefaultNewsImageHelper

attr_accessor :item, :update_type, :state

Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -44,6 +45,10 @@ def present(...)
description: worldwide_org.summary,
details: {
body: "<div class=\"govspeak\"><p>Information about the organisation with <em>italics</em>.</p>\n</div>",
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<br/>worldwide<br/>organisation<br/>title",
Expand Down Expand Up @@ -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

0 comments on commit 7e6a67e

Please sign in to comment.