diff --git a/app/helpers/admin/republishing_helper.rb b/app/helpers/admin/republishing_helper.rb
index f751f580ef9..f4a7310a65c 100644
--- a/app/helpers/admin/republishing_helper.rb
+++ b/app/helpers/admin/republishing_helper.rb
@@ -3,6 +3,13 @@ module Admin::RepublishingHelper
def bulk_content_type_metadata
@bulk_content_type_metadata ||= {
+ all_documents: {
+ id: "all-documents",
+ name: "all documents",
+ republishing_path: admin_bulk_republishing_all_republish_path("all-documents"),
+ confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents"),
+ republish_method: -> { BulkRepublisher.new.republish_all_documents },
+ },
all_organisation_about_us_pages: {
id: "all-organisation-about-us-pages",
name: "all organisation 'About Us' pages",
diff --git a/app/models/republishing_event.rb b/app/models/republishing_event.rb
index 3d636b39923..181894bbdcc 100644
--- a/app/models/republishing_event.rb
+++ b/app/models/republishing_event.rb
@@ -9,6 +9,7 @@ class RepublishingEvent < ApplicationRecord
validates :bulk_content_type, presence: true, if: -> { bulk }
enum :bulk_content_type, %i[
+ all_documents
all_organisation_about_us_pages
]
end
diff --git a/app/services/bulk_republisher.rb b/app/services/bulk_republisher.rb
index 877212e2fbf..427791cb692 100644
--- a/app/services/bulk_republisher.rb
+++ b/app/services/bulk_republisher.rb
@@ -10,4 +10,10 @@ def republish_all_organisation_about_us_pages
)
end
end
+
+ def republish_all_documents
+ Document.find_each do |document|
+ PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document.id, true)
+ end
+ end
end
diff --git a/features/bulk-republishing-content.feature b/features/bulk-republishing-content.feature
index c9b45f43b67..670ddd20078 100644
--- a/features/bulk-republishing-content.feature
+++ b/features/bulk-republishing-content.feature
@@ -6,7 +6,12 @@ Feature: Bulk republishing content
Background:
Given I am a GDS admin
+ Scenario: Republish all documents
+ Given Documents exist
+ When I request a bulk republishing of all documents
+ Then I can see that all documents have been queued for republishing
+
Scenario: Republish all Organisation "About Us" pages
- Given Published Organisation "About Us" pages exist
+ Given Organisation "About Us" pages exist
When I request a bulk republishing of the Organisation "About Us" pages
Then I can see the Organisation "About Us" pages have been queued for republishing
diff --git a/features/step_definitions/bulk_republishing_content_steps.rb b/features/step_definitions/bulk_republishing_content_steps.rb
index 9eb89010373..6de2704d40b 100644
--- a/features/step_definitions/bulk_republishing_content_steps.rb
+++ b/features/step_definitions/bulk_republishing_content_steps.rb
@@ -1,4 +1,19 @@
-Given(/^Published Organisation "About Us" pages exist$/) do
+Given(/^Documents exist$/) do
+ 2.times { create(:document) }
+end
+
+When(/^I request a bulk republishing of all documents$/) do
+ visit admin_republishing_index_path
+ find("#all-documents").click
+ fill_in "What is the reason for republishing?", with: "It needs republishing"
+ click_button("Confirm republishing")
+end
+
+Then(/^I can see that all documents have been queued for republishing$/) do
+ expect(page).to have_selector(".gem-c-success-alert", text: "All documents have been queued for republishing")
+end
+
+Given(/^Organisation "About Us" pages exist$/) do
2.times { create(:about_corporate_information_page) }
end
diff --git a/test/functional/admin/republishing_controller_test.rb b/test/functional/admin/republishing_controller_test.rb
index aa37c72e47b..884d653dd95 100644
--- a/test/functional/admin/republishing_controller_test.rb
+++ b/test/functional/admin/republishing_controller_test.rb
@@ -19,7 +19,8 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
assert_select ".govuk-table:nth-of-type(2) .govuk-table__body .govuk-table__row:nth-child(3) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/role/find']", text: "Republish a role"
assert_select ".govuk-table:nth-of-type(2) .govuk-table__body .govuk-table__row:nth-child(4) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/document/find']", text: "Republish a document"
- assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-organisation-about-us-pages/confirm']", text: "Republish all organisation 'About Us' pages"
+ assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(1) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-documents/confirm']", text: "Republish all documents"
+ assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(2) .govuk-table__cell:nth-child(2) a[href='/government/admin/republishing/bulk/all-organisation-about-us-pages/confirm']", text: "Republish all organisation 'About Us' pages"
assert_response :ok
end
diff --git a/test/unit/app/helpers/admin/republishing_helper_test.rb b/test/unit/app/helpers/admin/republishing_helper_test.rb
index e7f27e4457f..8081186b32e 100644
--- a/test/unit/app/helpers/admin/republishing_helper_test.rb
+++ b/test/unit/app/helpers/admin/republishing_helper_test.rb
@@ -6,11 +6,11 @@ class Admin::RepublishingHelperTest < ActionView::TestCase
end
test "#republishing_index_bulk_republishing_rows capitalises the first letter of the bulk content type" do
- assert_equal @first_row.first[:text], "All organisation 'About Us' pages"
+ assert_equal @first_row.first[:text], "All documents"
end
test "#republishing_index_bulk_republishing_rows creates a link to the specific bulk republishing confirmation page" do
- expected_link = 'Republish all organisation \'About Us\' pages'
+ expected_link = 'Republish all documents'
assert_equal @first_row[1][:text], expected_link
end
end
diff --git a/test/unit/app/services/bulk_republisher_test.rb b/test/unit/app/services/bulk_republisher_test.rb
index 3703a016878..81b46520bbc 100644
--- a/test/unit/app/services/bulk_republisher_test.rb
+++ b/test/unit/app/services/bulk_republisher_test.rb
@@ -19,4 +19,21 @@ class BulkRepublisherTest < ActiveSupport::TestCase
BulkRepublisher.new.republish_all_organisation_about_us_pages
end
end
+
+ describe "#republish_all_documents" do
+ test "queues all documents for republishing" do
+ queue_sequence = sequence("queue")
+
+ 2.times do
+ document = create(:document)
+
+ PublishingApiDocumentRepublishingWorker
+ .expects(:perform_async_in_queue)
+ .with("bulk_republishing", document.id, true)
+ .in_sequence(queue_sequence)
+ end
+
+ BulkRepublisher.new.republish_all_documents
+ end
+ end
end