Skip to content

Commit

Permalink
Add test for double replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraghiorghisor-tw committed Jan 9, 2025
1 parent f9364b7 commit 7bfb40c
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion test/integration/attachment_replacement_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class AttachmentReplacementIntegrationTest < ActionDispatch::IntegrationTest
describe "attachment replacement" do
let(:managing_editor) { create(:managing_editor) }
let(:filename) { "sample.csv" }
let(:asset_manager_id) { "asset_manager_id" }
let(:replacement_filename) { "sample.rtf" }
let(:double_replacement_filename) { "sample.docx" }
let(:asset_manager_id) { "asset_manager_id" }
let(:replacement_asset_manager_id) { "replacement-asset-id" }
let(:double_replacement_asset_manager_id) { "double-replacement-asset-id" }
let(:variant) { Asset.variants[:original] }
let(:attachment) { build(:csv_attachment, title: "attachment-title", attachable: edition) }

Expand Down Expand Up @@ -92,6 +94,71 @@ class AttachmentReplacementIntegrationTest < ActionDispatch::IntegrationTest
AssetManagerAttachmentMetadataWorker.drain
end
end

context "when new draft is created and attachment is replaced twice" do
before do

[
{ id: replacement_asset_manager_id, filename: replacement_filename },
{ id: double_replacement_asset_manager_id, filename: double_replacement_filename }].each do |item|
Services.asset_manager.expects(:create_asset).with { |args|
args[:file].path =~ /#{item[:filename]}/
}.returns("id" => "http://asset-manager/assets/#{item[:id]}", "name" => item[:filename])
end
stub_asset(double_replacement_asset_manager_id)

Sidekiq::Job.clear_all
end

it "updates replacement_id for attachment in Asset Manager" do
visit admin_news_article_path(edition)
click_button "Create new edition"
# choose "No – it’s a minor edit that does not change the meaning"
# click_button "Save"

AssetManagerCreateAssetWorker.drain
PublishingApiDraftUpdateWorker.drain
AssetManagerAttachmentMetadataWorker.drain

Services.asset_manager.expects(:update_asset)
.times(3)
.with(asset_manager_id, { "replacement_id" => replacement_asset_manager_id })
Services.asset_manager.expects(:update_asset)
.times(3)
.with(replacement_asset_manager_id, has_entry({ "draft" => true }))

click_link "Attachments 1"
within page.find("li", text: filename) do
click_link "Edit attachment"
end
attach_file "Replace file", path_to_attachment(replacement_filename)
click_button "Save"
assert_text "Attachment 'attachment-title' updated"

AssetManagerCreateAssetWorker.drain
PublishingApiDraftUpdateWorker.drain
AssetManagerAttachmentMetadataWorker.drain


Services.asset_manager.expects(:update_asset)
.times(3)
.with(replacement_asset_manager_id, { "replacement_id" => double_replacement_asset_manager_id })
Services.asset_manager.expects(:update_asset)
.times(3)
.with(double_replacement_asset_manager_id, has_entry({ "draft" => true }))

within page.find("li", text: replacement_filename) do
click_link "Edit attachment"
end
attach_file "Replace file", path_to_attachment(double_replacement_filename)
click_button "Save"
assert_text "Attachment 'attachment-title' updated"

AssetManagerCreateAssetWorker.drain
PublishingApiDraftUpdateWorker.drain
AssetManagerAttachmentMetadataWorker.drain
end
end
end

private
Expand Down

0 comments on commit 7bfb40c

Please sign in to comment.