Skip to content

Commit

Permalink
Merge pull request #9790 from alphagov/fix-worldwide-org-contact-unpu…
Browse files Browse the repository at this point in the history
…blishing

Ensure worldwide org office contacts are unpublished effectively
  • Loading branch information
ryanb-gds authored Jan 8, 2025
2 parents 664d2c7 + 6eb380f commit ec419f9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,30 @@ def unpublish(allow_draft: false)
end

current_associated_documents.each do |associated_document|
if associated_document.respond_to?(:translations)
associated_document.translations.each do |translation|
locales_to_unpublish =
if associated_document.respond_to?(:translations)
associated_document.translations.map(&:locale).map(&:to_s)
else
[locale_for_document(associated_document).to_s]
end

locales_to_unpublish.each do |locale|
if associated_document.respond_to?(:base_path)
PublishingApiRedirectWorker.new.perform(
associated_document.content_id,
destination,
translation.locale.to_s,
locale,
allow_draft,
)
else
PublishingApiGoneWorker.new.perform(
associated_document.content_id,
nil,
nil,
locale,
allow_draft,
)
end
else
PublishingApiRedirectWorker.new.perform(
associated_document.content_id,
destination,
locale_for_document(associated_document).to_s,
allow_draft,
)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/factories/worldwide_offices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
factory :worldwide_office do
transient do
title { "Contact title" }
translated_into { nil }
end
sequence(:slug) { |index| "worldwide-office-#{index}" }
content_id { SecureRandom.uuid }
contact { create :contact_with_country, title: }
contact { create :contact_with_country, title:, translated_into: }
edition { create :worldwide_organisation }
worldwide_office_type_id { WorldwideOfficeType.all.sample.id }
end
Expand Down
6 changes: 6 additions & 0 deletions test/factories/worldwide_organisations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
end
end

trait(:with_translated_main_office) do
after :create do |organisation, _evaluator|
FactoryBot.create(:worldwide_office, edition: organisation, translated_into: :fr)
end
end

trait(:with_home_page_offices) do
after :create do |organisation, _evaluator|
worldwide_office = create(:worldwide_office, edition: organisation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,29 @@ class Unpublish < PublishingApiAssociatedDocumentsTest
call(worldwide_organisation)
end

test "for an worldwide organisation that has been unpublished publishes a gone unpublishing for all the office contact translations" do
worldwide_organisation = create(:unpublished_worldwide_organisation, :with_translated_main_office, translated_into: :fr)
office = worldwide_organisation.main_office

PublishingApiGoneWorker.any_instance.expects(:perform).with(
office.contact.content_id,
nil,
nil,
"en",
false,
)

PublishingApiGoneWorker.any_instance.expects(:perform).with(
office.contact.content_id,
nil,
nil,
"fr",
false,
)

call(worldwide_organisation)
end

test "for an worldwide organisation that has been consolidated publishes a redirect to the alternative url" do
worldwide_organisation = create(:unpublished_worldwide_organisation_consolidated, :with_main_office, :with_page)
office = worldwide_organisation.main_office
Expand All @@ -493,9 +516,10 @@ class Unpublish < PublishingApiAssociatedDocumentsTest
false,
)

PublishingApiRedirectWorker.any_instance.expects(:perform).with(
PublishingApiGoneWorker.any_instance.expects(:perform).with(
office.contact.content_id,
"/government/another/page",
nil,
nil,
"en",
false,
)
Expand Down Expand Up @@ -533,9 +557,10 @@ class Unpublish < PublishingApiAssociatedDocumentsTest
false,
)

PublishingApiRedirectWorker.any_instance.expects(:perform).with(
PublishingApiGoneWorker.any_instance.expects(:perform).with(
office.contact.content_id,
"/government/another/page",
nil,
nil,
"en",
false,
)
Expand Down Expand Up @@ -569,9 +594,10 @@ class Unpublish < PublishingApiAssociatedDocumentsTest
false,
)

PublishingApiRedirectWorker.any_instance.expects(:perform).with(
PublishingApiGoneWorker.any_instance.expects(:perform).with(
office.contact.content_id,
external_url,
nil,
nil,
"en",
false,
)
Expand Down Expand Up @@ -610,9 +636,10 @@ class Unpublish < PublishingApiAssociatedDocumentsTest
false,
)

PublishingApiRedirectWorker.any_instance.expects(:perform).with(
PublishingApiGoneWorker.any_instance.expects(:perform).with(
office.contact.content_id,
worldwide_organisation.search_link,
nil,
nil,
"en",
false,
)
Expand Down

0 comments on commit ec419f9

Please sign in to comment.