diff --git a/app/controllers/admin/worldwide_offices_controller.rb b/app/controllers/admin/worldwide_offices_controller.rb index 7fefc642a82..2a312b0bcc2 100644 --- a/app/controllers/admin/worldwide_offices_controller.rb +++ b/app/controllers/admin/worldwide_offices_controller.rb @@ -50,6 +50,11 @@ def destroy title = @worldwide_office.title if @worldwide_office.destroy + if @worldwide_office.edition + PublishingApiDiscardDraftWorker.perform_async(@worldwide_office.content_id, I18n.default_locale.to_s) + PublishingApiDiscardDraftWorker.perform_async(@worldwide_office.contact.content_id, I18n.default_locale.to_s) + end + republish_draft_worldwide_organisation redirect_to admin_worldwide_organisation_worldwide_offices_path(@worldwide_organisation), notice: "#{title} has been deleted" else diff --git a/test/functional/admin/worldwide_offices_controller_test.rb b/test/functional/admin/worldwide_offices_controller_test.rb index 9b8f5bf53d1..0657d52a736 100644 --- a/test/functional/admin/worldwide_offices_controller_test.rb +++ b/test/functional/admin/worldwide_offices_controller_test.rb @@ -440,6 +440,23 @@ class Admin::WorldwideOfficesControllerTest < ActionController::TestCase } end + test "DELETE :destroy for an office attached to an editionable worldwide organisation discards draft of the office and the contact" do + feature_flags.switch! :editionable_worldwide_organisations, true + + office = create(:worldwide_office, edition: create(:draft_editionable_worldwide_organisation), worldwide_organisation: nil) + + PublishingApiDiscardDraftWorker.any_instance.expects(:perform).with(office.content_id, "en") + PublishingApiDiscardDraftWorker.any_instance.expects(:perform).with(office.contact.content_id, "en") + + Sidekiq::Testing.inline! do + delete :destroy, + params: { + id: office, + worldwide_organisation_id: office.edition, + } + end + end + private def create_worldwide_organisation_and_office