Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI for republishing all documents with pre-publication editions #9092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/helpers/admin/republishing_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def bulk_content_type_metadata
confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents"),
republish_method: -> { BulkRepublisher.new.republish_all_documents },
},
all_documents_with_pre_publication_editions: {
id: "all-documents-with-pre-publication-editions",
name: "all documents with pre-publication editions",
republishing_path: admin_bulk_republishing_all_republish_path("all-documents-with-pre-publication-editions"),
confirmation_path: admin_bulk_republishing_all_confirm_path("all-documents-with-pre-publication-editions"),
republish_method: -> { BulkRepublisher.new.republish_all_documents_with_pre_publication_editions },
},
all_organisation_about_us_pages: {
id: "all-organisation-about-us-pages",
name: "all organisation 'About Us' pages",
Expand Down
1 change: 1 addition & 0 deletions app/models/republishing_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class RepublishingEvent < ApplicationRecord
enum :bulk_content_type, %i[
all_documents
all_organisation_about_us_pages
all_documents_with_pre_publication_editions
]
end
8 changes: 8 additions & 0 deletions app/services/bulk_republisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ def republish_all_documents
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", document.id, true)
end
end

def republish_all_documents_with_pre_publication_editions
editions = Edition.in_pre_publication_state.includes(:document)

editions.find_each do |edition|
PublishingApiDocumentRepublishingWorker.perform_async_in_queue("bulk_republishing", edition.document.id, true)
end
end
end
5 changes: 5 additions & 0 deletions features/bulk-republishing-content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Feature: Bulk republishing content
When I request a bulk republishing of all documents
Then I can see that all documents have been queued for republishing

Scenario: Republish all documents with pre-publication editions
Given Documents with pre-publication editions exist
When I request a bulk republishing of all documents with pre-publication editions
Then I can see that all documents with pre-publication editions have been queued for republishing

Scenario: Republish all Organisation "About Us" pages
Given Organisation "About Us" pages exist
When I request a bulk republishing of the Organisation "About Us" pages
Expand Down
15 changes: 15 additions & 0 deletions features/step_definitions/bulk_republishing_content_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@
expect(page).to have_selector(".gem-c-success-alert", text: "All documents have been queued for republishing")
end

Given(/^Documents with pre-publication editions exist$/) do
2.times { create(:document, editions: [build(:published_edition), build(:draft_edition)]) }
end

When(/^I request a bulk republishing of all documents with pre-publication editions$/) do
visit admin_republishing_index_path
find("#all-documents-with-pre-publication-editions").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 with pre-publication editions have been queued for republishing$/) do
expect(page).to have_selector(".gem-c-success-alert", text: "All documents with pre-publication editions have been queued for republishing")
end

Given(/^Organisation "About Us" pages exist$/) do
2.times { create(:about_corporate_information_page) }
end
Expand Down
3 changes: 2 additions & 1 deletion test/functional/admin/republishing_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Admin::RepublishingControllerTest < ActionController::TestCase
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-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_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-documents-with-pre-publication-editions/confirm']", text: "Republish all documents with pre-publication editions"
assert_select ".govuk-table:nth-of-type(3) .govuk-table__body .govuk-table__row:nth-child(3) .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
Expand Down
24 changes: 24 additions & 0 deletions test/unit/app/services/bulk_republisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,28 @@ class BulkRepublisherTest < ActiveSupport::TestCase
BulkRepublisher.new.republish_all_documents
end
end

describe "#republish_all_documents_with_pre_publication_editions" do
test "queues all documents with pre-publication editions for republishing" do
document_without_pre_publication_edition = create(:document, editions: [build(:published_edition)])

PublishingApiDocumentRepublishingWorker
.expects(:perform_async_in_queue)
.with("bulk_republishing", document_without_pre_publication_edition.id, true)
.never

queue_sequence = sequence("queue")

2.times do
document_with_pre_publication_edition = create(:document, editions: [build(:published_edition), build(:draft_edition)])

PublishingApiDocumentRepublishingWorker
.expects(:perform_async_in_queue)
.with("bulk_republishing", document_with_pre_publication_edition.id, true)
.in_sequence(queue_sequence)
end

BulkRepublisher.new.republish_all_documents_with_pre_publication_editions
end
end
end
Loading