Skip to content

Commit

Permalink
Add test for withdrawal sync rather than async
Browse files Browse the repository at this point in the history
  • Loading branch information
GDSNewt committed Feb 6, 2025
1 parent 6c32f3a commit 4ae8543
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ class AttachmentRedirectDueToUnpublishingIntegrationTest < ActionDispatch::Integ
end

context "given a published document with HTML attachment" do
let(:edition) { create(:published_publication, :with_html_attachment) }
let(:edition) { create(:published_publication, :with_alternative_format_provider) }

it "unpublishes the HTML attachment when the document is unpublished" do
visit admin_publication_path(edition)
assert_redirected_in_publishing_api(edition.html_attachments.first.content_id, redirect_path)
assert_redirected_in_publishing_api(edition.document.content_id, "")
assert_redirected_in_publishing_api_html(edition.html_attachments.first.content_id, redirect_path)

unpublish_document_published_in_error
assert_sets_redirect_url_in_asset_manager_to redirect_url
Expand Down Expand Up @@ -188,6 +189,20 @@ def assert_sets_redirect_url_in_asset_manager_to(redirect_url)
end

def assert_redirected_in_publishing_api(content_id, redirect_path)
Services.publishing_api.expects(:unpublish)
.with(
content_id,
type: "gone",
alternative_path: redirect_path,
locale: "en",
allow_draft: false,
discard_drafts: true,
explanation: nil,
)
.once
end

def assert_redirected_in_publishing_api_html(content_id, redirect_path)
Services.publishing_api.expects(:unpublish)
.with(
content_id,
Expand Down
13 changes: 13 additions & 0 deletions test/unit/lib/whitehall/publishing_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,19 @@ class Whitehall::PublishingApiTest < ActiveSupport::TestCase
Whitehall::PublishingApi.unpublish_sync(unpublishing)
end

test ".publish_withdrawal_sync immediately runs a PublishingApiWithdrawalWorker job for the withdrawal" do
document_content_id = "12345"
explanation = "This document has been withdrawn"
unpublished_at = Time.zone.now
locale = "en"

stubbed_worker = stub("worker", perform: nil)
PublishingApiWithdrawalWorker.expects(:new).returns(stubbed_worker)
stubbed_worker.expects(:perform).with(document_content_id, explanation, locale.to_s, false, unpublished_at.to_s)

Whitehall::PublishingApi.publish_withdrawal_sync(document_content_id, explanation, unpublished_at, locale)
end

test ".publish handles the specific exception" do
raises_exception = lambda { |_, _, _|
body = {
Expand Down

0 comments on commit 4ae8543

Please sign in to comment.