From 5c903044ab5b30e8d127630b8c06a64838e75c50 Mon Sep 17 00:00:00 2001 From: JonathanHallam Date: Wed, 11 Dec 2024 10:35:44 +0000 Subject: [PATCH 1/4] Include social media accounts on model --- app/models/editionable_topical_event.rb | 2 ++ test/factories/editionable_topical_events.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/app/models/editionable_topical_event.rb b/app/models/editionable_topical_event.rb index 6b509e92a8a..7dad56c9cfe 100644 --- a/app/models/editionable_topical_event.rb +++ b/app/models/editionable_topical_event.rb @@ -1,4 +1,6 @@ class EditionableTopicalEvent < Edition + include Edition::SocialMediaAccounts + def display_type_key "editionable_topical_event" end diff --git a/test/factories/editionable_topical_events.rb b/test/factories/editionable_topical_events.rb index 39aee5df63d..77bc229237d 100644 --- a/test/factories/editionable_topical_events.rb +++ b/test/factories/editionable_topical_events.rb @@ -5,4 +5,10 @@ end factory :draft_editionable_topical_event, parent: :editionable_topical_event, traits: [:draft] + + trait(:with_social_media_account) do + after :create do |organisation, _evaluator| + create(:social_media_account, socialable: organisation, social_media_service: create(:social_media_service, name: "Blog")) + end + end end From 152258bf2cde0a6090d145777d75aa80ad805b10 Mon Sep 17 00:00:00 2001 From: JonathanHallam Date: Wed, 11 Dec 2024 11:05:27 +0000 Subject: [PATCH 2/4] Present social media accounts to publishing API --- app/models/editionable_topical_event.rb | 2 +- .../editionable_topical_event_presenter.rb | 16 +++++++++++++++- .../editionable_topical_event_presenter_test.rb | 15 +++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/models/editionable_topical_event.rb b/app/models/editionable_topical_event.rb index 7dad56c9cfe..fd3bb567d3e 100644 --- a/app/models/editionable_topical_event.rb +++ b/app/models/editionable_topical_event.rb @@ -1,6 +1,6 @@ class EditionableTopicalEvent < Edition include Edition::SocialMediaAccounts - + def display_type_key "editionable_topical_event" end diff --git a/app/presenters/publishing_api/editionable_topical_event_presenter.rb b/app/presenters/publishing_api/editionable_topical_event_presenter.rb index 8206eb52ee8..8071f1323d1 100644 --- a/app/presenters/publishing_api/editionable_topical_event_presenter.rb +++ b/app/presenters/publishing_api/editionable_topical_event_presenter.rb @@ -35,8 +35,22 @@ def links {} end + private + def details - {} + {}.tap do |details| + details[:social_media_links] = social_media_links + end + end + + def social_media_links + item.social_media_accounts.map do |social_media_account| + { + href: social_media_account.url, + service_type: social_media_account.service_name.parameterize, + title: social_media_account.display_name, + } + end end end end diff --git a/test/unit/app/presenters/publishing_api/editionable_topical_event_presenter_test.rb b/test/unit/app/presenters/publishing_api/editionable_topical_event_presenter_test.rb index 8a9c05bce42..aec93ea8ae8 100644 --- a/test/unit/app/presenters/publishing_api/editionable_topical_event_presenter_test.rb +++ b/test/unit/app/presenters/publishing_api/editionable_topical_event_presenter_test.rb @@ -6,10 +6,21 @@ def present(...) end test "presents a Topical Event ready for adding to the publishing API" do - topical_event = create(:editionable_topical_event) + topical_event = create(:editionable_topical_event, + :with_social_media_account) public_path = topical_event.public_path + expected_details = { + social_media_links: [ + { + href: topical_event.social_media_accounts.first.url, + service_type: topical_event.social_media_accounts.first.service_name.parameterize, + title: topical_event.social_media_accounts.first.display_name, + }, + ], + } + expected_hash = { base_path: public_path, title: topical_event.title, @@ -22,7 +33,7 @@ def present(...) public_updated_at: topical_event.updated_at, routes: [{ path: public_path, type: "exact" }], redirects: [], - details: {}, + details: expected_details, update_type: "major", } From 75dfb285f2090946632f791ca8a4ef8320ff78b9 Mon Sep 17 00:00:00 2001 From: JonathanHallam Date: Wed, 11 Dec 2024 16:14:58 +0000 Subject: [PATCH 3/4] add editionable topical event translation --- config/locales/en.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index ca75a15a0ec..c3be1082342 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -193,6 +193,9 @@ en: edition: one: Edition other: Editions + editionable_topical_event: + one: Topical event + other: Topical events edition_with_appointment: one: Edition with appointment other: Editions with appointment From 47bdf90707ae053beb22f423a8a8b5e519a100a6 Mon Sep 17 00:00:00 2001 From: JonathanHallam Date: Wed, 11 Dec 2024 16:29:31 +0000 Subject: [PATCH 4/4] Create feature tests for social media accounts There were none already so i've had to create them I've borrowed pretty heavily from when we did the worldwide org work! --- features/editionable-topical-events.feature | 20 +++++++++++ .../editionable_topical_events_steps.rb | 34 +++++++++++++++++++ features/support/document_helper.rb | 8 +++++ 3 files changed, 62 insertions(+) create mode 100644 features/editionable-topical-events.feature create mode 100644 features/step_definitions/editionable_topical_events_steps.rb diff --git a/features/editionable-topical-events.feature b/features/editionable-topical-events.feature new file mode 100644 index 00000000000..dd05a09ce9d --- /dev/null +++ b/features/editionable-topical-events.feature @@ -0,0 +1,20 @@ +Feature: Topical events + Scenario Outline: Adding a social media account to an editionable topical event + Given a social media service "Facebook" exists + Given a topical event called "Test editionable topical event" with summary "A topical event" and description "A topical event" + And I edit the editionable topical event "Test editionable topical event" adding the social media service of "Facebook" with title "Our Facebook page" at URL "https://www.social.gov.uk" + Then I should see the "Our Facebook page" social media site has been assigned to the editionable topical event "Test editionable topical event" + + Scenario Outline: Editing a social media account to an editionable topical event + Given a social media service "Facebook" exists + Given a topical event called "Test editionable topical event" with summary "A topical event" and description "A topical event" + And I edit the editionable topical event "Test editionable topical event" adding the social media service of "Facebook" with title "Our Facebook page" at URL "https://www.social.gov.uk" + And I edit the editionable topical event "Test editionable topical event" changing the social media account with title "Our Facebook page" to "Our new Facebook page" + Then I should see the "Our new Facebook page" social media site has been assigned to the editionable topical event "Test editionable topical event" + + Scenario Outline: Deleting a social media account assigned to an editionable topical event + Given a social media service "Facebook" exists + Given a topical event called "Test editionable topical event" with summary "A topical event" and description "A topical event" + And I edit the editionable topical event "Test editionable topical event" adding the social media service of "Facebook" with title "Our Facebook page" at URL "https://www.social.gov.uk" + And I edit the editionable topical event "Test editionable topical event" deleting the social media account with title "Our Facebook page" + Then I should see the editionable topical event "Test editionable topical event" has no social media accounts \ No newline at end of file diff --git a/features/step_definitions/editionable_topical_events_steps.rb b/features/step_definitions/editionable_topical_events_steps.rb new file mode 100644 index 00000000000..c6a19b3a45d --- /dev/null +++ b/features/step_definitions/editionable_topical_events_steps.rb @@ -0,0 +1,34 @@ +And(/^I edit the topical event "([^"]*)" adding the social media service of "([^"]*)" with title "([^"]*)" at URL "([^"]*)"$/) do |title, social_media_service_name, social_media_title, social_media_url| + begin_editing_document(title) + click_link "Social media accounts" + click_link "Add new social media account" + select social_media_service_name, from: "Service (required)" + fill_in "URL (required)", with: social_media_url + fill_in "Title", with: social_media_title + click_button "Save" +end + +And(/^I edit the topical event "([^"]*)" changing the social media account with title "([^"]*)" to "([^"]*)"$/) do |title, _old_social_media_title, new_social_media_title| + begin_editing_document(title) + click_link "Social media accounts" + click_link "Edit" + fill_in "Title", with: new_social_media_title + click_button "Save" +end + +And(/^I edit the topical event "([^"]*)" deleting the social media account with title "([^"]*)"$/) do |title, _social_media_title| + begin_editing_document(title) + click_link "Social media accounts" + click_link "Delete" + click_button "Delete" +end + +Then(/^I should see the "([^"]*)" social media site has been assigned to the topical event "([^"]*)"$/) do |social_media_title, title| + @topical_event = EditionableTopicalEvent.find_by(title:) + expect(@topical_event.social_media_accounts.first.title).to eq(social_media_title) +end + +Then(/^I should see the topical event "([^"]*)" has no social media accounts$/) do |title| + @topical_event = EditionableTopicalEvent.find_by(title:) + expect(@topical_event.social_media_accounts).to be_empty +end diff --git a/features/support/document_helper.rb b/features/support/document_helper.rb index 277812775e1..101571d5016 100644 --- a/features/support/document_helper.rb +++ b/features/support/document_helper.rb @@ -122,6 +122,12 @@ def begin_drafting_worldwide_organisation(options) fill_in_worldwide_organisation_fields(**options.slice(:world_location)) end + def begin_drafting_editionable_topical_event(options) + begin_drafting_document options.merge(type: "editionable_topical_event") + + fill_in_editionable_topical_event_fields(**options.slice(:topical_event)) + end + def pdf_attachment Rails.root.join("features/fixtures/attachment.pdf") end @@ -131,6 +137,8 @@ def fill_in_worldwide_organisation_fields(world_location: "United Kingdom") fill_in "Logo formatted name", with: "Logo\r\nformatted\r\nname\r\n" end + def fill_in_editionable_topical_event_fields; end + def fill_in_news_article_fields(first_published: "2010-01-01", announcement_type: "News story") select announcement_type, from: "News article type" checkbox_label = "This document has previously been published on another website"