Skip to content

Commit

Permalink
WIP: sitewide settings calling the correct presenters
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraghiorghisor-tw committed Jun 12, 2024
1 parent 954bfb8 commit 0d1e1ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
13 changes: 7 additions & 6 deletions app/models/sitewide_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 26 additions & 16 deletions test/unit/app/models/sitewide_setting_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0d1e1ce

Please sign in to comment.