diff --git a/modules/simple_forms_api/app/services/simple_forms_api/form_remediation/s3_client.rb b/modules/simple_forms_api/app/services/simple_forms_api/form_remediation/s3_client.rb index c0be4e9dfb6..d991b3cc40f 100644 --- a/modules/simple_forms_api/app/services/simple_forms_api/form_remediation/s3_client.rb +++ b/modules/simple_forms_api/app/services/simple_forms_api/form_remediation/s3_client.rb @@ -41,6 +41,12 @@ def upload config.handle_error("Failed #{upload_type} upload: #{id}", e) end + def retrieve_presigned_url + archive = config.submission_archive_class.new(config:, id:, type: upload_type) + @archive_path, @manifest_row = archive.retrieval_data + generate_presigned_url(type: upload_type) + end + private attr_reader :archive_path, :config, :id, :manifest_row, :parent_dir, :temp_directory_path, :upload_type @@ -117,12 +123,6 @@ def generate_presigned_url(type: upload_type) s3_uploader.get_s3_link(s3_upload_file_path(type)) end - def retrieve_presigned_url - archive = config.submission_archive_class.new(config:, id:, type: upload_type) - @archive_path, @manifest_row = archive.retrieval_data - generate_presigned_url(type: upload_type) - end - def s3_upload_file_path(type) extension = File.extname(archive_path) ext = type == :submission ? '.pdf' : '.zip' diff --git a/modules/simple_forms_api/spec/services/form_remediation/s3_client_spec.rb b/modules/simple_forms_api/spec/services/form_remediation/s3_client_spec.rb index 34463ed0a30..ea5431a193b 100644 --- a/modules/simple_forms_api/spec/services/form_remediation/s3_client_spec.rb +++ b/modules/simple_forms_api/spec/services/form_remediation/s3_client_spec.rb @@ -71,7 +71,10 @@ allow(CarrierWave::SanitizedFile).to receive(:new).with(file_double).and_return(carrier_wave_file) allow(CSV).to receive(:open).and_return(true) allow(SimpleFormsApi::FormRemediation::SubmissionArchive).to(receive(:new).and_return(submission_archive_double)) - allow(submission_archive_double).to receive(:build!).and_return([local_archive_path, manifest_entry]) + allow(submission_archive_double).to receive_messages( + build!: [local_archive_path, manifest_entry], + retrieval_data: [local_archive_path, manifest_entry] + ) allow(SimpleFormsApi::FormRemediation::Uploader).to receive_messages(new: uploader) allow(uploader).to receive(:get_s3_link).with(s3_archive_path).and_return('/s3_url/stuff.pdf') allow(uploader).to receive_messages(get_s3_file: s3_file, store!: carrier_wave_file) @@ -84,6 +87,11 @@ let(:type) { archive_type } describe '.fetch_presigned_url' do + subject(:fetch_presigned_url) { described_class.fetch_presigned_url(benefits_intake_uuid, config:, type:) } + + it 'returns the s3 link' do + expect(fetch_presigned_url).to eq('/s3_url/stuff.pdf') + end end describe '#initialize' do