diff --git a/app/models/sitewide_setting.rb b/app/models/sitewide_setting.rb index ae1cbd29211f..0c4fd154f564 100644 --- a/app/models/sitewide_setting.rb +++ b/app/models/sitewide_setting.rb @@ -17,11 +17,12 @@ def name def republish_downstream_if_reshuffle return unless key == "minister_reshuffle_mode" - payload = PublishingApi::MinistersIndexPresenter.new - - Services.publishing_api.put_content(payload.content_id, payload.content) - Services.publishing_api.publish(payload.content_id, nil, locale: "en") - - PresentPageToPublishingApiWorker.perform_async("PublishingApi::HowGovernmentWorksPresenter") + if on + PresentPageToPublishingApiWorker.perform_async("PublishingApi::HowGovernmentWorksEnableReshufflePresenter", true) + PresentPageToPublishingApiWorker.perform_async("PublishingApi::MinistersIndexEnableReshufflePresenter", true) + else + PresentPageToPublishingApiWorker.perform_async("PublishingApi::HowGovernmentWorksPresenter", true) + PresentPageToPublishingApiWorker.perform_async("PublishingApi::MinistersIndexPresenter", true) + end end end diff --git a/test/unit/app/models/sitewide_setting_test.rb b/test/unit/app/models/sitewide_setting_test.rb index 043402689f51..d2b82d774996 100644 --- a/test/unit/app/models/sitewide_setting_test.rb +++ b/test/unit/app/models/sitewide_setting_test.rb @@ -1,35 +1,45 @@ require "test_helper" class SitewideSettingTest < ActiveSupport::TestCase - test "toggling reshuffle mode republished the ministers index page" do - payload = PublishingApi::MinistersIndexPresenter.new + test "enabling reshuffle mode republishes custom ministers index and how government work pages" do + ministers_payload = PublishingApi::MinistersIndexEnableReshufflePresenter.new + how_gov_works_payload = PublishingApi::HowGovernmentWorksEnableReshufflePresenter.new - create(:sitewide_setting, key: :minister_reshuffle_mode, on: true) + Sidekiq::Testing.inline! do + create(:sitewide_setting, key: :minister_reshuffle_mode, on: true) + end requests = [ - stub_publishing_api_put_content(payload.content_id, payload.content), - stub_publishing_api_publish(payload.content_id, locale: "en", update_type: nil), + stub_publishing_api_put_content(ministers_payload.content_id, ministers_payload.content), + stub_publishing_api_patch_links(ministers_payload.content_id, ministers_payload.content), + stub_publishing_api_publish(ministers_payload.content_id, locale: "en", update_type: nil), + stub_publishing_api_put_content(how_gov_works_payload.content_id, how_gov_works_payload.content), + stub_publishing_api_patch_links(how_gov_works_payload.content_id, how_gov_works_payload.content), + stub_publishing_api_publish(how_gov_works_payload.content_id, locale: "en", update_type: nil), ] assert_all_requested(requests) end - # moved from duplicate file - test "should send the how government works page to publishing api when reshuffle mode is switched on" do - PresentPageToPublishingApi.any_instance.expects(:publish).with(PublishingApi::HowGovernmentWorksPresenter) - - Sidekiq::Testing.inline! do - create(:sitewide_setting, key: :minister_reshuffle_mode, on: true) - end - end + test "disabling reshuffle mode republishes ministers index and how government work pages" do + ministers_payload = PublishingApi::MinistersIndexPresenter.new + how_gov_works_payload = PublishingApi::HowGovernmentWorksPresenter.new - test "should send the how government works page to publishing api when reshuffle mode is switched off" do setting = create(:sitewide_setting, key: :minister_reshuffle_mode, on: true) - PresentPageToPublishingApi.any_instance.expects(:publish).with(PublishingApi::HowGovernmentWorksPresenter) - Sidekiq::Testing.inline! do setting.update!(on: false) end + + requests = [ + stub_publishing_api_put_content(ministers_payload.content_id, ministers_payload.content), + stub_publishing_api_patch_links(ministers_payload.content_id, ministers_payload.content), + stub_publishing_api_publish(ministers_payload.content_id, locale: "en", update_type: nil), + stub_publishing_api_put_content(how_gov_works_payload.content_id, how_gov_works_payload.content), + stub_publishing_api_patch_links(how_gov_works_payload.content_id, how_gov_works_payload.content), + stub_publishing_api_publish(how_gov_works_payload.content_id, locale: "en", update_type: nil), + ] + + assert_all_requested(requests) end end